PageRenderTime 35ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 192 lines | 117 code | 43 blank | 32 comment | 0 complexity | 6cfdca90d6d11f75804291274e89f979 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 static org.testng.Assert.assertEquals;
  24. import static org.testng.Assert.assertTrue;
  25. import java.io.ByteArrayInputStream;
  26. import java.io.ByteArrayOutputStream;
  27. import java.io.InputStream;
  28. import java.io.ObjectInputStream;
  29. import java.io.ObjectOutputStream;
  30. import java.util.Arrays;
  31. import org.mobicents.protocols.asn.AsnInputStream;
  32. import org.mobicents.protocols.asn.AsnOutputStream;
  33. import org.mobicents.protocols.asn.Tag;
  34. import org.mobicents.protocols.ss7.map.api.primitives.AddressNature;
  35. import org.mobicents.protocols.ss7.map.api.primitives.AddressString;
  36. import org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString;
  37. import org.mobicents.protocols.ss7.map.api.primitives.NumberingPlan;
  38. import org.mobicents.protocols.ss7.map.primitives.AddressStringImpl;
  39. import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
  40. import org.testng.annotations.Test;
  41. /**
  42. *
  43. * @author sergey vetyutnev
  44. *
  45. */
  46. public class SM_RP_OATest {
  47. private byte[] getEncodedData_Msisdn() {
  48. return new byte[] { (byte)130, 7, (byte)145, (byte)147, 51, 88, 38, 101, 89 };
  49. }
  50. private byte[] getEncodedData_ServiceCentreAddressOA() {
  51. return new byte[] { -124, 7, -111, -127, 16, 7, 17, 17, -15 };
  52. }
  53. private byte[] getEncodedData_No() {
  54. return new byte[] { (byte)133, 0 };
  55. }
  56. @Test(groups = { "functional.decode","service.sms"})
  57. public void testDecode() throws Exception {
  58. byte[] rawData = getEncodedData_ServiceCentreAddressOA();
  59. AsnInputStream asn = new AsnInputStream(rawData);
  60. int tag = asn.readTag();
  61. SM_RP_OAImpl oa = new SM_RP_OAImpl();
  62. oa.decodeAll(asn);
  63. assertEquals( tag,4);
  64. assertEquals( asn.getTagClass(),Tag.CLASS_CONTEXT_SPECIFIC);
  65. AddressString nnm = oa.getServiceCentreAddressOA();
  66. assertEquals( nnm.getAddressNature(),AddressNature.international_number);
  67. assertEquals( nnm.getNumberingPlan(),NumberingPlan.ISDN);
  68. assertEquals( nnm.getAddress(),"18017011111");
  69. rawData = getEncodedData_Msisdn();
  70. asn = new AsnInputStream(rawData);
  71. tag = asn.readTag();
  72. oa = new SM_RP_OAImpl();
  73. oa.decodeAll(asn);
  74. assertEquals( tag,2);
  75. assertEquals( asn.getTagClass(),Tag.CLASS_CONTEXT_SPECIFIC);
  76. ISDNAddressString msisdn = oa.getMsisdn();
  77. assertEquals( msisdn.getAddressNature(),AddressNature.international_number);
  78. assertEquals( msisdn.getNumberingPlan(),NumberingPlan.ISDN);
  79. assertEquals( msisdn.getAddress(),"393385625695");
  80. rawData = getEncodedData_No();
  81. asn = new AsnInputStream(rawData);
  82. tag = asn.readTag();
  83. oa = new SM_RP_OAImpl();
  84. oa.decodeAll(asn);
  85. assertEquals( tag,5);
  86. assertEquals( asn.getTagClass(),Tag.CLASS_CONTEXT_SPECIFIC);
  87. assertEquals( oa.getServiceCentreAddressOA(),null);
  88. assertEquals( oa.getMsisdn(),null);
  89. }
  90. @Test(groups = { "functional.encode","service.sms"})
  91. public void testEncode() throws Exception {
  92. AddressStringImpl astr = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "18017011111");
  93. SM_RP_OAImpl oa = new SM_RP_OAImpl();
  94. oa.setServiceCentreAddressOA(astr);
  95. AsnOutputStream asnOS = new AsnOutputStream();
  96. oa.encodeAll(asnOS);
  97. byte[] encodedData = asnOS.toByteArray();
  98. byte[] rawData = getEncodedData_ServiceCentreAddressOA();
  99. assertTrue( Arrays.equals(rawData,encodedData));
  100. ISDNAddressStringImpl isdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "393385625695");
  101. oa = new SM_RP_OAImpl();
  102. oa.setMsisdn(isdn);
  103. asnOS = new AsnOutputStream();
  104. oa.encodeAll(asnOS);
  105. encodedData = asnOS.toByteArray();
  106. rawData = getEncodedData_Msisdn();
  107. assertTrue( Arrays.equals(rawData,encodedData));
  108. oa = new SM_RP_OAImpl();
  109. asnOS = new AsnOutputStream();
  110. oa.encodeAll(asnOS);
  111. encodedData = asnOS.toByteArray();
  112. rawData = getEncodedData_No();
  113. assertTrue( Arrays.equals(rawData,encodedData));
  114. }
  115. @Test(groups = { "functional.serialize", "service.sms" })
  116. public void testSerialization() throws Exception {
  117. AddressStringImpl astr = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "18017011111");
  118. SM_RP_OAImpl original = new SM_RP_OAImpl();
  119. // serialize
  120. ByteArrayOutputStream out = new ByteArrayOutputStream();
  121. ObjectOutputStream oos = new ObjectOutputStream(out);
  122. oos.writeObject(original);
  123. oos.close();
  124. // deserialize
  125. byte[] pickled = out.toByteArray();
  126. InputStream in = new ByteArrayInputStream(pickled);
  127. ObjectInputStream ois = new ObjectInputStream(in);
  128. Object o = ois.readObject();
  129. SM_RP_OAImpl copy = (SM_RP_OAImpl) o;
  130. //test result
  131. assertEquals(copy.getServiceCentreAddressOA(), original.getServiceCentreAddressOA());
  132. ISDNAddressStringImpl isdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "393385625695");
  133. original = new SM_RP_OAImpl();
  134. original.setMsisdn(isdn);
  135. // serialize
  136. out = new ByteArrayOutputStream();
  137. oos = new ObjectOutputStream(out);
  138. oos.writeObject(original);
  139. oos.close();
  140. // deserialize
  141. pickled = out.toByteArray();
  142. in = new ByteArrayInputStream(pickled);
  143. ois = new ObjectInputStream(in);
  144. o = ois.readObject();
  145. copy = (SM_RP_OAImpl) o;
  146. //test result
  147. assertEquals(copy.getMsisdn(), original.getMsisdn());
  148. }
  149. }