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

http://mobicents.googlecode.com/ · Java · 124 lines · 74 code · 22 blank · 28 comment · 0 complexity · 7bf35d7ad1e3da2927b5cfcc2e822278 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. * @author amit bhayani
  41. *
  42. */
  43. public class SupportedGADShapesTest {
  44. private byte[] getEncodedData() {
  45. return new byte[] { (byte)0x03, 0x02, 0x01, (byte) 0xfe };
  46. }
  47. @BeforeClass
  48. public static void setUpClass() throws Exception {
  49. }
  50. @AfterClass
  51. public static void tearDownClass() throws Exception {
  52. }
  53. @BeforeTest
  54. public void setUp() {
  55. }
  56. @AfterTest
  57. public void tearDown() {
  58. }
  59. @Test(groups = { "functional.decode","service.lsm"})
  60. public void testDecode() throws Exception {
  61. byte[] rawData = getEncodedData();
  62. AsnInputStream asn = new AsnInputStream(rawData);
  63. int tag = asn.readTag();
  64. SupportedGADShapesImpl supportedLCSCapabilityTest = new SupportedGADShapesImpl();
  65. supportedLCSCapabilityTest.decodeAll(asn);
  66. assertEquals( tag,Tag.STRING_BIT);
  67. assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
  68. assertEquals( (boolean) supportedLCSCapabilityTest.getEllipsoidArc(),true);
  69. assertEquals( (boolean) supportedLCSCapabilityTest.getEllipsoidPoint(),true);
  70. assertEquals( (boolean) supportedLCSCapabilityTest.getEllipsoidPointWithAltitude(),true);
  71. assertEquals( (boolean) supportedLCSCapabilityTest.getEllipsoidPointWithAltitudeAndUncertaintyElipsoid(),true);
  72. assertEquals( (boolean) supportedLCSCapabilityTest.getEllipsoidPointWithUncertaintyCircle(),true);
  73. assertEquals( (boolean) supportedLCSCapabilityTest.getEllipsoidPointWithUncertaintyEllipse(),true);
  74. assertEquals( (boolean) supportedLCSCapabilityTest.getPolygon(),true);
  75. }
  76. @Test(groups = { "functional.encode","service.lsm"})
  77. public void testEncode() throws Exception {
  78. SupportedGADShapesImpl supportedLCSCapabilityTest = new SupportedGADShapesImpl(true, true, true, true, true, true, true);
  79. AsnOutputStream asnOS = new AsnOutputStream();
  80. supportedLCSCapabilityTest.encodeAll(asnOS);
  81. byte[] encodedData = asnOS.toByteArray();
  82. byte[] rawData = getEncodedData();
  83. assertTrue( Arrays.equals(rawData,encodedData));
  84. }
  85. @Test(groups = { "functional.serialize", "service.lsm" })
  86. public void testSerialization() throws Exception {
  87. SupportedGADShapesImpl original = new SupportedGADShapesImpl(true, true, true, true, true, true, true);
  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. SupportedGADShapesImpl copy = (SupportedGADShapesImpl) o;
  99. //test result
  100. assertEquals(copy, original);
  101. }
  102. }