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

http://mobicents.googlecode.com/ · Java · 140 lines · 86 code · 28 blank · 26 comment · 0 complexity · b7f48a07b8fa3f356a8ed4f85b7be2f8 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.*;import org.testng.*;import org.testng.annotations.*;
  25. import org.mobicents.protocols.asn.AsnInputStream;
  26. import org.mobicents.protocols.asn.AsnOutputStream;
  27. import org.mobicents.protocols.asn.Tag;
  28. import org.mobicents.protocols.ss7.map.api.primitives.AddressNature;
  29. import org.mobicents.protocols.ss7.map.api.primitives.AddressString;
  30. import org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString;
  31. import org.mobicents.protocols.ss7.map.api.primitives.NumberingPlan;
  32. import org.mobicents.protocols.ss7.map.api.service.sms.SMDeliveryOutcome;
  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. /**
  37. *
  38. * @author sergey vetyutnev
  39. *
  40. */
  41. public class ReportSMDeliveryStatusRequestIndicationTest {
  42. private byte[] getEncodedData() {
  43. return new byte[] { 48, 19, 4, 6, -111, 39, 34, 51, 19, 17, 4, 6, -111, 1, -112, 115, 84, -13, 10, 1, 1 };
  44. }
  45. private byte[] getEncodedDataFull() {
  46. return new byte[] { 48, 73, 4, 6, -72, 17, 33, 34, 51, -13, 4, 6, -111, 51, 35, 34, 17, -15, 10, 1, 2, -128, 2, 1, -68, -95, 39, -96, 32, 48, 10, 6, 3,
  47. 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, 32, 33, -126, 0, -124, 1, 0,
  48. -123, 2, 2, 43 };
  49. }
  50. @Test(groups = { "functional.decode","service.sms"})
  51. public void testDecode() throws Exception {
  52. byte[] rawData = getEncodedData();
  53. AsnInputStream asn = new AsnInputStream(rawData);
  54. int tag = asn.readTag();
  55. ReportSMDeliveryStatusRequestIndicationImpl ind = new ReportSMDeliveryStatusRequestIndicationImpl(3);
  56. ind.decodeAll(asn);
  57. assertEquals( tag,Tag.SEQUENCE);
  58. assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
  59. ISDNAddressString msisdn = ind.getMsisdn();
  60. assertEquals( msisdn.getAddressNature(),AddressNature.international_number);
  61. assertEquals( msisdn.getNumberingPlan(),NumberingPlan.ISDN);
  62. assertEquals( msisdn.getAddress(),"7222333111");
  63. AddressString sca = ind.getServiceCentreAddress();
  64. assertEquals( sca.getAddressNature(),AddressNature.international_number);
  65. assertEquals( sca.getNumberingPlan(),NumberingPlan.ISDN);
  66. assertEquals( sca.getAddress(),"100937453");
  67. assertEquals( ind.getSMDeliveryOutcome(),SMDeliveryOutcome.absentSubscriber);
  68. rawData = getEncodedDataFull();
  69. asn = new AsnInputStream(rawData);
  70. tag = asn.readTag();
  71. ind = new ReportSMDeliveryStatusRequestIndicationImpl(3);
  72. ind.decodeAll(asn);
  73. assertEquals( tag,Tag.SEQUENCE);
  74. assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
  75. msisdn = ind.getMsisdn();
  76. assertEquals( msisdn.getAddressNature(),AddressNature.network_specific_number);
  77. assertEquals( msisdn.getNumberingPlan(),NumberingPlan.national);
  78. assertEquals( msisdn.getAddress(),"111222333");
  79. sca = ind.getServiceCentreAddress();
  80. assertEquals( sca.getAddressNature(),AddressNature.international_number);
  81. assertEquals( sca.getNumberingPlan(),NumberingPlan.ISDN);
  82. assertEquals( sca.getAddress(),"333222111");
  83. assertEquals( ind.getSMDeliveryOutcome(),SMDeliveryOutcome.successfulTransfer);
  84. assertEquals( (int) ind.getAbsentSubscriberDiagnosticSM(),444);
  85. assertTrue(MAPExtensionContainerTest.CheckTestExtensionContainer(ind.getExtensionContainer()));
  86. assertEquals( (boolean)ind.getGprsSupportIndicator(),true);
  87. assertEquals( (boolean)ind.getDeliveryOutcomeIndicator(),false);
  88. assertEquals( ind.getAdditionalSMDeliveryOutcome(),SMDeliveryOutcome.memoryCapacityExceeded);
  89. assertEquals( (int) ind.getAdditionalAbsentSubscriberDiagnosticSM(),555);
  90. }
  91. @Test(groups = { "functional.encode","service.sms"})
  92. public void testEncode() throws Exception {
  93. ISDNAddressString msisdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "7222333111");
  94. AddressString sca = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "100937453");
  95. ReportSMDeliveryStatusRequestIndicationImpl ind = new ReportSMDeliveryStatusRequestIndicationImpl(3, msisdn, sca, SMDeliveryOutcome.absentSubscriber,
  96. null, null, false, false, null, null);
  97. AsnOutputStream asnOS = new AsnOutputStream();
  98. ind.encodeAll(asnOS);
  99. byte[] encodedData = asnOS.toByteArray();
  100. byte[] rawData = getEncodedData();
  101. assertTrue( Arrays.equals(rawData,encodedData));
  102. msisdn = new ISDNAddressStringImpl(AddressNature.network_specific_number, NumberingPlan.national, "111222333");
  103. sca = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "333222111");
  104. ind = new ReportSMDeliveryStatusRequestIndicationImpl(3, msisdn, sca, SMDeliveryOutcome.successfulTransfer, 444,
  105. MAPExtensionContainerTest.GetTestExtensionContainer(), true, false, SMDeliveryOutcome.memoryCapacityExceeded, 555);
  106. asnOS = new AsnOutputStream();
  107. ind.encodeAll(asnOS);
  108. encodedData = asnOS.toByteArray();
  109. rawData = getEncodedDataFull();
  110. assertTrue( Arrays.equals(rawData,encodedData));
  111. }
  112. }