/protocols/ss7/map/map-impl/src/test/java/org/mobicents/protocols/ss7/map/dialog/MAPProviderAbortInfoTest.java

http://mobicents.googlecode.com/ · Java · 113 lines · 54 code · 31 blank · 28 comment · 0 complexity · 121729b8e5a961a83ea84f822e0bf08d 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.dialog;
  23. import java.util.Arrays;
  24. import static org.testng.Assert.*;
  25. import org.testng.*;import org.testng.annotations.*;
  26. import org.mobicents.protocols.asn.AsnInputStream;
  27. import org.mobicents.protocols.asn.AsnOutputStream;
  28. import org.mobicents.protocols.ss7.map.api.dialog.MAPProviderAbortReason;
  29. import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerTest;
  30. /**
  31. *
  32. * @author amit bhayani
  33. *
  34. */
  35. public class MAPProviderAbortInfoTest {
  36. private byte[] getDataFull() {
  37. return new byte[] { -91, 44, 10, 1, 1, 48, 39, -96, 32, 48, 10, 6, 3, 42, 3, 4, 11, 12, 13, 14, 15, 48, 5, 6, 3, 42, 3, 6, 48, 11, 6, 3, 42, 3, 5, 21,
  38. 22, 23, 24, 25, 26, -95, 3, 31, 32, 33 };
  39. }
  40. @Test(groups = { "functional.decode","dialog"})
  41. public void testDecode() throws Exception {
  42. // The raw data is from last packet of long ussd-abort from msc2.txt
  43. byte[] data = new byte[] { (byte) 0xA5, 0x03, (byte) 0x0A, 0x01, 0x00 };
  44. AsnInputStream asnIs = new AsnInputStream(data);
  45. int tag = asnIs.readTag();
  46. assertEquals( tag,5);
  47. MAPProviderAbortInfoImpl mapProviderAbortInfo = new MAPProviderAbortInfoImpl();
  48. mapProviderAbortInfo.decodeAll(asnIs);
  49. MAPProviderAbortReason reason = mapProviderAbortInfo
  50. .getMAPProviderAbortReason();
  51. assertNotNull(reason);
  52. assertEquals( reason,MAPProviderAbortReason.abnormalDialogue);
  53. data = this.getDataFull();
  54. asnIs = new AsnInputStream(data);
  55. tag = asnIs.readTag();
  56. assertEquals( tag,5);
  57. mapProviderAbortInfo = new MAPProviderAbortInfoImpl();
  58. mapProviderAbortInfo.decodeAll(asnIs);
  59. reason = mapProviderAbortInfo.getMAPProviderAbortReason();
  60. assertNotNull(reason);
  61. assertEquals( reason,MAPProviderAbortReason.invalidPDU);
  62. assertTrue(MAPExtensionContainerTest.CheckTestExtensionContainer(mapProviderAbortInfo.getExtensionContainer()));
  63. }
  64. @Test(groups = { "functional.encode","dialog"})
  65. public void testEncode() throws Exception {
  66. MAPProviderAbortInfoImpl mapProviderAbortInfo = new MAPProviderAbortInfoImpl();
  67. mapProviderAbortInfo.setMAPProviderAbortReason(MAPProviderAbortReason.invalidPDU);
  68. AsnOutputStream asnOS = new AsnOutputStream();
  69. mapProviderAbortInfo.encodeAll(asnOS);
  70. byte[] data = asnOS.toByteArray();
  71. // System.out.println(dump(data, data.length, false));
  72. assertTrue(Arrays.equals(new byte[] { (byte) 0xA5, 0x03, (byte) 0x0A,
  73. 0x01, 0x01 }, data));
  74. mapProviderAbortInfo = new MAPProviderAbortInfoImpl();
  75. mapProviderAbortInfo.setMAPProviderAbortReason(MAPProviderAbortReason.invalidPDU);
  76. mapProviderAbortInfo.setExtensionContainer(MAPExtensionContainerTest.GetTestExtensionContainer());
  77. asnOS = new AsnOutputStream();
  78. mapProviderAbortInfo.encodeAll(asnOS);
  79. data = asnOS.toByteArray();
  80. assertTrue(Arrays.equals(this.getDataFull(), data));
  81. }
  82. }