/protocols/ss7/inap/inap-impl/src/test/java/org/mobicents/protocols/ss7/inap/primitives/LegIDTest.java

http://mobicents.googlecode.com/ · Java · 86 lines · 45 code · 15 blank · 26 comment · 0 complexity · 1ed46ef77bd0f07a8533a27fbcd14311 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.inap.primitives;
  23. import static org.testng.Assert.*;
  24. import java.util.Arrays;
  25. import org.mobicents.protocols.asn.AsnInputStream;
  26. import org.mobicents.protocols.asn.AsnOutputStream;
  27. import org.mobicents.protocols.ss7.inap.api.primitives.LegType;
  28. import org.testng.*;import org.testng.annotations.*;
  29. /**
  30. *
  31. * @author sergey vetyutnev
  32. *
  33. */
  34. public class LegIDTest {
  35. private byte[] getData1() {
  36. return new byte[] { (byte) 128, 1, 2 };
  37. }
  38. private byte[] getData2() {
  39. return new byte[] { (byte) 129, 1, 1 };
  40. }
  41. @Test(groups = { "functional.decode","primitives"})
  42. public void testDecode() throws Exception {
  43. byte[] data = this.getData1();
  44. AsnInputStream ais = new AsnInputStream(data);
  45. LegIDImpl legId = new LegIDImpl();
  46. int tag = ais.readTag();
  47. legId.decodeAll(ais);
  48. assertNotNull(legId.getSendingSideID());
  49. assertNull(legId.getReceivingSideID());
  50. assertEquals(legId.getSendingSideID(), LegType.leg2);
  51. data = this.getData2();
  52. ais = new AsnInputStream(data);
  53. legId = new LegIDImpl();
  54. tag = ais.readTag();
  55. legId.decodeAll(ais);
  56. assertNull(legId.getSendingSideID());
  57. assertNotNull(legId.getReceivingSideID());
  58. assertEquals(legId.getReceivingSideID(), LegType.leg1);
  59. }
  60. @Test(groups = { "functional.encode","primitives"})
  61. public void testEncode() throws Exception {
  62. LegIDImpl legId = new LegIDImpl(true, LegType.leg2);
  63. AsnOutputStream aos = new AsnOutputStream();
  64. legId.encodeAll(aos);
  65. assertTrue(Arrays.equals(aos.toByteArray(), this.getData1()));
  66. legId = new LegIDImpl(false, LegType.leg1);
  67. aos.reset();
  68. legId.encodeAll(aos);
  69. assertTrue(Arrays.equals(aos.toByteArray(), this.getData2()));
  70. }
  71. }