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

http://mobicents.googlecode.com/ · Java · 157 lines · 99 code · 29 blank · 29 comment · 0 complexity · 3ddc05431f3a156ee538b709847ad02a 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 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.AdditionalNumberType;
  35. import org.mobicents.protocols.ss7.map.api.primitives.AddressNature;
  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.ISDNAddressStringImpl;
  39. import org.mobicents.protocols.ss7.map.primitives.LMSIImpl;
  40. import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerTest;
  41. import org.testng.annotations.Test;
  42. /**
  43. *
  44. * @author sergey vetyutnev
  45. *
  46. */
  47. public class LocationInfoWithLMSITest {
  48. private byte[] getEncodedData() {
  49. return new byte[] { -96, 15, -127, 7, -111, -105, 48, 115, 0, 34, -14, 4, 4, 0, 3, 98, 49 };
  50. }
  51. private byte[] getEncodedDataFull() {
  52. return new byte[] { -96, 65, -127, 6, -88, 33, 67, 101, -121, 9, 4, 4, 4, 3, 2, 1, 48, 39, -96, 32, 48, 10, 6, 3, 42, 3, 4, 11, 12, 13, 14, 15, 48, 5,
  53. 6, 3, 42, 3, 6, 48, 11, 6, 3, 42, 3, 5, 21, 22, 23, 24, 25, 26, -95, 3, 31, 32, 33, -123, 0, -122, 6, -71, -119, 103, 69, 35, -15 };
  54. }
  55. @Test(groups = { "functional.decode","service.sms"})
  56. public void testDecode() throws Exception {
  57. byte[] rawData = getEncodedData();
  58. AsnInputStream asn = new AsnInputStream(rawData);
  59. int tag = asn.readTag();
  60. LocationInfoWithLMSIImpl liw = new LocationInfoWithLMSIImpl();
  61. liw.decodeAll(asn);
  62. assertEquals( tag,0);
  63. assertEquals( asn.getTagClass(),Tag.CLASS_CONTEXT_SPECIFIC);
  64. ISDNAddressString nnm = liw.getNetworkNodeNumber();
  65. assertEquals( nnm.getAddressNature(),AddressNature.international_number);
  66. assertEquals( nnm.getNumberingPlan(),NumberingPlan.ISDN);
  67. assertEquals( nnm.getAddress(),"79033700222");
  68. assertTrue(Arrays.equals(new byte[] { 0, 3, 98, 49 }, liw.getLMSI().getData()));
  69. rawData = getEncodedDataFull();
  70. asn = new AsnInputStream(rawData);
  71. tag = asn.readTag();
  72. liw = new LocationInfoWithLMSIImpl();
  73. liw.decodeAll(asn);
  74. assertEquals( tag,0);
  75. assertEquals( asn.getTagClass(),Tag.CLASS_CONTEXT_SPECIFIC);
  76. nnm = liw.getNetworkNodeNumber();
  77. assertEquals( nnm.getAddressNature(),AddressNature.national_significant_number);
  78. assertEquals( nnm.getNumberingPlan(),NumberingPlan.national);
  79. assertEquals( nnm.getAddress(),"1234567890");
  80. assertTrue(Arrays.equals(new byte[] { 4, 3, 2, 1 }, liw.getLMSI().getData()));
  81. assertTrue(MAPExtensionContainerTest.CheckTestExtensionContainer(liw.getExtensionContainer()));
  82. assertEquals( liw.getAdditionalNumberType(),AdditionalNumberType.sgsn);
  83. nnm = liw.getAdditionalNumber();
  84. assertEquals( nnm.getAddressNature(),AddressNature.network_specific_number);
  85. assertEquals( nnm.getNumberingPlan(),NumberingPlan.private_plan);
  86. assertEquals( nnm.getAddress(),"987654321");
  87. }
  88. @Test(groups = { "functional.encode","service.sms"})
  89. public void testEncode() throws Exception {
  90. ISDNAddressString nnm = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "79033700222");
  91. LMSIImpl lmsi = new LMSIImpl(new byte[] { 0, 3, 98, 49 });
  92. LocationInfoWithLMSIImpl liw = new LocationInfoWithLMSIImpl(nnm, lmsi, null, null, null);
  93. AsnOutputStream asnOS = new AsnOutputStream();
  94. liw.encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, 0);
  95. byte[] encodedData = asnOS.toByteArray();
  96. byte[] rawData = getEncodedData();
  97. assertTrue( Arrays.equals(rawData,encodedData));
  98. nnm = new ISDNAddressStringImpl(AddressNature.national_significant_number, NumberingPlan.national, "1234567890");
  99. ISDNAddressStringImpl an = new ISDNAddressStringImpl(AddressNature.network_specific_number, NumberingPlan.private_plan, "987654321");
  100. lmsi = new LMSIImpl(new byte[] { 4, 3, 2, 1 });
  101. liw = new LocationInfoWithLMSIImpl(nnm, lmsi, MAPExtensionContainerTest.GetTestExtensionContainer(), AdditionalNumberType.sgsn, an);
  102. asnOS.reset();
  103. liw.encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, 0);
  104. encodedData = asnOS.toByteArray();
  105. rawData = getEncodedDataFull();
  106. assertTrue( Arrays.equals(rawData,encodedData));
  107. }
  108. @Test(groups = { "functional.serialize", "service.sms" })
  109. public void testSerialization() throws Exception {
  110. ISDNAddressString nnm = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "79033700222");
  111. LMSIImpl lmsi = new LMSIImpl(new byte[] { 0, 3, 98, 49 });
  112. LocationInfoWithLMSIImpl original = new LocationInfoWithLMSIImpl(nnm, lmsi, null, null, null);
  113. // serialize
  114. ByteArrayOutputStream out = new ByteArrayOutputStream();
  115. ObjectOutputStream oos = new ObjectOutputStream(out);
  116. oos.writeObject(original);
  117. oos.close();
  118. // deserialize
  119. byte[] pickled = out.toByteArray();
  120. InputStream in = new ByteArrayInputStream(pickled);
  121. ObjectInputStream ois = new ObjectInputStream(in);
  122. Object o = ois.readObject();
  123. LocationInfoWithLMSIImpl copy = (LocationInfoWithLMSIImpl) o;
  124. //test result
  125. assertEquals(copy.getNetworkNodeNumber(), original.getNetworkNodeNumber());
  126. assertEquals(copy.getLMSI(), original.getLMSI());
  127. }
  128. }