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

http://mobicents.googlecode.com/ · Java · 145 lines · 84 code · 31 blank · 30 comment · 0 complexity · 3b5cbac811b3d3c40ff90340035b78eb 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.assertTrue;
  26. import java.io.ByteArrayInputStream;
  27. import java.io.ByteArrayOutputStream;
  28. import java.io.InputStream;
  29. import java.io.ObjectInputStream;
  30. import java.io.ObjectOutputStream;
  31. import java.util.Arrays;
  32. import org.mobicents.protocols.asn.AsnInputStream;
  33. import org.mobicents.protocols.asn.AsnOutputStream;
  34. import org.mobicents.protocols.asn.Tag;
  35. import org.mobicents.protocols.ss7.map.MAPParameterFactoryImpl;
  36. import org.mobicents.protocols.ss7.map.api.MAPParameterFactory;
  37. import org.mobicents.protocols.ss7.map.api.service.lsm.Area;
  38. import org.mobicents.protocols.ss7.map.api.service.lsm.AreaDefinition;
  39. import org.mobicents.protocols.ss7.map.api.service.lsm.AreaList;
  40. import org.mobicents.protocols.ss7.map.api.service.lsm.AreaType;
  41. import org.testng.annotations.AfterClass;
  42. import org.testng.annotations.AfterTest;
  43. import org.testng.annotations.BeforeClass;
  44. import org.testng.annotations.BeforeTest;
  45. import org.testng.annotations.Test;
  46. /**
  47. * @author amit bhayani
  48. *
  49. */
  50. public class AreaDefinitionTest {
  51. MAPParameterFactory MAPParameterFactory = new MAPParameterFactoryImpl();
  52. @BeforeClass
  53. public static void setUpClass() throws Exception {
  54. }
  55. @AfterClass
  56. public static void tearDownClass() throws Exception {
  57. }
  58. @BeforeTest
  59. public void setUp() {
  60. }
  61. @AfterTest
  62. public void tearDown() {
  63. }
  64. @Test(groups = { "functional.decode","service.lsm"})
  65. public void testDecode() throws Exception {
  66. // TODO this is self generated trace. We need trace from operator
  67. byte[] data = new byte[] { 0x30, 0x16, (byte) 0xa0, 0x14, 0x30, 0x08, (byte) 0x80, 0x01, 0x05, (byte) 0x81, 0x03, 0x09, 0x70, 0x71, 0x30, 0x08, (byte) 0x80, 0x01,
  68. 0x03, (byte) 0x81, 0x03, 0x04, 0x30, 0x31 };
  69. AsnInputStream asn = new AsnInputStream(data);
  70. int tag = asn.readTag();
  71. AreaDefinition areaDef = new AreaDefinitionImpl();
  72. ((AreaDefinitionImpl)areaDef).decodeAll(asn);
  73. AreaList areaList = areaDef.getAreaList();
  74. assertNotNull(areaList);
  75. assertEquals( areaList.getAreas().length,2);
  76. Area[] areas = areaList.getAreas();
  77. assertNotNull(areas[0].getAreaIdentification());
  78. assertTrue(Arrays.equals(new byte[] { 0x09, 0x70, 0x71 }, areas[0].getAreaIdentification()));
  79. }
  80. @Test(groups = { "functional.encode","service.lsm"})
  81. public void testEncode() throws Exception {
  82. // TODO this is self generated trace. We need trace from operator
  83. byte[] data = new byte[] { 0x30, 0x16, (byte) 0xa0, 0x14, 0x30, 0x08, (byte) 0x80, 0x01, 0x05, (byte) 0x81, 0x03, 0x09, 0x70, 0x71, 0x30, 0x08, (byte) 0x80, 0x01,
  84. 0x03, (byte) 0x81, 0x03, 0x04, 0x30, 0x31 };
  85. Area area1 = new AreaImpl(AreaType.utranCellId, new byte[] { 0x09, 0x70, 0x71 });
  86. Area area2 = new AreaImpl(AreaType.routingAreaId, new byte[] { 0x04, 0x30, 0x31 });
  87. AreaList areaList = new AreaListImpl(new Area[] { area1, area2 });
  88. AreaDefinition areaDef = new AreaDefinitionImpl(areaList);
  89. AsnOutputStream asnOS = new AsnOutputStream();
  90. ((AreaDefinitionImpl)areaDef).encodeAll(asnOS, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
  91. byte[] encodedData = asnOS.toByteArray();
  92. assertTrue( Arrays.equals(data,encodedData));
  93. }
  94. @Test(groups = { "functional.serialize", "service.lsm" })
  95. public void testSerialization() throws Exception {
  96. Area area1 = new AreaImpl(AreaType.utranCellId, new byte[] { 0x09, 0x70, 0x71 });
  97. Area area2 = new AreaImpl(AreaType.routingAreaId, new byte[] { 0x04, 0x30, 0x31 });
  98. AreaList areaList = new AreaListImpl(new Area[] { area1, area2 });
  99. AreaDefinition original = new AreaDefinitionImpl(areaList);
  100. // serialize
  101. ByteArrayOutputStream out = new ByteArrayOutputStream();
  102. ObjectOutputStream oos = new ObjectOutputStream(out);
  103. oos.writeObject(original);
  104. oos.close();
  105. // deserialize
  106. byte[] pickled = out.toByteArray();
  107. InputStream in = new ByteArrayInputStream(pickled);
  108. ObjectInputStream ois = new ObjectInputStream(in);
  109. Object o = ois.readObject();
  110. AreaDefinitionImpl copy = (AreaDefinitionImpl) o;
  111. //test result
  112. assertEquals(copy.getAreaList(), original.getAreaList());
  113. }
  114. }