/protocols/ss7/map/map-impl/src/test/java/org/mobicents/protocols/ss7/map/primitives/IMSITest.java
Java | 107 lines | 52 code | 24 blank | 31 comment | 0 complexity | d3789538b65794f36af8ecf1199538b2 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 23package org.mobicents.protocols.ss7.map.primitives; 24 25import static org.testng.Assert.assertEquals; 26import static org.testng.Assert.assertTrue; 27 28import java.io.ByteArrayInputStream; 29import java.io.ByteArrayOutputStream; 30import java.io.InputStream; 31import java.io.ObjectInputStream; 32import java.io.ObjectOutputStream; 33import java.util.Arrays; 34 35import org.mobicents.protocols.asn.AsnInputStream; 36import org.mobicents.protocols.asn.AsnOutputStream; 37import org.mobicents.protocols.asn.Tag; 38import org.testng.annotations.Test; 39 40/** 41 * 42 * @author sergey vetyutnev 43 * 44 */ 45public class IMSITest { 46 47 private byte[] getEncodedData() { 48 return new byte[] { 4, 8, 16, 33, 2, 2, 16, -119, 34, -9 }; 49 } 50 51 @Test(groups = { "functional.decode","primitives"}) 52 public void testDecode() throws Exception { 53 54 byte[] rawData = getEncodedData(); 55 56 AsnInputStream asn = new AsnInputStream(rawData); 57 58 int tag = asn.readTag(); 59 IMSIImpl imsi = new IMSIImpl(); 60 imsi.decodeAll(asn); 61 62 assertEquals( tag,Tag.STRING_OCTET); 63 assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL); 64 65// assertEquals( (long)imsi.getMCC(),11); 66// assertEquals( (long)imsi.getMNC(),22); 67 assertEquals( imsi.getData(),"011220200198227"); 68 } 69 70 @Test(groups = { "functional.encode","primitives"}) 71 public void testEncode() throws Exception { 72 73 IMSIImpl imsi = new IMSIImpl("011220200198227"); 74 AsnOutputStream asnOS = new AsnOutputStream(); 75 76 imsi.encodeAll(asnOS, Tag.CLASS_UNIVERSAL, Tag.STRING_OCTET); 77 78 byte[] encodedData = asnOS.toByteArray(); 79 80 byte[] rawData = getEncodedData(); 81 82 assertTrue( Arrays.equals(rawData,encodedData)); 83 84 } 85 86 @Test(groups = { "functional.serialize", "primitives" }) 87 public void testSerialization() throws Exception { 88 IMSIImpl original = new IMSIImpl("011220200198227"); 89 // serialize 90 ByteArrayOutputStream out = new ByteArrayOutputStream(); 91 ObjectOutputStream oos = new ObjectOutputStream(out); 92 oos.writeObject(original); 93 oos.close(); 94 95 // deserialize 96 byte[] pickled = out.toByteArray(); 97 InputStream in = new ByteArrayInputStream(pickled); 98 ObjectInputStream ois = new ObjectInputStream(in); 99 Object o = ois.readObject(); 100 IMSIImpl copy = (IMSIImpl) o; 101 102 //test result 103 assertEquals(copy.getData(), original.getData()); 104 105 } 106 107}