PageRenderTime 25ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/protocols/ss7/map/map-impl/src/test/java/org/mobicents/protocols/ss7/map/primitives/USSDStringTest.java

http://mobicents.googlecode.com/
Java | 114 lines | 62 code | 21 blank | 31 comment | 0 complexity | 031ba0b9164fe92bcda576f377a70563 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/or its affiliates, and individual
  4. * contributors as indicated by the @authors tag. All rights reserved.
  5. * See the copyright.txt in the distribution for a full listing
  6. * of individual contributors.
  7. *
  8. * This copyrighted material is made available to anyone wishing to use,
  9. * modify, copy, or redistribute it subject to the terms and conditions
  10. * of the GNU General Public License, v. 2.0.
  11. *
  12. * This program 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. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License,
  18. * v. 2.0 along with this distribution; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20. * MA 02110-1301, USA.
  21. */
  22. package org.mobicents.protocols.ss7.map.primitives;
  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.testng.annotations.AfterClass;
  34. import org.testng.annotations.AfterTest;
  35. import org.testng.annotations.BeforeClass;
  36. import org.testng.annotations.BeforeTest;
  37. import org.testng.annotations.Test;
  38. /**
  39. * @author amit bhayani
  40. *
  41. */
  42. public class USSDStringTest {
  43. @BeforeClass
  44. public static void setUpClass() throws Exception {
  45. }
  46. @AfterClass
  47. public static void tearDownClass() throws Exception {
  48. }
  49. @BeforeTest
  50. public void setUp() {
  51. }
  52. @AfterTest
  53. public void tearDown() {
  54. }
  55. @Test(groups = { "functional.decode","primitives"})
  56. public void testDecode() throws Exception {
  57. byte[] data = new byte[] { 0x04, 0x04, 0x2a, 0x1c, 0x6e, (byte)0x04 };
  58. AsnInputStream asn = new AsnInputStream(data);
  59. int tag = asn.readTag();
  60. USSDStringImpl ussdStr = new USSDStringImpl();
  61. ussdStr.decodeAll(asn);
  62. assertEquals( ussdStr.getString(),"*88#");
  63. }
  64. //TODO Fix the GSMEncoder. This is failing
  65. @Test(groups = { "functional.encode","primitives"})
  66. public void testEncode() throws Exception {
  67. byte[] data = new byte[] { 0x04, 0x04, 0x2a, 0x1c, 0x6e, (byte)0x04 };
  68. USSDStringImpl ussdStr = new USSDStringImpl("*88#", null);
  69. AsnOutputStream asnOS = new AsnOutputStream();
  70. ussdStr.encodeAll(asnOS);
  71. byte[] encodedData = asnOS.toByteArray();
  72. assertTrue( Arrays.equals(data,encodedData));
  73. }
  74. @Test(groups = { "functional.serialize", "primitives" })
  75. public void testSerialization() throws Exception {
  76. USSDStringImpl original = new USSDStringImpl("*88#", null);
  77. // serialize
  78. ByteArrayOutputStream out = new ByteArrayOutputStream();
  79. ObjectOutputStream oos = new ObjectOutputStream(out);
  80. oos.writeObject(original);
  81. oos.close();
  82. // deserialize
  83. byte[] pickled = out.toByteArray();
  84. InputStream in = new ByteArrayInputStream(pickled);
  85. ObjectInputStream ois = new ObjectInputStream(in);
  86. Object o = ois.readObject();
  87. USSDStringImpl copy = (USSDStringImpl) o;
  88. //test result
  89. assertEquals(copy.getString(), original.getString());
  90. //TODO Charset is not Serializable now
  91. //assertEquals(copy.getCharset(), original.getCharset());
  92. }
  93. }