/protocols/ss7/map/map-impl/src/test/java/org/mobicents/protocols/ss7/map/service/sms/SendRoutingInfoForSMResponseIndicationTest.java

http://mobicents.googlecode.com/ · Java · 151 lines · 94 code · 27 blank · 30 comment · 0 complexity · 7fdb9af1b5ede4f342ad6ce74cc6ca9a 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. package org.mobicents.protocols.ss7.map.service.sms;
  23. import java.util.Arrays;
  24. import static org.testng.Assert.*;
  25. import org.testng.*;import org.testng.annotations.*;
  26. import org.mobicents.protocols.asn.AsnInputStream;
  27. import org.mobicents.protocols.asn.AsnOutputStream;
  28. import org.mobicents.protocols.asn.Tag;
  29. import org.mobicents.protocols.ss7.map.api.primitives.AdditionalNumberType;
  30. import org.mobicents.protocols.ss7.map.api.primitives.AddressNature;
  31. import org.mobicents.protocols.ss7.map.api.primitives.IMSI;
  32. import org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString;
  33. import org.mobicents.protocols.ss7.map.api.primitives.LMSI;
  34. import org.mobicents.protocols.ss7.map.api.primitives.NumberingPlan;
  35. import org.mobicents.protocols.ss7.map.api.service.sms.LocationInfoWithLMSI;
  36. import org.mobicents.protocols.ss7.map.primitives.IMSIImpl;
  37. import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
  38. import org.mobicents.protocols.ss7.map.primitives.LMSIImpl;
  39. import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerTest;
  40. /**
  41. *
  42. * @author sergey vetyutnev
  43. *
  44. */
  45. public class SendRoutingInfoForSMResponseIndicationTest {
  46. private byte[] getEncodedData() {
  47. return new byte[] { 48, 27, 4, 8, 2, -112, 9, 2, 16, 17, 34, -9, -96, 15, -127, 7, -111, 33, 48, 18, 0, -110, -11, 4, 4, 0, 3, 98, 49 };
  48. }
  49. private byte[] getEncodedDataFull() {
  50. return new byte[] { 48, 115, 4, 7, 17, 1, 35, 34, 51, 19, 17, -96, 63, -127, 5, -58, 0, 0, 17, 17, 4, 4, 0, 2, 1, 0, 48, 39, -96, 32, 48, 10, 6, 3, 42,
  51. 3, 4, 11, 12, 13, 14, 15, 48, 5, 6, 3, 42, 3, 6, 48, 11, 6, 3, 42, 3, 5, 21, 22, 23, 24, 25, 26, -95, 3, 31, 32, 33, -123, 0, -122, 5, -90,
  52. -103, -103, -103, -103, -92, 39, -96, 32, 48, 10, 6, 3, 42, 3, 4, 11, 12, 13, 14, 15, 48, 5, 6, 3, 42, 3, 6, 48, 11, 6, 3, 42, 3, 5, 21, 22,
  53. 23, 24, 25, 26, -95, 3, 31, 32, 33 };
  54. }
  55. @Test(groups = { "functional.decode","service.sms"})
  56. public void testDecode() throws Exception {
  57. byte[] rawData = getEncodedData();
  58. AsnInputStream asn = new AsnInputStream(rawData);
  59. int tag = asn.readTag();
  60. SendRoutingInfoForSMResponseIndicationImpl ind = new SendRoutingInfoForSMResponseIndicationImpl();
  61. ind.decodeAll(asn);
  62. assertEquals( tag,Tag.SEQUENCE);
  63. assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
  64. IMSI imsi = ind.getIMSI();
  65. // assertEquals( (long)imsi.getMCC(),200L);
  66. // assertEquals( (long)imsi.getMNC(),99L);
  67. assertEquals( imsi.getData(),"200990200111227");
  68. LocationInfoWithLMSI li = ind.getLocationInfoWithLMSI();
  69. ISDNAddressString nnn = li.getNetworkNodeNumber();
  70. assertEquals( nnn.getAddressNature(),AddressNature.international_number);
  71. assertEquals( nnn.getNumberingPlan(),NumberingPlan.ISDN);
  72. assertEquals( nnn.getAddress(),"12032100295");
  73. LMSI lmsi = li.getLMSI();
  74. assertTrue(Arrays.equals(new byte[] { 0, 3, 98, 49 }, lmsi.getData()));
  75. rawData = getEncodedDataFull();
  76. asn = new AsnInputStream(rawData);
  77. tag = asn.readTag();
  78. ind = new SendRoutingInfoForSMResponseIndicationImpl();
  79. ind.decodeAll(asn);
  80. assertEquals( tag,Tag.SEQUENCE);
  81. assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
  82. imsi = ind.getIMSI();
  83. // assertEquals( (long)imsi.getMCC(),111L);
  84. // assertEquals( (long)imsi.getMNC(),3L);
  85. assertEquals( imsi.getData(),"11103222333111");
  86. li = ind.getLocationInfoWithLMSI();
  87. nnn = li.getNetworkNodeNumber();
  88. assertEquals( nnn.getAddressNature(),AddressNature.subscriber_number);
  89. assertEquals( nnn.getNumberingPlan(),NumberingPlan.land_mobile);
  90. assertEquals( nnn.getAddress(),"00001111");
  91. lmsi = li.getLMSI();
  92. assertTrue(MAPExtensionContainerTest.CheckTestExtensionContainer(li.getExtensionContainer()));
  93. assertEquals( li.getAdditionalNumberType(),AdditionalNumberType.sgsn);
  94. ISDNAddressString an = li.getAdditionalNumber();
  95. assertEquals( an.getAddressNature(),AddressNature.national_significant_number);
  96. assertEquals( an.getNumberingPlan(),NumberingPlan.land_mobile);
  97. assertEquals( an.getAddress(),"99999999");
  98. assertTrue(MAPExtensionContainerTest.CheckTestExtensionContainer(ind.getExtensionContainer()));
  99. }
  100. @Test(groups = { "functional.encode","service.sms"})
  101. public void testEncode() throws Exception {
  102. IMSI imsi = new IMSIImpl("200990200111227");
  103. ISDNAddressString nnn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "12032100295");
  104. LMSI lmsi = new LMSIImpl(new byte[] { 0, 3, 98, 49 });
  105. LocationInfoWithLMSI li = new LocationInfoWithLMSIImpl(nnn, lmsi, null, null, null);
  106. SendRoutingInfoForSMResponseIndicationImpl ind = new SendRoutingInfoForSMResponseIndicationImpl(imsi, li, null);
  107. AsnOutputStream asnOS = new AsnOutputStream();
  108. ind.encodeAll(asnOS);
  109. byte[] encodedData = asnOS.toByteArray();
  110. byte[] rawData = getEncodedData();
  111. assertTrue( Arrays.equals(rawData,encodedData));
  112. imsi = new IMSIImpl("11103222333111");
  113. nnn = new ISDNAddressStringImpl(AddressNature.subscriber_number, NumberingPlan.land_mobile, "00001111");
  114. lmsi = new LMSIImpl(new byte[] { 0, 2, 1, 0 });
  115. ISDNAddressString additionalNumber = new ISDNAddressStringImpl(AddressNature.national_significant_number, NumberingPlan.land_mobile, "99999999");
  116. li = new LocationInfoWithLMSIImpl(nnn, lmsi, MAPExtensionContainerTest.GetTestExtensionContainer(), AdditionalNumberType.sgsn, additionalNumber);
  117. ind = new SendRoutingInfoForSMResponseIndicationImpl(imsi, li, MAPExtensionContainerTest.GetTestExtensionContainer());
  118. asnOS = new AsnOutputStream();
  119. ind.encodeAll(asnOS);
  120. encodedData = asnOS.toByteArray();
  121. rawData = getEncodedDataFull();
  122. assertTrue( Arrays.equals(rawData,encodedData));
  123. }
  124. }