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

http://mobicents.googlecode.com/ · Java · 128 lines · 74 code · 24 blank · 30 comment · 0 complexity · 55b6b5534975074d1d08b41d0ce9eebd MD5 · raw file

  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.service.lsm;
  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.AfterClass;
  35. import org.testng.annotations.AfterTest;
  36. import org.testng.annotations.BeforeClass;
  37. import org.testng.annotations.BeforeTest;
  38. import org.testng.annotations.Test;
  39. /**
  40. * TODO : Self generated trace. Get real ones
  41. *
  42. * @author amit bhayani
  43. *
  44. */
  45. public class SupportedLCSCapabilitySetsTest {
  46. private byte[] getEncodedData() {
  47. return new byte[] { 3, 2, 4, 64 };
  48. }
  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[] rawData = getEncodedData();
  64. AsnInputStream asn = new AsnInputStream(rawData);
  65. int tag = asn.readTag();
  66. SupportedLCSCapabilitySetsImpl supportedLCSCapabilityTest = new SupportedLCSCapabilitySetsImpl();
  67. supportedLCSCapabilityTest.decodeAll(asn);
  68. assertEquals( tag,Tag.STRING_BIT);
  69. assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
  70. assertEquals( (boolean)supportedLCSCapabilityTest.getLcsCapabilitySet1(),false);
  71. assertEquals( (boolean)supportedLCSCapabilityTest.getLcsCapabilitySet2(),true);
  72. assertEquals( (boolean)supportedLCSCapabilityTest.getLcsCapabilitySet3(),false);
  73. assertEquals( (boolean)supportedLCSCapabilityTest.getLcsCapabilitySet4(),false);
  74. }
  75. @Test(groups = { "functional.encode","service.lsm"})
  76. public void testEncode() throws Exception {
  77. SupportedLCSCapabilitySetsImpl supportedLCSCapabilityTest = new SupportedLCSCapabilitySetsImpl(false, true, false, false);
  78. AsnOutputStream asnOS = new AsnOutputStream();
  79. supportedLCSCapabilityTest.encodeAll(asnOS);
  80. byte[] encodedData = asnOS.toByteArray();
  81. byte[] rawData = getEncodedData();
  82. assertTrue( Arrays.equals(rawData,encodedData));
  83. }
  84. @Test(groups = { "functional.serialize", "service.lsm" })
  85. public void testSerialization() throws Exception {
  86. SupportedLCSCapabilitySetsImpl original = new SupportedLCSCapabilitySetsImpl(false, true, false, false);
  87. // serialize
  88. ByteArrayOutputStream out = new ByteArrayOutputStream();
  89. ObjectOutputStream oos = new ObjectOutputStream(out);
  90. oos.writeObject(original);
  91. oos.close();
  92. // deserialize
  93. byte[] pickled = out.toByteArray();
  94. InputStream in = new ByteArrayInputStream(pickled);
  95. ObjectInputStream ois = new ObjectInputStream(in);
  96. Object o = ois.readObject();
  97. SupportedLCSCapabilitySetsImpl copy = (SupportedLCSCapabilitySetsImpl) o;
  98. //test result
  99. assertEquals(copy.getLcsCapabilitySet1(), original.getLcsCapabilitySet1());
  100. assertEquals(copy.getLcsCapabilitySet2(), original.getLcsCapabilitySet2());
  101. assertEquals(copy.getLcsCapabilitySet3(), original.getLcsCapabilitySet3());
  102. assertEquals(copy.getLcsCapabilitySet4(), original.getLcsCapabilitySet4());
  103. }
  104. }