/protocols/ss7/map/map-impl/src/test/java/org/mobicents/protocols/ss7/map/primitives/USSDStringTest.java
Java | 114 lines | 62 code | 21 blank | 31 comment | 0 complexity | 031ba0b9164fe92bcda576f377a70563 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 */ 22package org.mobicents.protocols.ss7.map.primitives; 23 24import static org.testng.Assert.assertEquals; 25import static org.testng.Assert.assertTrue; 26 27import java.io.ByteArrayInputStream; 28import java.io.ByteArrayOutputStream; 29import java.io.InputStream; 30import java.io.ObjectInputStream; 31import java.io.ObjectOutputStream; 32import java.util.Arrays; 33 34import org.mobicents.protocols.asn.AsnInputStream; 35import org.mobicents.protocols.asn.AsnOutputStream; 36import org.testng.annotations.AfterClass; 37import org.testng.annotations.AfterTest; 38import org.testng.annotations.BeforeClass; 39import org.testng.annotations.BeforeTest; 40import org.testng.annotations.Test; 41 42/** 43 * @author amit bhayani 44 * 45 */ 46public class USSDStringTest { 47 @BeforeClass 48 public static void setUpClass() throws Exception { 49 } 50 51 @AfterClass 52 public static void tearDownClass() throws Exception { 53 } 54 55 @BeforeTest 56 public void setUp() { 57 } 58 59 @AfterTest 60 public void tearDown() { 61 } 62 63 @Test(groups = { "functional.decode","primitives"}) 64 public void testDecode() throws Exception { 65 byte[] data = new byte[] { 0x04, 0x04, 0x2a, 0x1c, 0x6e, (byte)0x04 }; 66 67 AsnInputStream asn = new AsnInputStream(data); 68 int tag = asn.readTag(); 69 70 USSDStringImpl ussdStr = new USSDStringImpl(); 71 ussdStr.decodeAll(asn); 72 73 assertEquals( ussdStr.getString(),"*88#"); 74 75 } 76 77 //TODO Fix the GSMEncoder. This is failing 78 @Test(groups = { "functional.encode","primitives"}) 79 public void testEncode() throws Exception { 80 byte[] data = new byte[] { 0x04, 0x04, 0x2a, 0x1c, 0x6e, (byte)0x04 }; 81 82 USSDStringImpl ussdStr = new USSDStringImpl("*88#", null); 83 84 AsnOutputStream asnOS = new AsnOutputStream(); 85 ussdStr.encodeAll(asnOS); 86 87 byte[] encodedData = asnOS.toByteArray(); 88 89 assertTrue( Arrays.equals(data,encodedData)); 90 } 91 92 @Test(groups = { "functional.serialize", "primitives" }) 93 public void testSerialization() throws Exception { 94 USSDStringImpl original = new USSDStringImpl("*88#", null); 95 // serialize 96 ByteArrayOutputStream out = new ByteArrayOutputStream(); 97 ObjectOutputStream oos = new ObjectOutputStream(out); 98 oos.writeObject(original); 99 oos.close(); 100 101 // deserialize 102 byte[] pickled = out.toByteArray(); 103 InputStream in = new ByteArrayInputStream(pickled); 104 ObjectInputStream ois = new ObjectInputStream(in); 105 Object o = ois.readObject(); 106 USSDStringImpl copy = (USSDStringImpl) o; 107 108 //test result 109 assertEquals(copy.getString(), original.getString()); 110 111 //TODO Charset is not Serializable now 112 //assertEquals(copy.getCharset(), original.getCharset()); 113 } 114}