PageRenderTime 20ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 104 lines | 52 code | 23 blank | 29 comment | 0 complexity | 7b0e8759b8b870aff38cc093f561bc6a 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.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.mobicents.protocols.asn.Tag;
  34. import org.testng.annotations.Test;
  35. /**
  36. *
  37. * @author sergey vetyutnev
  38. *
  39. */
  40. public class LMSITest {
  41. private byte[] getEncodedData() {
  42. return new byte[] { 4, 4, 0, 3, 98, 49 };
  43. }
  44. @Test(groups = { "functional.decode","primitives"})
  45. public void testDecode() throws Exception {
  46. byte[] rawData = getEncodedData();
  47. AsnInputStream asn = new AsnInputStream(rawData);
  48. int tag = asn.readTag();
  49. LMSIImpl lmsi = new LMSIImpl();
  50. lmsi.decodeAll(asn);
  51. assertEquals( tag,Tag.STRING_OCTET);
  52. assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
  53. assertTrue(Arrays.equals(new byte[] { 0, 3, 98, 49 }, lmsi.getData()));
  54. }
  55. @Test(groups = { "functional.encode","primitives"})
  56. public void testEncode() throws Exception {
  57. LMSIImpl lmsi = new LMSIImpl(new byte[] { 0, 3, 98, 49 });
  58. AsnOutputStream asnOS = new AsnOutputStream();
  59. lmsi.encodeAll(asnOS, Tag.CLASS_UNIVERSAL, Tag.STRING_OCTET);
  60. byte[] encodedData = asnOS.toByteArray();
  61. byte[] rawData = getEncodedData();
  62. assertTrue( Arrays.equals(rawData,encodedData));
  63. }
  64. @Test(groups = { "functional.serialize", "primitives" })
  65. public void testSerialization() throws Exception {
  66. LMSIImpl original = new LMSIImpl(new byte[] { 0, 3, 98, 49 });
  67. // serialize
  68. ByteArrayOutputStream out = new ByteArrayOutputStream();
  69. ObjectOutputStream oos = new ObjectOutputStream(out);
  70. oos.writeObject(original);
  71. oos.close();
  72. // deserialize
  73. byte[] pickled = out.toByteArray();
  74. InputStream in = new ByteArrayInputStream(pickled);
  75. ObjectInputStream ois = new ObjectInputStream(in);
  76. Object o = ois.readObject();
  77. LMSIImpl copy = (LMSIImpl) o;
  78. //test result
  79. assertEquals(copy.getData(), original.getData());
  80. }
  81. }