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

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