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

http://mobicents.googlecode.com/ · Java · 117 lines · 66 code · 23 blank · 28 comment · 0 complexity · 3276290bfa1761620608ea22b2e9d624 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.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.ss7.map.MAPParameterFactoryImpl;
  34. import org.mobicents.protocols.ss7.map.api.MAPParameterFactory;
  35. import org.mobicents.protocols.ss7.map.api.service.lsm.ResponseTimeCategory;
  36. import org.testng.annotations.AfterClass;
  37. import org.testng.annotations.AfterTest;
  38. import org.testng.annotations.BeforeClass;
  39. import org.testng.annotations.BeforeTest;
  40. import org.testng.annotations.Test;
  41. /**
  42. * @author amit bhayani
  43. *
  44. */
  45. public class ResponseTimeTest {
  46. MAPParameterFactory MAPParameterFactory = new MAPParameterFactoryImpl();
  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, 0x0a, 0x01, 0x00 };
  62. AsnInputStream asn = new AsnInputStream(data);
  63. int tag = asn.readTag();
  64. ResponseTimeImpl responseTime = new ResponseTimeImpl();
  65. responseTime.decodeAll(asn);
  66. assertEquals( responseTime.getResponseTimeCategory(),ResponseTimeCategory.lowdelay);
  67. }
  68. @Test(groups = { "functional.encode","service.lsm"})
  69. public void testEncode() throws Exception {
  70. byte[] data = new byte[] { 0x30, 0x03, 0x0a, 0x01, 0x00 };
  71. ResponseTimeImpl responseTime = new ResponseTimeImpl(ResponseTimeCategory.lowdelay);
  72. AsnOutputStream asnOS = new AsnOutputStream();
  73. responseTime.encodeAll(asnOS);
  74. byte[] encodedData = asnOS.toByteArray();
  75. assertTrue( Arrays.equals(data,encodedData));
  76. }
  77. @Test(groups = { "functional.serialize", "service.lsm" })
  78. public void testSerialization() throws Exception {
  79. ResponseTimeImpl original = new ResponseTimeImpl(ResponseTimeCategory.lowdelay);
  80. // serialize
  81. ByteArrayOutputStream out = new ByteArrayOutputStream();
  82. ObjectOutputStream oos = new ObjectOutputStream(out);
  83. oos.writeObject(original);
  84. oos.close();
  85. // deserialize
  86. byte[] pickled = out.toByteArray();
  87. InputStream in = new ByteArrayInputStream(pickled);
  88. ObjectInputStream ois = new ObjectInputStream(in);
  89. Object o = ois.readObject();
  90. ResponseTimeImpl copy = (ResponseTimeImpl) o;
  91. //test result
  92. assertEquals(copy, original);
  93. }
  94. }