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

http://mobicents.googlecode.com/ · Java · 146 lines · 94 code · 26 blank · 26 comment · 0 complexity · 2223e63dff470a6493f2f28569ce2f92 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_DA;
  32. import org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_OA;
  33. import org.mobicents.protocols.ss7.map.api.service.sms.SmsSignalInfo;
  34. import org.mobicents.protocols.ss7.map.primitives.AddressStringImpl;
  35. import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
  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 ForwardShortMessageRequestIndicationTest {
  44. private byte[] getEncodedDataSimple() {
  45. 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,
  46. 1, 2, 3, 4, 5, 6, 7, 9, 8 };
  47. }
  48. private byte[] getEncodedDataComplex() {
  49. return new byte[] { 48, 63, -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,
  50. 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, 5, 0 };
  51. }
  52. @Test(groups = { "functional.decode","service.sms"})
  53. public void testDecode() throws Exception {
  54. byte[] rawData = getEncodedDataSimple();
  55. AsnInputStream asn = new AsnInputStream(rawData);
  56. int tag = asn.readTag();
  57. ForwardShortMessageRequestIndicationImpl ind = new ForwardShortMessageRequestIndicationImpl();
  58. ind.decodeAll(asn);
  59. assertEquals(Tag.SEQUENCE, tag);
  60. assertEquals(Tag.CLASS_UNIVERSAL, asn.getTagClass());
  61. SM_RP_DA da = ind.getSM_RP_DA();
  62. SM_RP_OA oa = ind.getSM_RP_OA();
  63. SmsSignalInfo ui = ind.getSM_RP_UI();
  64. assertEquals(AddressNature.international_number, da.getServiceCentreAddressDA().getAddressNature());
  65. assertEquals(NumberingPlan.ISDN, da.getServiceCentreAddressDA().getNumberingPlan());
  66. assertEquals("223334990223", da.getServiceCentreAddressDA().getAddress());
  67. assertEquals(AddressNature.international_number, oa.getMsisdn().getAddressNature());
  68. assertEquals(NumberingPlan.ISDN, oa.getMsisdn().getNumberingPlan());
  69. assertEquals("2311231234334", oa.getMsisdn().getAddress());
  70. assertTrue(Arrays.equals(ui.getData(), new byte[] { 11, 22, 33, 44, 55, 66, 77, 0, 1, 2, 3, 4, 5, 6, 7, 9, 8 }));
  71. assertFalse(ind.getMoreMessagesToSend());
  72. rawData = getEncodedDataComplex();
  73. asn = new AsnInputStream(rawData);
  74. tag = asn.readTag();
  75. ind = new ForwardShortMessageRequestIndicationImpl();
  76. ind.decodeAll(asn);
  77. assertEquals(Tag.SEQUENCE, tag);
  78. assertEquals(Tag.CLASS_UNIVERSAL, asn.getTagClass());
  79. da = ind.getSM_RP_DA();
  80. oa = ind.getSM_RP_OA();
  81. ui = ind.getSM_RP_UI();
  82. assertEquals(AddressNature.international_number, da.getServiceCentreAddressDA().getAddressNature());
  83. assertEquals(NumberingPlan.ISDN, da.getServiceCentreAddressDA().getNumberingPlan());
  84. assertEquals("2311231234334", da.getServiceCentreAddressDA().getAddress());
  85. assertEquals(AddressNature.international_number, oa.getMsisdn().getAddressNature());
  86. assertEquals(NumberingPlan.ISDN, oa.getMsisdn().getNumberingPlan());
  87. assertEquals("223334990223", oa.getMsisdn().getAddress());
  88. 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,
  89. 3, 3, 3, 4, 4, 4, 4, 4, 4 }));
  90. assertTrue(ind.getMoreMessagesToSend());
  91. }
  92. @Test(groups = { "functional.decode","service.sms"})
  93. public void testEncode() throws Exception {
  94. AddressString sca = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "223334990223");
  95. SM_RP_DA sm_RP_DA = new SM_RP_DAImpl(sca);
  96. ISDNAddressString msisdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "2311231234334");
  97. SM_RP_OAImpl sm_RP_OA = new SM_RP_OAImpl();
  98. sm_RP_OA.setMsisdn(msisdn);
  99. 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);
  100. ForwardShortMessageRequestIndicationImpl ind = new ForwardShortMessageRequestIndicationImpl(sm_RP_DA, sm_RP_OA, sm_RP_UI, false);
  101. AsnOutputStream asnOS = new AsnOutputStream();
  102. ind.encodeAll(asnOS);
  103. byte[] encodedData = asnOS.toByteArray();
  104. byte[] rawData = getEncodedDataSimple();
  105. assertTrue(Arrays.equals(rawData, encodedData));
  106. sca = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "2311231234334");
  107. sm_RP_DA = new SM_RP_DAImpl(sca);
  108. msisdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "223334990223");
  109. sm_RP_OA = new SM_RP_OAImpl();
  110. sm_RP_OA.setMsisdn(msisdn);
  111. 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,
  112. 3, 4, 4, 4, 4, 4, 4 }, null);
  113. ind = new ForwardShortMessageRequestIndicationImpl(sm_RP_DA, sm_RP_OA, sm_RP_UI, true);
  114. asnOS = new AsnOutputStream();
  115. ind.encodeAll(asnOS);
  116. encodedData = asnOS.toByteArray();
  117. rawData = getEncodedDataComplex();
  118. assertTrue(Arrays.equals(rawData, encodedData));
  119. }
  120. }