PageRenderTime 37ms CodeModel.GetById 25ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/ss7/map/map-impl/src/test/java/org/mobicents/protocols/ss7/map/primitives/FTNAddressStringTest.java

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