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

http://mobicents.googlecode.com/ · Java · 179 lines · 117 code · 36 blank · 26 comment · 0 complexity · 30d667b10b5c9d80197884d490142eaa 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 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.ISDNAddressString;
  30. import org.mobicents.protocols.ss7.map.api.primitives.NumberingPlan;
  31. import org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_MTI;
  32. import org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_SMEA;
  33. import org.mobicents.protocols.ss7.map.primitives.AddressStringImpl;
  34. import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
  35. import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerTest;
  36. import static org.testng.Assert.*;
  37. import org.testng.*;import org.testng.annotations.*;
  38. /**
  39. *
  40. * @author sergey vetyutnev
  41. *
  42. */
  43. public class SendRoutingInfoForSMRequestIndicationTest {
  44. private byte[] getEncodedDataSimple() {
  45. return new byte[] { 48, 20, -128, 7, -111, 49, 84, 119, 84, 85, -15, -127, 1, 0, -126, 6, -111, -119, 18, 17, 51, 51 };
  46. }
  47. private byte[] getEncodedDataComplex() {
  48. return new byte[] { 48, 30, -128, 7, -111, 49, 84, 119, 84, 85, -15, -127, 1, 0, -126, 6, -111, -119, 18, 17, 51, 51, -121, 0, -119, 6, -111, 105, 49,
  49. 3, -105, 97 };
  50. }
  51. private byte[] getEncodedDataFull() {
  52. return new byte[] { 48, 70, -128, 6, -111, 17, 33, 34, 51, -13, -127, 1, -1, -126, 3, -72, 68, 68, -90, 39, -96, 32, 48, 10, 6, 3, 42, 3, 4, 11, 12,
  53. 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, -121, 0, -120, 1, 1, -119, 6, -111, 105,
  54. 49, 3, -105, 97 };
  55. }
  56. @Test(groups = { "functional.decode","service.sms"})
  57. public void testDecode() throws Exception {
  58. byte[] rawData = getEncodedDataSimple();
  59. AsnInputStream asn = new AsnInputStream(rawData);
  60. int tag = asn.readTag();
  61. SendRoutingInfoForSMRequestIndicationImpl ind = new SendRoutingInfoForSMRequestIndicationImpl();
  62. ind.decodeAll(asn);
  63. assertEquals( tag,Tag.SEQUENCE);
  64. assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
  65. ISDNAddressString msisdn = ind.getMsisdn();
  66. assertEquals( msisdn.getAddressNature(),AddressNature.international_number);
  67. assertEquals( msisdn.getNumberingPlan(),NumberingPlan.ISDN);
  68. assertEquals( msisdn.getAddress(),"13457745551");
  69. assertEquals( (boolean) ind.getSm_RP_PRI(),false);
  70. AddressString sca = ind.getServiceCentreAddress();
  71. assertEquals( sca.getAddressNature(),AddressNature.international_number);
  72. assertEquals( sca.getNumberingPlan(),NumberingPlan.ISDN);
  73. assertEquals( sca.getAddress(),"9821113333");
  74. rawData = getEncodedDataComplex();
  75. asn = new AsnInputStream(rawData);
  76. tag = asn.readTag();
  77. ind = new SendRoutingInfoForSMRequestIndicationImpl();
  78. ind.decodeAll(asn);
  79. assertEquals( tag,Tag.SEQUENCE);
  80. assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
  81. msisdn = ind.getMsisdn();
  82. assertEquals( msisdn.getAddressNature(),AddressNature.international_number);
  83. assertEquals( msisdn.getNumberingPlan(),NumberingPlan.ISDN);
  84. assertEquals( msisdn.getAddress(),"13457745551");
  85. assertEquals( (boolean) ind.getSm_RP_PRI(),false);
  86. sca = ind.getServiceCentreAddress();
  87. assertEquals( sca.getAddressNature(),AddressNature.international_number);
  88. assertEquals( sca.getNumberingPlan(),NumberingPlan.ISDN);
  89. assertEquals( sca.getAddress(),"9821113333");
  90. assertEquals( (boolean) ind.getGprsSupportIndicator(),true);
  91. assertTrue(Arrays.equals(new byte[] { -111, 105, 49, 3, -105, 97 }, ind.getSM_RP_SMEA().getData()));
  92. rawData = getEncodedDataFull();
  93. asn = new AsnInputStream(rawData);
  94. tag = asn.readTag();
  95. ind = new SendRoutingInfoForSMRequestIndicationImpl();
  96. ind.decodeAll(asn);
  97. assertEquals( tag,Tag.SEQUENCE);
  98. assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
  99. msisdn = ind.getMsisdn();
  100. assertEquals( msisdn.getAddressNature(),AddressNature.international_number);
  101. assertEquals( msisdn.getNumberingPlan(),NumberingPlan.ISDN);
  102. assertEquals( msisdn.getAddress(),"111222333");
  103. assertEquals( (boolean) ind.getSm_RP_PRI(),true);
  104. sca = ind.getServiceCentreAddress();
  105. assertEquals( sca.getAddressNature(),AddressNature.network_specific_number);
  106. assertEquals( sca.getNumberingPlan(),NumberingPlan.national);
  107. assertEquals( sca.getAddress(),"4444");
  108. assertEquals( (boolean) ind.getGprsSupportIndicator(),true);
  109. assertTrue(Arrays.equals(new byte[] { -111, 105, 49, 3, -105, 97 }, ind.getSM_RP_SMEA().getData()));
  110. assertTrue(MAPExtensionContainerTest.CheckTestExtensionContainer(ind.getExtensionContainer()));
  111. assertEquals( ind.getSM_RP_MTI(),SM_RP_MTI.SMS_Status_Report);
  112. }
  113. @Test(groups = { "functional.encode","service.sms"})
  114. public void testEncode() throws Exception {
  115. ISDNAddressString msisdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "13457745551");
  116. AddressString sca = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "9821113333");
  117. SendRoutingInfoForSMRequestIndicationImpl ind = new SendRoutingInfoForSMRequestIndicationImpl(msisdn, false, sca, null, false, null, null);
  118. AsnOutputStream asnOS = new AsnOutputStream();
  119. ind.encodeAll(asnOS);
  120. byte[] encodedData = asnOS.toByteArray();
  121. byte[] rawData = getEncodedDataSimple();
  122. assertTrue( Arrays.equals(rawData,encodedData));
  123. msisdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "13457745551");
  124. sca = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "9821113333");
  125. SM_RP_SMEA ui = new SM_RP_SMEAImpl(new byte[] { -111, 105, 49, 3, -105, 97 });
  126. ind = new SendRoutingInfoForSMRequestIndicationImpl(msisdn, false, sca, null, true, null, ui);
  127. asnOS = new AsnOutputStream();
  128. ind.encodeAll(asnOS);
  129. encodedData = asnOS.toByteArray();
  130. rawData = getEncodedDataComplex();
  131. assertTrue( Arrays.equals(rawData,encodedData));
  132. msisdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "111222333");
  133. sca = new AddressStringImpl(AddressNature.network_specific_number, NumberingPlan.national, "4444");
  134. ui = new SM_RP_SMEAImpl(new byte[] { -111, 105, 49, 3, -105, 97 });
  135. ind = new SendRoutingInfoForSMRequestIndicationImpl(msisdn, true, sca, MAPExtensionContainerTest.GetTestExtensionContainer(), true,
  136. SM_RP_MTI.SMS_Status_Report, ui);
  137. asnOS = new AsnOutputStream();
  138. ind.encodeAll(asnOS);
  139. encodedData = asnOS.toByteArray();
  140. rawData = getEncodedDataFull();
  141. assertTrue( Arrays.equals(rawData,encodedData));
  142. }
  143. }