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

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

http://mobicents.googlecode.com/
Java | 125 lines | 71 code | 26 blank | 28 comment | 0 complexity | 9cdb141c33d1ae92ad4a76453ba286f7 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.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.ss7.map.MAPParameterFactoryImpl;
  35. import org.mobicents.protocols.ss7.map.api.MAPParameterFactory;
  36. import org.mobicents.protocols.ss7.map.api.primitives.CellGlobalIdOrServiceAreaIdFixedLength;
  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 CellGlobalIdOrServiceAreaIdOrLAITest {
  47. MAPParameterFactory MAPParameterFactory = new MAPParameterFactoryImpl();
  48. @BeforeClass
  49. public static void setUpClass() throws Exception {
  50. }
  51. @AfterClass
  52. public static void tearDownClass() throws Exception {
  53. }
  54. @BeforeTest
  55. public void setUp() {
  56. }
  57. @AfterTest
  58. public void tearDown() {
  59. }
  60. @Test(groups = { "functional.decode","service.lsm"})
  61. public void testDecode() throws Exception {
  62. byte[] data = new byte[] { (byte) 0x80, 0x07, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b };
  63. AsnInputStream asn = new AsnInputStream(data);
  64. int tag = asn.readTag();
  65. CellGlobalIdOrServiceAreaIdOrLAIImpl cellGlobalIdOrServiceAreaIdOrLAI = new CellGlobalIdOrServiceAreaIdOrLAIImpl();
  66. cellGlobalIdOrServiceAreaIdOrLAI.decodeAll(asn);
  67. assertNotNull(cellGlobalIdOrServiceAreaIdOrLAI.getCellGlobalIdOrServiceAreaIdFixedLength());
  68. assertTrue(Arrays.equals(new byte[] { 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b }, cellGlobalIdOrServiceAreaIdOrLAI
  69. .getCellGlobalIdOrServiceAreaIdFixedLength().getData()));
  70. }
  71. @Test(groups = { "functional.encode","service.lsm"})
  72. public void testEncode() throws Exception {
  73. byte[] data = new byte[] { (byte) 0x80, 0x07, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b };
  74. CellGlobalIdOrServiceAreaIdFixedLength par = new CellGlobalIdOrServiceAreaIdFixedLengthImpl(new byte[] { 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b });
  75. CellGlobalIdOrServiceAreaIdOrLAIImpl cellGlobalIdOrServiceAreaIdOrLAI = new CellGlobalIdOrServiceAreaIdOrLAIImpl(par);
  76. AsnOutputStream asnOS = new AsnOutputStream();
  77. cellGlobalIdOrServiceAreaIdOrLAI.encodeAll(asnOS);
  78. byte[] encodedData = asnOS.toByteArray();
  79. assertTrue( Arrays.equals(data,encodedData));
  80. }
  81. @Test(groups = { "functional.serialize", "service.lsm" })
  82. public void testSerialization() throws Exception {
  83. CellGlobalIdOrServiceAreaIdFixedLength par = new CellGlobalIdOrServiceAreaIdFixedLengthImpl(new byte[] { 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b });
  84. CellGlobalIdOrServiceAreaIdOrLAIImpl original = new CellGlobalIdOrServiceAreaIdOrLAIImpl(par);
  85. // serialize
  86. ByteArrayOutputStream out = new ByteArrayOutputStream();
  87. ObjectOutputStream oos = new ObjectOutputStream(out);
  88. oos.writeObject(original);
  89. oos.close();
  90. // deserialize
  91. byte[] pickled = out.toByteArray();
  92. InputStream in = new ByteArrayInputStream(pickled);
  93. ObjectInputStream ois = new ObjectInputStream(in);
  94. Object o = ois.readObject();
  95. CellGlobalIdOrServiceAreaIdOrLAIImpl copy = (CellGlobalIdOrServiceAreaIdOrLAIImpl) o;
  96. //test result
  97. assertEquals(copy, original);
  98. }
  99. }