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

http://mobicents.googlecode.com/ · Java · 119 lines · 68 code · 23 blank · 28 comment · 0 complexity · ed4c81b0ad82bc251b501cfcbf9ac90d 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.ss7.map.api.service.lsm.ResponseTime;
  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 LCSQoSTest {
  46. @BeforeClass
  47. public static void setUpClass() throws Exception {
  48. }
  49. @AfterClass
  50. public static void tearDownClass() throws Exception {
  51. }
  52. @BeforeTest
  53. public void setUp() {
  54. }
  55. @AfterTest
  56. public void tearDown() {
  57. }
  58. @Test(groups = { "functional.decode","service.lsm"})
  59. public void testDecode() throws Exception {
  60. byte[] data = new byte[] { 0x30, 0x05, (byte) 0xa3, 0x03, 0x0a, 0x01, 0x00 };
  61. AsnInputStream asn = new AsnInputStream(data);
  62. int tag = asn.readTag();
  63. LCSQoSImpl lcsQos = new LCSQoSImpl();
  64. lcsQos.decodeAll(asn);
  65. assertNotNull(lcsQos.getResponseTime());
  66. ResponseTime resTime = lcsQos.getResponseTime();
  67. assertNotNull(resTime.getResponseTimeCategory());
  68. assertEquals( resTime.getResponseTimeCategory(),ResponseTimeCategory.lowdelay);
  69. }
  70. @Test(groups = { "functional.encode","service.lsm"})
  71. public void testEncode() throws Exception {
  72. byte[] data = new byte[] { 0x30, 0x05, (byte) 0xa3, 0x03, 0x0a, 0x01, 0x00 };
  73. LCSQoSImpl lcsQos = new LCSQoSImpl(null, null, null, new ResponseTimeImpl(ResponseTimeCategory.lowdelay), null);
  74. AsnOutputStream asnOS = new AsnOutputStream();
  75. lcsQos.encodeAll(asnOS);
  76. byte[] encodedData = asnOS.toByteArray();
  77. assertTrue( Arrays.equals(data,encodedData));
  78. }
  79. @Test(groups = { "functional.serialize", "service.lsm" })
  80. public void testSerialization() throws Exception {
  81. LCSQoSImpl original = new LCSQoSImpl(null, null, null, new ResponseTimeImpl(ResponseTimeCategory.lowdelay), null);
  82. // serialize
  83. ByteArrayOutputStream out = new ByteArrayOutputStream();
  84. ObjectOutputStream oos = new ObjectOutputStream(out);
  85. oos.writeObject(original);
  86. oos.close();
  87. // deserialize
  88. byte[] pickled = out.toByteArray();
  89. InputStream in = new ByteArrayInputStream(pickled);
  90. ObjectInputStream ois = new ObjectInputStream(in);
  91. Object o = ois.readObject();
  92. LCSQoSImpl copy = (LCSQoSImpl) o;
  93. //test result
  94. assertEquals(copy, original);
  95. }
  96. }