PageRenderTime 25ms CodeModel.GetById 8ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 145 lines | 84 code | 31 blank | 30 comment | 0 complexity | 3b5cbac811b3d3c40ff90340035b78eb 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.service.lsm.Area;
 42import org.mobicents.protocols.ss7.map.api.service.lsm.AreaDefinition;
 43import org.mobicents.protocols.ss7.map.api.service.lsm.AreaList;
 44import org.mobicents.protocols.ss7.map.api.service.lsm.AreaType;
 45import org.testng.annotations.AfterClass;
 46import org.testng.annotations.AfterTest;
 47import org.testng.annotations.BeforeClass;
 48import org.testng.annotations.BeforeTest;
 49import org.testng.annotations.Test;
 50
 51/**
 52 * @author amit bhayani
 53 * 
 54 */
 55public class AreaDefinitionTest {
 56	MAPParameterFactory MAPParameterFactory = new MAPParameterFactoryImpl();
 57
 58	@BeforeClass
 59	public static void setUpClass() throws Exception {
 60	}
 61
 62	@AfterClass
 63	public static void tearDownClass() throws Exception {
 64	}
 65
 66	@BeforeTest
 67	public void setUp() {
 68	}
 69
 70	@AfterTest
 71	public void tearDown() {
 72	}
 73
 74	@Test(groups = { "functional.decode","service.lsm"})
 75	public void testDecode() throws Exception {
 76		// TODO this is self generated trace. We need trace from operator
 77		byte[] data = new byte[] { 0x30, 0x16, (byte) 0xa0, 0x14, 0x30, 0x08, (byte) 0x80, 0x01, 0x05, (byte) 0x81, 0x03, 0x09, 0x70, 0x71, 0x30, 0x08, (byte) 0x80, 0x01,
 78				0x03, (byte) 0x81, 0x03, 0x04, 0x30, 0x31 };
 79		
 80		AsnInputStream asn = new AsnInputStream(data);
 81		int tag = asn.readTag();
 82
 83		AreaDefinition areaDef = new AreaDefinitionImpl();
 84		((AreaDefinitionImpl)areaDef).decodeAll(asn);
 85
 86		AreaList areaList = areaDef.getAreaList();
 87
 88		assertNotNull(areaList);
 89		assertEquals( areaList.getAreas().length,2);
 90		Area[] areas = areaList.getAreas();
 91		assertNotNull(areas[0].getAreaIdentification());
 92		assertTrue(Arrays.equals(new byte[] { 0x09, 0x70, 0x71 }, areas[0].getAreaIdentification()));
 93
 94	}
 95
 96	@Test(groups = { "functional.encode","service.lsm"})
 97	public void testEncode() throws Exception {
 98		// TODO this is self generated trace. We need trace from operator
 99		byte[] data = new byte[] { 0x30, 0x16, (byte) 0xa0, 0x14, 0x30, 0x08, (byte) 0x80, 0x01, 0x05, (byte) 0x81, 0x03, 0x09, 0x70, 0x71, 0x30, 0x08, (byte) 0x80, 0x01,
100				0x03, (byte) 0x81, 0x03, 0x04, 0x30, 0x31 };
101
102		Area area1 = new AreaImpl(AreaType.utranCellId, new byte[] { 0x09, 0x70, 0x71 });
103		Area area2 = new AreaImpl(AreaType.routingAreaId, new byte[] { 0x04, 0x30, 0x31 });
104
105		AreaList areaList = new AreaListImpl(new Area[] { area1, area2 });
106
107		AreaDefinition areaDef = new AreaDefinitionImpl(areaList);
108
109		
110		AsnOutputStream asnOS = new AsnOutputStream();
111		((AreaDefinitionImpl)areaDef).encodeAll(asnOS, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
112		
113		byte[] encodedData = asnOS.toByteArray();
114
115
116		assertTrue( Arrays.equals(data,encodedData));
117
118	}
119	
120	@Test(groups = { "functional.serialize", "service.lsm" })
121	public void testSerialization() throws Exception {
122		Area area1 = new AreaImpl(AreaType.utranCellId, new byte[] { 0x09, 0x70, 0x71 });
123		Area area2 = new AreaImpl(AreaType.routingAreaId, new byte[] { 0x04, 0x30, 0x31 });
124
125		AreaList areaList = new AreaListImpl(new Area[] { area1, area2 });
126
127		AreaDefinition original = new AreaDefinitionImpl(areaList);
128		// serialize
129		ByteArrayOutputStream out = new ByteArrayOutputStream();
130		ObjectOutputStream oos = new ObjectOutputStream(out);
131		oos.writeObject(original);
132		oos.close();
133
134		// deserialize
135		byte[] pickled = out.toByteArray();
136		InputStream in = new ByteArrayInputStream(pickled);
137		ObjectInputStream ois = new ObjectInputStream(in);
138		Object o = ois.readObject();
139		AreaDefinitionImpl copy = (AreaDefinitionImpl) o;
140		
141		//test result
142		assertEquals(copy.getAreaList(), original.getAreaList());
143		
144	}
145}