PageRenderTime 26ms CodeModel.GetById 12ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

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

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