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

http://mobicents.googlecode.com/ · Java · 157 lines · 95 code · 34 blank · 28 comment · 0 complexity · 6c9bcc6d1c83bdfbee62b6298eaa7d29 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.assertNull;
  26. import static org.testng.Assert.assertTrue;
  27. import java.io.ByteArrayInputStream;
  28. import java.io.ByteArrayOutputStream;
  29. import java.io.InputStream;
  30. import java.io.ObjectInputStream;
  31. import java.io.ObjectOutputStream;
  32. import java.util.Arrays;
  33. import org.mobicents.protocols.asn.AsnInputStream;
  34. import org.mobicents.protocols.asn.AsnOutputStream;
  35. import org.mobicents.protocols.ss7.map.api.service.lsm.DeferredLocationEventType;
  36. import org.mobicents.protocols.ss7.map.api.service.lsm.LocationEstimateType;
  37. import org.testng.annotations.AfterClass;
  38. import org.testng.annotations.AfterTest;
  39. import org.testng.annotations.BeforeClass;
  40. import org.testng.annotations.BeforeTest;
  41. import org.testng.annotations.Test;
  42. /**
  43. * @author amit bhayani
  44. *
  45. */
  46. public class LocationTypeTest {
  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[] data = new byte[] { 0x30, 0x03, (byte) 0x80, 0x01, 0x00 };
  62. AsnInputStream asn = new AsnInputStream(data);
  63. int tag = asn.readTag();
  64. LocationTypeImpl locType = new LocationTypeImpl();
  65. locType.decodeAll(asn);
  66. assertNotNull(locType.getLocationEstimateType());
  67. assertEquals( locType.getLocationEstimateType(),LocationEstimateType.currentLocation);
  68. assertNull(locType.getDeferredLocationEventType());
  69. }
  70. @Test(groups = { "functional.encode","service.lsm"})
  71. public void testEncode() throws Exception {
  72. byte[] data = new byte[] { 0x30, 0x03, (byte) 0x80, 0x01, 0x00 };
  73. LocationTypeImpl locType = new LocationTypeImpl(LocationEstimateType.currentLocation, null);
  74. AsnOutputStream asnOS = new AsnOutputStream();
  75. locType.encodeAll(asnOS);
  76. byte[] encodedData = asnOS.toByteArray();
  77. assertTrue( Arrays.equals(data,encodedData));
  78. }
  79. @Test(groups = { "functional.decode","service.lsm"})
  80. public void testDecode1() throws Exception {
  81. byte[] data = new byte[] { 0x30, 0x07, (byte) 0x80, 0x01, 0x00, (byte) 0x81, 0x02, 0x04, (byte) -16 };
  82. AsnInputStream asn = new AsnInputStream(data);
  83. int tag = asn.readTag();
  84. LocationTypeImpl locType = new LocationTypeImpl();
  85. locType.decodeAll(asn);
  86. assertNotNull(locType.getLocationEstimateType());
  87. assertEquals( locType.getLocationEstimateType(),LocationEstimateType.currentLocation);
  88. assertNotNull(locType.getDeferredLocationEventType());
  89. assertNotNull(locType.getDeferredLocationEventType());
  90. assertTrue(locType.getDeferredLocationEventType().getEnteringIntoArea());
  91. assertTrue(locType.getDeferredLocationEventType().getMsAvailable());
  92. assertTrue(locType.getDeferredLocationEventType().getLeavingFromArea());
  93. assertTrue(locType.getDeferredLocationEventType().getBeingInsideArea());
  94. }
  95. @Test(groups = { "functional.encode","service.lsm"})
  96. public void testEncode1() throws Exception {
  97. byte[] data = new byte[] { 0x30, 0x07, (byte) 0x80, 0x01, 0x00, (byte) 0x81, 0x02, 0x04, (byte) -16 };
  98. DeferredLocationEventType deferredLocationEventType = new DeferredLocationEventTypeImpl(true, true, true, true);
  99. LocationTypeImpl locType = new LocationTypeImpl(LocationEstimateType.currentLocation, deferredLocationEventType);
  100. AsnOutputStream asnOS = new AsnOutputStream();
  101. locType.encodeAll(asnOS);
  102. byte[] encodedData = asnOS.toByteArray();
  103. assertTrue( Arrays.equals(data,encodedData));
  104. }
  105. @Test(groups = { "functional.serialize", "service.lsm" })
  106. public void testSerialization() throws Exception {
  107. DeferredLocationEventType deferredLocationEventType = new DeferredLocationEventTypeImpl(true, true, true, true);
  108. LocationTypeImpl original = new LocationTypeImpl(LocationEstimateType.currentLocation, deferredLocationEventType);
  109. // serialize
  110. ByteArrayOutputStream out = new ByteArrayOutputStream();
  111. ObjectOutputStream oos = new ObjectOutputStream(out);
  112. oos.writeObject(original);
  113. oos.close();
  114. // deserialize
  115. byte[] pickled = out.toByteArray();
  116. InputStream in = new ByteArrayInputStream(pickled);
  117. ObjectInputStream ois = new ObjectInputStream(in);
  118. Object o = ois.readObject();
  119. LocationTypeImpl copy = (LocationTypeImpl) o;
  120. //test result
  121. assertEquals(copy, original);
  122. }
  123. }