/protocols/ss7/map/map-impl/src/test/java/org/mobicents/protocols/ss7/map/service/lsm/LCSRequestorIDTest.java

http://mobicents.googlecode.com/ · Java · 129 lines · 76 code · 23 blank · 30 comment · 0 complexity · a8390afc6fee6b9f34602466a4557695 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.lsm;
  23. import static org.testng.Assert.assertEquals;
  24. import static org.testng.Assert.assertNotNull;
  25. import static org.testng.Assert.assertNull;
  26. import static org.testng.Assert.assertTrue;
  27. import java.io.ByteArrayInputStream;
  28. import java.io.ByteArrayOutputStream;
  29. import java.io.InputStream;
  30. import java.io.ObjectInputStream;
  31. import java.io.ObjectOutputStream;
  32. import java.util.Arrays;
  33. import org.mobicents.protocols.asn.AsnInputStream;
  34. import org.mobicents.protocols.asn.AsnOutputStream;
  35. import org.mobicents.protocols.asn.Tag;
  36. import org.mobicents.protocols.ss7.map.MAPParameterFactoryImpl;
  37. import org.mobicents.protocols.ss7.map.api.MAPParameterFactory;
  38. import org.mobicents.protocols.ss7.map.api.primitives.USSDString;
  39. import org.testng.annotations.AfterClass;
  40. import org.testng.annotations.AfterTest;
  41. import org.testng.annotations.BeforeClass;
  42. import org.testng.annotations.BeforeTest;
  43. import org.testng.annotations.Test;
  44. /**
  45. * TODO Add test for LCS-FormatIndicator
  46. *
  47. * @author amit bhayani
  48. *
  49. */
  50. public class LCSRequestorIDTest {
  51. MAPParameterFactory MAPParameterFactory = new MAPParameterFactoryImpl();
  52. @BeforeClass
  53. public static void setUpClass() throws Exception {
  54. }
  55. @AfterClass
  56. public static void tearDownClass() throws Exception {
  57. }
  58. @BeforeTest
  59. public void setUp() {
  60. }
  61. @AfterTest
  62. public void tearDown() {
  63. }
  64. @Test(groups = { "functional.decode","service.lsm"})
  65. public void testDecode() throws Exception {
  66. byte[] data = new byte[] { (byte) 0xb0, 0x13, (byte) 0x80, 0x01, 0x0f, (byte) 0x81, 0x0e, 0x6e, 0x72, (byte) 0xfb, 0x1c, (byte) 0x86, (byte) 0xc3,
  67. 0x65, 0x6e, 0x72, (byte) 0xfb, 0x1c, (byte) 0x86, (byte) 0xc3, 0x65 };
  68. AsnInputStream asn = new AsnInputStream(data);
  69. int tag = asn.readTag();
  70. LCSRequestorIDImpl lcsRequestorID = new LCSRequestorIDImpl();
  71. lcsRequestorID.decodeAll(asn);
  72. assertEquals( lcsRequestorID.getDataCodingScheme(),(byte) 0x0f);
  73. assertNotNull(lcsRequestorID.getRequestorIDString());
  74. assertEquals( lcsRequestorID.getRequestorIDString().getString(),"ndmgapp2ndmgapp2");
  75. assertNull(lcsRequestorID.getLCSFormatIndicator());
  76. }
  77. @Test(groups = { "functional.encode","service.lsm"})
  78. public void testEncode() throws Exception {
  79. byte[] data = new byte[] { (byte) 0xb0, 0x13, (byte) 0x80, 0x01, 0x0f, (byte) 0x81, 0x0e, 0x6e, 0x72, (byte) 0xfb, 0x1c, (byte) 0x86, (byte) 0xc3,
  80. 0x65, 0x6e, 0x72, (byte) 0xfb, 0x1c, (byte) 0x86, (byte) 0xc3, 0x65 };
  81. USSDString nameString = MAPParameterFactory.createUSSDString("ndmgapp2ndmgapp2");
  82. LCSRequestorIDImpl lcsRequestorID = new LCSRequestorIDImpl((byte) 0x0f, nameString, null);
  83. AsnOutputStream asnOS = new AsnOutputStream();
  84. lcsRequestorID.encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, Tag.SEQUENCE);
  85. byte[] encodedData = asnOS.toByteArray();
  86. assertTrue( Arrays.equals(data,encodedData));
  87. }
  88. @Test(groups = { "functional.serialize", "service.lsm" })
  89. public void testSerialization() throws Exception {
  90. USSDString nameString = MAPParameterFactory.createUSSDString("ndmgapp2ndmgapp2");
  91. LCSRequestorIDImpl original = new LCSRequestorIDImpl((byte) 0x0f, nameString, null);
  92. // serialize
  93. ByteArrayOutputStream out = new ByteArrayOutputStream();
  94. ObjectOutputStream oos = new ObjectOutputStream(out);
  95. oos.writeObject(original);
  96. oos.close();
  97. // deserialize
  98. byte[] pickled = out.toByteArray();
  99. InputStream in = new ByteArrayInputStream(pickled);
  100. ObjectInputStream ois = new ObjectInputStream(in);
  101. Object o = ois.readObject();
  102. LCSRequestorIDImpl copy = (LCSRequestorIDImpl) o;
  103. //test result
  104. assertEquals(copy, original);
  105. }
  106. }