/protocols/ss7/isup/isup-impl/src/test/java/org/mobicents/protocols/ss7/isup/impl/message/parameter/NetworkManagementControlsTest.java

http://mobicents.googlecode.com/ · Java · 98 lines · 43 code · 12 blank · 43 comment · 8 complexity · 378b808957266d9eabfebe5687389fb6 MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. /**
  23. * Start time:13:20:04 2009-04-26<br>
  24. * Project: mobicents-isup-stack<br>
  25. *
  26. * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski
  27. * </a>
  28. *
  29. */
  30. package org.mobicents.protocols.ss7.isup.impl.message.parameter;
  31. import java.io.IOException;
  32. import org.mobicents.protocols.ss7.isup.ParameterException;
  33. import org.testng.annotations.Test;
  34. import static org.testng.Assert.*;
  35. import org.testng.*;
  36. import org.testng.annotations.*;
  37. /**
  38. * Start time:13:20:04 2009-04-26<br>
  39. * Project: mobicents-isup-stack<br>
  40. *
  41. * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski
  42. * </a>
  43. */
  44. public class NetworkManagementControlsTest extends ParameterHarness {
  45. public NetworkManagementControlsTest() {
  46. super();
  47. super.goodBodies.add(new byte[1]);
  48. super.goodBodies.add(new byte[] { 0x0E });
  49. super.goodBodies.add(new byte[] { 0x0E, 32, 45, 0x0A });
  50. }
  51. @Test(groups = { "functional.encode","functional.decode","parameter"})
  52. public void testBody1EncodedValues() throws IOException, ParameterException {
  53. boolean[] bools = new boolean[] { true, true, false, true, false, true, true };
  54. NetworkManagementControlsImpl eci = new NetworkManagementControlsImpl(getBody1(bools));
  55. byte[] encoded = eci.encode();
  56. for (int index = 0; index < encoded.length; index++) {
  57. if (bools[index] != eci.isTARControlEnabled(encoded[index])) {
  58. fail("Failed to get TAR bits, at index: " + index);
  59. }
  60. if (index == encoded.length - 1) {
  61. if (((encoded[index] >> 7) & 0x01) != 1) {
  62. fail("Last byte must have MSB turned on to indicate last byte, this one does not.");
  63. }
  64. }
  65. }
  66. }
  67. private byte[] getBody1(boolean[] tarEnabled) {
  68. boolean[] bools = new boolean[] { true, true, false, true, false, true, true };
  69. NetworkManagementControlsImpl eci = new NetworkManagementControlsImpl();
  70. byte[] b = new byte[tarEnabled.length];
  71. for (int index = 0; index < tarEnabled.length; index++) {
  72. b[index] = eci.createTAREnabledByte(tarEnabled[index]);
  73. }
  74. return b;
  75. }
  76. /*
  77. * (non-Javadoc)
  78. *
  79. * @see
  80. * org.mobicents.isup.messages.parameters.ParameterHarness#getTestedComponent
  81. * ()
  82. */
  83. public AbstractISUPParameter getTestedComponent() throws ParameterException {
  84. return new NetworkManagementControlsImpl(new byte[1]);
  85. }
  86. }