/protocols/ss7/map/map-impl/src/test/java/org/mobicents/protocols/ss7/map/service/supplementary/UnstructuredSSRequestIndicationTest.java

http://mobicents.googlecode.com/ · Java · 98 lines · 54 code · 19 blank · 25 comment · 0 complexity · ce3fc4b84405e697d86d20d97082fe6b MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual
  4. * contributors as indicated by the @authors tag. All rights reserved.
  5. * See the copyright.txt in the distribution for a full listing
  6. * of individual contributors.
  7. *
  8. * This copyrighted material is made available to anyone wishing to use,
  9. * modify, copy, or redistribute it subject to the terms and conditions
  10. * of the GNU General Public License, v. 2.0.
  11. *
  12. * This program 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. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License,
  18. * v. 2.0 along with this distribution; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20. * MA 02110-1301, USA.
  21. */
  22. package org.mobicents.protocols.ss7.map.service.supplementary;
  23. import static org.testng.Assert.*;
  24. import org.testng.*;
  25. import org.testng.annotations.*;
  26. import java.util.Arrays;
  27. import org.mobicents.protocols.asn.AsnInputStream;
  28. import org.mobicents.protocols.asn.AsnOutputStream;
  29. import org.mobicents.protocols.ss7.map.api.primitives.USSDString;
  30. import org.mobicents.protocols.ss7.map.primitives.USSDStringImpl;
  31. /**
  32. * @author amit bhayani
  33. *
  34. */
  35. public class UnstructuredSSRequestIndicationTest {
  36. @BeforeClass
  37. public static void setUpClass() throws Exception {
  38. }
  39. @AfterClass
  40. public static void tearDownClass() throws Exception {
  41. }
  42. @BeforeTest
  43. public void setUp() {
  44. }
  45. @AfterTest
  46. public void tearDown() {
  47. }
  48. @Test(groups = { "functional.decode","service.ussd"})
  49. public void testDecode() throws Exception {
  50. byte[] data = new byte[] { 0x30, 0x3e, 0x04, 0x01, 0x0f, 0x04, 0x39, (byte) 0xd5, (byte) 0xe9, (byte) 0x94, 0x08, (byte) 0x9a, (byte) 0xd2,
  51. (byte) 0xe5, 0x69, (byte) 0xf7, 0x19, (byte) 0xa4, 0x03, 0x21, (byte) 0xcb, 0x6c, (byte) 0xf6, 0x1b, 0x74, 0x7d, (byte) 0xcb, (byte) 0xd9,
  52. 0x64, 0x10, 0x6f, 0x28, (byte) 0xf5, (byte) 0x81, 0x62, 0x2e, (byte) 0x90, 0x30, (byte) 0xcc, 0x0e, (byte) 0xbb, (byte) 0xc7, 0x65, 0x10, 0x6f,
  53. 0x28, (byte) 0xf5, (byte) 0x81, 0x64, 0x2e, 0x10, (byte) 0xb5, (byte) 0x8c, (byte) 0xa7, (byte) 0xcf, 0x41, (byte) 0xd2, 0x72, 0x3b,
  54. (byte) 0x9c, 0x76, (byte) 0xa7, (byte) 0xdd, 0x67 };
  55. AsnInputStream asn = new AsnInputStream(data);
  56. int tag = asn.readTag();
  57. UnstructuredSSRequestIndicationImpl addNum = new UnstructuredSSRequestIndicationImpl();
  58. addNum.decodeAll(asn);
  59. byte dataCodingScheme = addNum.getUSSDDataCodingScheme();
  60. assertEquals( dataCodingScheme,(byte) 0x0f);
  61. USSDString ussdString = addNum.getUSSDString();
  62. assertNotNull(ussdString);
  63. assertEquals( ussdString.getString(),"USSD String : Hello World <CR> 1. Balance <CR> 2. Texts Remaining");
  64. }
  65. @Test(groups = { "functional.encode","service.ussd"})
  66. public void testEncode() throws Exception {
  67. byte[] data = new byte[] { 0x30, 0x3e, 0x04, 0x01, 0x0f, 0x04, 0x39, (byte) 0xd5, (byte) 0xe9, (byte) 0x94, 0x08, (byte) 0x9a, (byte) 0xd2,
  68. (byte) 0xe5, 0x69, (byte) 0xf7, 0x19, (byte) 0xa4, 0x03, 0x21, (byte) 0xcb, 0x6c, (byte) 0xf6, 0x1b, 0x74, 0x7d, (byte) 0xcb, (byte) 0xd9,
  69. 0x64, 0x10, 0x6f, 0x28, (byte) 0xf5, (byte) 0x81, 0x62, 0x2e, (byte) 0x90, 0x30, (byte) 0xcc, 0x0e, (byte) 0xbb, (byte) 0xc7, 0x65, 0x10, 0x6f,
  70. 0x28, (byte) 0xf5, (byte) 0x81, 0x64, 0x2e, 0x10, (byte) 0xb5, (byte) 0x8c, (byte) 0xa7, (byte) 0xcf, 0x41, (byte) 0xd2, 0x72, 0x3b,
  71. (byte) 0x9c, 0x76, (byte) 0xa7, (byte) 0xdd, 0x67 };
  72. USSDString ussdStr = new USSDStringImpl("USSD String : Hello World <CR> 1. Balance <CR> 2. Texts Remaining", null);
  73. UnstructuredSSRequestIndicationImpl addNum = new UnstructuredSSRequestIndicationImpl((byte) 0x0f, ussdStr, null, null);
  74. AsnOutputStream asnOS = new AsnOutputStream();
  75. addNum.encodeAll(asnOS);
  76. byte[] encodedData = asnOS.toByteArray();
  77. assertTrue( Arrays.equals(data,encodedData));
  78. }
  79. }