PageRenderTime 41ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 107 lines | 52 code | 24 blank | 31 comment | 0 complexity | d3789538b65794f36af8ecf1199538b2 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.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.asn.Tag;
  34. import org.testng.annotations.Test;
  35. /**
  36. *
  37. * @author sergey vetyutnev
  38. *
  39. */
  40. public class IMSITest {
  41. private byte[] getEncodedData() {
  42. return new byte[] { 4, 8, 16, 33, 2, 2, 16, -119, 34, -9 };
  43. }
  44. @Test(groups = { "functional.decode","primitives"})
  45. public void testDecode() throws Exception {
  46. byte[] rawData = getEncodedData();
  47. AsnInputStream asn = new AsnInputStream(rawData);
  48. int tag = asn.readTag();
  49. IMSIImpl imsi = new IMSIImpl();
  50. imsi.decodeAll(asn);
  51. assertEquals( tag,Tag.STRING_OCTET);
  52. assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
  53. // assertEquals( (long)imsi.getMCC(),11);
  54. // assertEquals( (long)imsi.getMNC(),22);
  55. assertEquals( imsi.getData(),"011220200198227");
  56. }
  57. @Test(groups = { "functional.encode","primitives"})
  58. public void testEncode() throws Exception {
  59. IMSIImpl imsi = new IMSIImpl("011220200198227");
  60. AsnOutputStream asnOS = new AsnOutputStream();
  61. imsi.encodeAll(asnOS, Tag.CLASS_UNIVERSAL, Tag.STRING_OCTET);
  62. byte[] encodedData = asnOS.toByteArray();
  63. byte[] rawData = getEncodedData();
  64. assertTrue( Arrays.equals(rawData,encodedData));
  65. }
  66. @Test(groups = { "functional.serialize", "primitives" })
  67. public void testSerialization() throws Exception {
  68. IMSIImpl original = new IMSIImpl("011220200198227");
  69. // serialize
  70. ByteArrayOutputStream out = new ByteArrayOutputStream();
  71. ObjectOutputStream oos = new ObjectOutputStream(out);
  72. oos.writeObject(original);
  73. oos.close();
  74. // deserialize
  75. byte[] pickled = out.toByteArray();
  76. InputStream in = new ByteArrayInputStream(pickled);
  77. ObjectInputStream ois = new ObjectInputStream(in);
  78. Object o = ois.readObject();
  79. IMSIImpl copy = (IMSIImpl) o;
  80. //test result
  81. assertEquals(copy.getData(), original.getData());
  82. }
  83. }