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

http://mobicents.googlecode.com/ · Java · 116 lines · 58 code · 13 blank · 45 comment · 15 complexity · 0a97f81ce366b62b9a17e24fbeac2c94 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:14:40:20 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.ByteArrayOutputStream;
  32. import java.io.IOException;
  33. import java.lang.reflect.InvocationTargetException;
  34. import org.mobicents.protocols.ss7.isup.ParameterException;
  35. import org.testng.annotations.Test;
  36. import static org.testng.Assert.*;
  37. import org.testng.*;
  38. import org.testng.annotations.*;
  39. /**
  40. * Start time:14:40:20 2009-04-26<br>
  41. * Project: mobicents-isup-stack<br>
  42. *
  43. * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski
  44. * </a>
  45. */
  46. public class NetworkSpecificFacilityTest extends ParameterHarness {
  47. public NetworkSpecificFacilityTest() {
  48. super(); // L1, ext bit,|| this byte
  49. // super.goodBodies.add(new byte[] { 1, (byte) 0x80, 11, 1, 2, 3, 4 });
  50. }
  51. @Test(groups = { "functional.encode","functional.decode","parameter"})
  52. public void testBody1EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
  53. NetworkSpecificFacilityImpl bci = new NetworkSpecificFacilityImpl(getBody(NetworkSpecificFacilityImpl._TNI_NNI, 1, new byte[] { 1, 2, 3, 4, 5, (byte) 0xAA }, new byte[10]));
  54. String[] methodNames = { "isIncludeNetworkIdentification", "getLengthOfNetworkIdentification", "getTypeOfNetworkIdentification", "getNetworkIdentificationPlan" };
  55. Object[] expectedValues = { true, 6, NetworkSpecificFacilityImpl._TNI_NNI, 1 };
  56. super.testValues(bci, methodNames, expectedValues);
  57. // now some custom part?
  58. byte[] body = bci.encode();
  59. for (int index = 2; index < 8; index++) {
  60. if (index == 7) {
  61. if (((body[index] >> 7) & 0x01) != 0) {
  62. fail("Last octet must have MSB set to zero to indicate last byte.");
  63. }
  64. } else {
  65. if (((body[index] >> 7) & 0x01) != 1) {
  66. fail("Last octet must have MSB set to one to indicate that there are more bytes.");
  67. }
  68. }
  69. }
  70. }
  71. private byte[] getBody(int _TNI, int _NIP, byte[] ntwrkID, byte[] ntwrSpecificFacilityIndicator) throws IOException {
  72. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  73. int v = _NIP;
  74. v |= _TNI << 4;
  75. if (ntwrkID != null) {
  76. bos.write(ntwrkID.length);
  77. bos.write(v);
  78. for (int index = 0; index < ntwrkID.length; index++) {
  79. if (index == ntwrkID.length - 1) {
  80. ntwrkID[index] |= 0x01 << 7;
  81. } else {
  82. ntwrkID[index] &= 0x7F;
  83. }
  84. }
  85. bos.write(ntwrkID);
  86. } else {
  87. v |= 0x01 << 7;
  88. bos.write(v);
  89. }
  90. bos.write(ntwrSpecificFacilityIndicator);
  91. return bos.toByteArray();
  92. }
  93. /*
  94. * (non-Javadoc)
  95. *
  96. * @see
  97. * org.mobicents.isup.messages.parameters.ParameterHarness#getTestedComponent
  98. * ()
  99. */
  100. public AbstractISUPParameter getTestedComponent() throws ParameterException {
  101. return new NetworkSpecificFacilityImpl(new byte[] { 1, (byte) 0xFF, 1, 2, 2 });
  102. }
  103. }