PageRenderTime 465ms CodeModel.GetById 44ms RepoModel.GetById 24ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 242 lines | 165 code | 45 blank | 32 comment | 0 complexity | af17f0b99dcd9dea736d3927369ec900 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  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 org.mobicents.protocols.asn.AsnInputStream;
  25. import org.mobicents.protocols.asn.AsnOutputStream;
  26. import org.mobicents.protocols.asn.Tag;
  27. import org.mobicents.protocols.ss7.map.api.primitives.AddressNature;
  28. import org.mobicents.protocols.ss7.map.api.primitives.AddressString;
  29. import org.mobicents.protocols.ss7.map.api.primitives.IMSI;
  30. import org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString;
  31. import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
  32. import org.mobicents.protocols.ss7.map.api.primitives.NumberingPlan;
  33. import org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_DA;
  34. import org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_OA;
  35. import org.mobicents.protocols.ss7.map.api.service.sms.SmsSignalInfo;
  36. import org.mobicents.protocols.ss7.map.primitives.AddressStringImpl;
  37. import org.mobicents.protocols.ss7.map.primitives.IMSIImpl;
  38. import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
  39. import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerTest;
  40. import static org.testng.Assert.*;
  41. import org.testng.*;import org.testng.annotations.*;
  42. /**
  43. *
  44. * @author sergey vetyutnev
  45. *
  46. */
  47. public class MoForwardShortMessageRequestIndicationTest {
  48. private byte[] getEncodedDataSimple() {
  49. return new byte[] { 48, 38, -124, 7, -111, 34, 51, 67, -103, 32, 50, -126, 8, -111, 50, 17, 50, 33, 67, 51, -12, 4, 17, 11, 22, 33, 44, 55, 66, 77, 0,
  50. 1, 2, 3, 4, 5, 6, 7, 9, 8 };
  51. }
  52. private byte[] getEncodedDataComplex() {
  53. return new byte[] { 48, 71, -124, 8, -111, 50, 17, 50, 33, 67, 51, -12, -126, 7, -111, 34, 51, 67, -103, 32, 50, 4, 40, 11, 22, 33, 44, 55, 66, 77, 0,
  54. 1, 2, 3, 4, 5, 6, 7, 9, 8, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 8, 0, 1, 33, 50, 51, -108, 9, -14 };
  55. }
  56. private byte[] getEncodedDataNoDaOa() {
  57. return new byte[] { 48, 58, -123, 0, -123, 0, 4, 52, 11, 22, 33, 44, 55, 66, 77, 0, 1, 2, 3, 4, 5, 6, 7, 9, 8, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3,
  58. 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 99, 88, 77, 66, 55, 44, 44, 33, 22, 11, 11, 0 };
  59. }
  60. private byte[] getEncodedDataFull() {
  61. return new byte[] { 48, 80, -128, 8, 2, 1, 17, 50, 84, 118, -104, -16, -124, 6, -74, 16, 50, 84, 118, -104, 4, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99,
  62. 48, 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, 23, 24, 25, 26, -95, 3, 31,
  63. 32, 33, 4, 8, 66, -128, 24, 33, 50, 67, 84, -11 };
  64. }
  65. @Test(groups = { "functional.decode","service.sms"})
  66. public void testDecode() throws Exception {
  67. byte[] rawData = getEncodedDataSimple();
  68. AsnInputStream asn = new AsnInputStream(rawData);
  69. int tag = asn.readTag();
  70. MoForwardShortMessageRequestIndicationImpl ind = new MoForwardShortMessageRequestIndicationImpl();
  71. ind.decodeAll(asn);
  72. assertEquals( tag,Tag.SEQUENCE);
  73. assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
  74. SM_RP_DA da = ind.getSM_RP_DA();
  75. SM_RP_OA oa = ind.getSM_RP_OA();
  76. SmsSignalInfo ui = ind.getSM_RP_UI();
  77. assertEquals( da.getServiceCentreAddressDA().getAddressNature(),AddressNature.international_number);
  78. assertEquals( da.getServiceCentreAddressDA().getNumberingPlan(),NumberingPlan.ISDN);
  79. assertEquals( da.getServiceCentreAddressDA().getAddress(),"223334990223");
  80. assertEquals( oa.getMsisdn().getAddressNature(),AddressNature.international_number);
  81. assertEquals( oa.getMsisdn().getNumberingPlan(),NumberingPlan.ISDN);
  82. assertEquals( oa.getMsisdn().getAddress(),"2311231234334");
  83. assertTrue(Arrays.equals(ui.getData(), new byte[] { 11, 22, 33, 44, 55, 66, 77, 0, 1, 2, 3, 4, 5, 6, 7, 9, 8 }));
  84. rawData = getEncodedDataComplex();
  85. asn = new AsnInputStream(rawData);
  86. tag = asn.readTag();
  87. ind = new MoForwardShortMessageRequestIndicationImpl();
  88. ind.decodeAll(asn);
  89. assertEquals( tag,Tag.SEQUENCE);
  90. assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
  91. da = ind.getSM_RP_DA();
  92. oa = ind.getSM_RP_OA();
  93. ui = ind.getSM_RP_UI();
  94. IMSI imsi = ind.getIMSI();
  95. assertEquals( da.getServiceCentreAddressDA().getAddressNature(),AddressNature.international_number);
  96. assertEquals( da.getServiceCentreAddressDA().getNumberingPlan(),NumberingPlan.ISDN);
  97. assertEquals( da.getServiceCentreAddressDA().getAddress(),"2311231234334");
  98. assertEquals( oa.getMsisdn().getAddressNature(),AddressNature.international_number);
  99. assertEquals( oa.getMsisdn().getNumberingPlan(),NumberingPlan.ISDN);
  100. assertEquals( oa.getMsisdn().getAddress(),"223334990223");
  101. assertTrue(Arrays.equals(ui.getData(), new byte[] { 11, 22, 33, 44, 55, 66, 77, 0, 1, 2, 3, 4, 5, 6, 7, 9, 8, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4 }));
  102. // assertEquals( (long)imsi.getMCC(),1);
  103. // assertEquals( (long)imsi.getMNC(),1);
  104. assertEquals( imsi.getData(),"001012233349902");
  105. rawData = getEncodedDataNoDaOa();
  106. asn = new AsnInputStream(rawData);
  107. tag = asn.readTag();
  108. ind = new MoForwardShortMessageRequestIndicationImpl();
  109. ind.decodeAll(asn);
  110. assertEquals( tag,Tag.SEQUENCE);
  111. assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
  112. da = ind.getSM_RP_DA();
  113. oa = ind.getSM_RP_OA();
  114. ui = ind.getSM_RP_UI();
  115. assertNull(da.getServiceCentreAddressDA());
  116. assertNull(da.getIMSI());
  117. assertNull(da.getLMSI());
  118. assertNull(oa.getMsisdn());
  119. assertNull(oa.getServiceCentreAddressOA());
  120. assertTrue(Arrays.equals(ui.getData(), new byte[] { 11, 22, 33, 44, 55, 66, 77, 0, 1, 2, 3, 4, 5, 6, 7, 9, 8, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,4, 4, 4, 4, 4, 4, 99, 88, 77, 66, 55, 44, 44, 33, 22, 11, 11, 0 }));
  121. rawData = getEncodedDataFull();
  122. asn = new AsnInputStream(rawData);
  123. tag = asn.readTag();
  124. ind = new MoForwardShortMessageRequestIndicationImpl();
  125. ind.decodeAll(asn);
  126. assertEquals( tag,Tag.SEQUENCE);
  127. assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
  128. da = ind.getSM_RP_DA();
  129. oa = ind.getSM_RP_OA();
  130. ui = ind.getSM_RP_UI();
  131. imsi = ind.getIMSI();
  132. // assertEquals( (long)da.getIMSI().getMCC(),201);
  133. // assertEquals( (long)da.getIMSI().getMNC(),1);
  134. assertEquals( da.getIMSI().getData(),"201011234567890");
  135. assertEquals( oa.getServiceCentreAddressOA().getAddressNature(),AddressNature.network_specific_number);
  136. assertEquals( oa.getServiceCentreAddressOA().getNumberingPlan(),NumberingPlan.land_mobile);
  137. assertEquals( oa.getServiceCentreAddressOA().getAddress(),"0123456789");
  138. assertTrue(Arrays.equals(ui.getData(), new byte[] { 11, 22, 33, 44, 55, 66, 77, 88, 99 }));
  139. // assertEquals( (long)imsi.getMCC(),240);
  140. // assertEquals( (long)imsi.getMNC(),88);
  141. assertEquals( imsi.getData(),"240881122334455");
  142. assertTrue(MAPExtensionContainerTest.CheckTestExtensionContainer(ind.getExtensionContainer()));
  143. }
  144. @Test(groups = { "functional.encode","service.sms"})
  145. public void testEncode() throws Exception {
  146. AddressString sca = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "223334990223");
  147. SM_RP_DA sm_RP_DA = new SM_RP_DAImpl(sca);
  148. ISDNAddressString msisdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "2311231234334");
  149. SM_RP_OAImpl sm_RP_OA = new SM_RP_OAImpl();
  150. sm_RP_OA.setMsisdn(msisdn);
  151. SmsSignalInfo sm_RP_UI = new SmsSignalInfoImpl(new byte[] { 11, 22, 33, 44, 55, 66, 77, 0, 1, 2, 3, 4, 5, 6, 7, 9, 8 }, null);
  152. MoForwardShortMessageRequestIndicationImpl ind = new MoForwardShortMessageRequestIndicationImpl(sm_RP_DA, sm_RP_OA, sm_RP_UI, null, null);
  153. AsnOutputStream asnOS = new AsnOutputStream();
  154. ind.encodeAll(asnOS);
  155. byte[] encodedData = asnOS.toByteArray();
  156. byte[] rawData = getEncodedDataSimple();
  157. assertTrue( Arrays.equals(rawData,encodedData));
  158. sca = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "2311231234334");
  159. sm_RP_DA = new SM_RP_DAImpl(sca);
  160. msisdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "223334990223");
  161. sm_RP_OA = new SM_RP_OAImpl();
  162. sm_RP_OA.setMsisdn(msisdn);
  163. sm_RP_UI = new SmsSignalInfoImpl(new byte[] { 11, 22, 33, 44, 55, 66, 77, 0, 1, 2, 3, 4, 5, 6, 7, 9, 8, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  164. 3, 4, 4, 4, 4, 4, 4 }, null);
  165. IMSI imsi = new IMSIImpl("001012233349902");
  166. ind = new MoForwardShortMessageRequestIndicationImpl(sm_RP_DA, sm_RP_OA, sm_RP_UI, null, imsi);
  167. asnOS = new AsnOutputStream();
  168. ind.encodeAll(asnOS);
  169. encodedData = asnOS.toByteArray();
  170. rawData = getEncodedDataComplex();
  171. assertTrue( Arrays.equals(rawData,encodedData));
  172. sm_RP_DA = new SM_RP_DAImpl();
  173. sm_RP_OA = new SM_RP_OAImpl();
  174. sm_RP_UI = new SmsSignalInfoImpl(new byte[] { 11, 22, 33, 44, 55, 66, 77, 0, 1, 2, 3, 4, 5, 6, 7, 9, 8, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  175. 3, 4, 4, 4, 4, 4, 4, 99, 88, 77, 66, 55, 44, 44, 33, 22, 11, 11, 0 }, null);
  176. ind = new MoForwardShortMessageRequestIndicationImpl(sm_RP_DA, sm_RP_OA, sm_RP_UI, null, null);
  177. asnOS = new AsnOutputStream();
  178. ind.encodeAll(asnOS);
  179. encodedData = asnOS.toByteArray();
  180. rawData = getEncodedDataNoDaOa();
  181. assertTrue( Arrays.equals(rawData,encodedData));
  182. IMSI imsi0 = new IMSIImpl("201011234567890");
  183. sm_RP_DA = new SM_RP_DAImpl(imsi0);
  184. msisdn = new ISDNAddressStringImpl(AddressNature.network_specific_number, NumberingPlan.land_mobile, "0123456789");
  185. sm_RP_OA = new SM_RP_OAImpl();
  186. sm_RP_OA.setServiceCentreAddressOA(msisdn);
  187. sm_RP_UI = new SmsSignalInfoImpl(new byte[] { 11, 22, 33, 44, 55, 66, 77, 88, 99 }, null);
  188. MAPExtensionContainer extensionContainer = MAPExtensionContainerTest.GetTestExtensionContainer();
  189. imsi = new IMSIImpl("240881122334455");
  190. ind = new MoForwardShortMessageRequestIndicationImpl(sm_RP_DA, sm_RP_OA, sm_RP_UI, extensionContainer, imsi);
  191. asnOS = new AsnOutputStream();
  192. ind.encodeAll(asnOS);
  193. encodedData = asnOS.toByteArray();
  194. rawData = getEncodedDataFull();
  195. assertTrue( Arrays.equals(rawData,encodedData));
  196. }
  197. }