PageRenderTime 99ms CodeModel.GetById 74ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 1ms

/protocols/ss7/map/map-impl/src/test/java/org/mobicents/protocols/ss7/map/service/lsm/LCSClientExternalIDTest.java

http://mobicents.googlecode.com/
Java | 130 lines | 74 code | 26 blank | 30 comment | 0 complexity | 6b8f1eaeeb34b0b2715f3a85b23f9816 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.service.lsm;
 24
 25import static org.testng.Assert.assertEquals;
 26import static org.testng.Assert.assertNotNull;
 27import static org.testng.Assert.assertTrue;
 28
 29import java.io.ByteArrayInputStream;
 30import java.io.ByteArrayOutputStream;
 31import java.io.InputStream;
 32import java.io.ObjectInputStream;
 33import java.io.ObjectOutputStream;
 34import java.util.Arrays;
 35
 36import org.mobicents.protocols.asn.AsnInputStream;
 37import org.mobicents.protocols.asn.AsnOutputStream;
 38import org.mobicents.protocols.asn.Tag;
 39import org.mobicents.protocols.ss7.map.MAPParameterFactoryImpl;
 40import org.mobicents.protocols.ss7.map.api.MAPParameterFactory;
 41import org.mobicents.protocols.ss7.map.api.primitives.AddressNature;
 42import org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString;
 43import org.mobicents.protocols.ss7.map.api.primitives.NumberingPlan;
 44import org.testng.annotations.AfterClass;
 45import org.testng.annotations.AfterTest;
 46import org.testng.annotations.BeforeClass;
 47import org.testng.annotations.BeforeTest;
 48import org.testng.annotations.Test;
 49
 50/**
 51 * //TODO add ExtensionContainer and test
 52 * 
 53 * @author amit bhayani
 54 * 
 55 */
 56public class LCSClientExternalIDTest {
 57
 58	MAPParameterFactory MAPParameterFactory = new MAPParameterFactoryImpl();
 59
 60	@BeforeClass
 61	public static void setUpClass() throws Exception {
 62	}
 63
 64	@AfterClass
 65	public static void tearDownClass() throws Exception {
 66	}
 67
 68	@BeforeTest
 69	public void setUp() {
 70	}
 71
 72	@AfterTest
 73	public void tearDown() {
 74	}
 75
 76	@Test(groups = { "functional.decode","service.lsm"})
 77	public void testDecode() throws Exception {
 78		byte[] data = new byte[] { (byte)0xb0, 0x07, (byte) 0x80, 0x05, (byte) 0x91, 0x55, 0x16, 0x09, 0x70 };
 79		
 80		AsnInputStream asn = new AsnInputStream(data);
 81		int tag = asn.readTag();
 82		
 83		LCSClientExternalIDImpl lcsClientExterId = new LCSClientExternalIDImpl();
 84		lcsClientExterId.decodeAll(asn);
 85		
 86		assertNotNull(lcsClientExterId.getExternalAddress());
 87		assertEquals( lcsClientExterId.getExternalAddress().getAddress(),"55619007");
 88		
 89	}
 90
 91	@Test(groups = { "functional.encode","service.lsm"})
 92	public void testEncode() throws Exception {
 93		
 94		byte[] data = new byte[] { (byte)0xb0, 0x07, (byte) 0x80, 0x05, (byte) 0x91, 0x55, 0x16, 0x09, 0x70 };
 95
 96		ISDNAddressString externalAddress = MAPParameterFactory.createISDNAddressString(AddressNature.international_number, NumberingPlan.ISDN, "55619007");
 97		LCSClientExternalIDImpl lcsClientExterId = new LCSClientExternalIDImpl(externalAddress, null);
 98		AsnOutputStream asnOS = new AsnOutputStream();
 99		lcsClientExterId.encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, Tag.SEQUENCE);
100		
101		byte[] encodedData = asnOS.toByteArray();
102
103		assertTrue( Arrays.equals(data,encodedData));
104
105	}
106	
107	@Test(groups = { "functional.serialize", "service.lsm" })
108	public void testSerialization() throws Exception {
109		ISDNAddressString externalAddress = MAPParameterFactory.createISDNAddressString(AddressNature.international_number, NumberingPlan.ISDN, "55619007");
110		LCSClientExternalIDImpl original = new LCSClientExternalIDImpl(externalAddress, null);
111
112		// serialize
113		ByteArrayOutputStream out = new ByteArrayOutputStream();
114		ObjectOutputStream oos = new ObjectOutputStream(out);
115		oos.writeObject(original);
116		oos.close();
117
118		// deserialize
119		byte[] pickled = out.toByteArray();
120		InputStream in = new ByteArrayInputStream(pickled);
121		ObjectInputStream ois = new ObjectInputStream(in);
122		Object o = ois.readObject();
123		LCSClientExternalIDImpl copy = (LCSClientExternalIDImpl) o;
124		
125		//test result
126		assertEquals(copy.getExternalAddress(), original.getExternalAddress());
127		assertEquals(copy.getExtensionContainer(), original.getExtensionContainer());
128		
129	}
130}