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

http://mobicents.googlecode.com/ · Java · 109 lines · 57 code · 23 blank · 29 comment · 0 complexity · d987a9d04b013d09735a488fccb6837a 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.primitives;
  23. import java.io.ByteArrayInputStream;
  24. import java.io.ByteArrayOutputStream;
  25. import java.io.InputStream;
  26. import java.io.ObjectInputStream;
  27. import java.io.ObjectOutputStream;
  28. import java.util.Arrays;
  29. import org.mobicents.protocols.asn.AsnInputStream;
  30. import org.mobicents.protocols.asn.AsnOutputStream;
  31. import org.mobicents.protocols.asn.Tag;
  32. import org.mobicents.protocols.ss7.map.api.primitives.AddressNature;
  33. import org.mobicents.protocols.ss7.map.api.primitives.NumberingPlan;
  34. import static org.testng.Assert.*;
  35. import org.testng.*;import org.testng.annotations.*;
  36. /**
  37. *
  38. * @author sergey vetyutnev
  39. *
  40. */
  41. public class FTNAddressStringTest {
  42. private byte[] getEncodedData() {
  43. return new byte[] { 4, 6, -72, 33, 67, 101, -121, 9 };
  44. }
  45. @Test(groups = { "functional.decode","primitives"})
  46. public void testDecode() throws Exception {
  47. byte[] rawData = getEncodedData();
  48. AsnInputStream asn = new AsnInputStream(rawData);
  49. int tag = asn.readTag();
  50. FTNAddressStringImpl addrStr = new FTNAddressStringImpl();
  51. addrStr.decodeAll(asn);
  52. assertEquals( tag,Tag.STRING_OCTET);
  53. assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
  54. assertEquals( addrStr.getAddressNature(),AddressNature.network_specific_number);
  55. assertEquals( addrStr.getNumberingPlan(),NumberingPlan.national);
  56. assertEquals( addrStr.getAddress(),"1234567890");
  57. }
  58. @Test(groups = { "functional.encode","primitives"})
  59. public void testEncode() throws Exception {
  60. FTNAddressStringImpl addrStr = new FTNAddressStringImpl(AddressNature.network_specific_number, NumberingPlan.national, "1234567890");
  61. AsnOutputStream asnOS = new AsnOutputStream();
  62. addrStr.encodeAll(asnOS);
  63. byte[] encodedData = asnOS.toByteArray();
  64. byte[] rawData = getEncodedData();
  65. assertTrue( Arrays.equals(rawData,encodedData));
  66. }
  67. @Test(groups = { "functional.serialize", "primitives" })
  68. public void testSerialization() throws Exception {
  69. FTNAddressStringImpl original = new FTNAddressStringImpl(AddressNature.network_specific_number, NumberingPlan.national, "1234567890");
  70. // serialize
  71. ByteArrayOutputStream out = new ByteArrayOutputStream();
  72. ObjectOutputStream oos = new ObjectOutputStream(out);
  73. oos.writeObject(original);
  74. oos.close();
  75. // deserialize
  76. byte[] pickled = out.toByteArray();
  77. InputStream in = new ByteArrayInputStream(pickled);
  78. ObjectInputStream ois = new ObjectInputStream(in);
  79. Object o = ois.readObject();
  80. FTNAddressStringImpl copy = (FTNAddressStringImpl) o;
  81. //test result
  82. assertEquals(copy.getAddressNature(), original.getAddressNature());
  83. assertEquals(copy.getNumberingPlan(), original.getNumberingPlan());
  84. assertEquals(copy.getAddress(), original.getAddress());
  85. }
  86. }