PageRenderTime 23ms CodeModel.GetById 9ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 124 lines | 74 code | 22 blank | 28 comment | 0 complexity | 7bf35d7ad1e3da2927b5cfcc2e822278 MD5 | raw file
  1/*
  2 * JBoss, Home of Professional Open Source
  3 * Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual
  4 * contributors as indicated by the @authors tag. All rights reserved.
  5 * See the copyright.txt in the distribution for a full listing
  6 * of individual contributors.
  7 * 
  8 * This copyrighted material is made available to anyone wishing to use,
  9 * modify, copy, or redistribute it subject to the terms and conditions
 10 * of the GNU General Public License, v. 2.0.
 11 * 
 12 * This program 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 * General Public License for more details.
 16 * 
 17 * You should have received a copy of the GNU General Public License,
 18 * v. 2.0 along with this distribution; if not, write to the Free 
 19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 20 * MA 02110-1301, USA.
 21 */
 22package org.mobicents.protocols.ss7.map.service.lsm;
 23
 24import static org.testng.Assert.assertEquals;
 25import static org.testng.Assert.assertTrue;
 26
 27import java.io.ByteArrayInputStream;
 28import java.io.ByteArrayOutputStream;
 29import java.io.InputStream;
 30import java.io.ObjectInputStream;
 31import java.io.ObjectOutputStream;
 32import java.util.Arrays;
 33
 34import org.mobicents.protocols.asn.AsnInputStream;
 35import org.mobicents.protocols.asn.AsnOutputStream;
 36import org.mobicents.protocols.asn.Tag;
 37import org.testng.annotations.AfterClass;
 38import org.testng.annotations.AfterTest;
 39import org.testng.annotations.BeforeClass;
 40import org.testng.annotations.BeforeTest;
 41import org.testng.annotations.Test;
 42
 43/**
 44 * @author amit bhayani
 45 * 
 46 */
 47public class SupportedGADShapesTest {
 48
 49	private byte[] getEncodedData() {
 50		return new byte[] { (byte)0x03, 0x02, 0x01, (byte) 0xfe };
 51	}
 52
 53	@BeforeClass
 54	public static void setUpClass() throws Exception {
 55	}
 56
 57	@AfterClass
 58	public static void tearDownClass() throws Exception {
 59	}
 60
 61	@BeforeTest
 62	public void setUp() {
 63	}
 64
 65	@AfterTest
 66	public void tearDown() {
 67	}
 68
 69	@Test(groups = { "functional.decode","service.lsm"})
 70	public void testDecode() throws Exception {
 71		byte[] rawData = getEncodedData();
 72		AsnInputStream asn = new AsnInputStream(rawData);
 73
 74		int tag = asn.readTag();
 75		SupportedGADShapesImpl supportedLCSCapabilityTest = new SupportedGADShapesImpl();
 76		supportedLCSCapabilityTest.decodeAll(asn);
 77
 78		assertEquals( tag,Tag.STRING_BIT);
 79		assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
 80
 81		assertEquals( (boolean) supportedLCSCapabilityTest.getEllipsoidArc(),true);
 82		assertEquals( (boolean) supportedLCSCapabilityTest.getEllipsoidPoint(),true);
 83		assertEquals( (boolean) supportedLCSCapabilityTest.getEllipsoidPointWithAltitude(),true);
 84		assertEquals( (boolean) supportedLCSCapabilityTest.getEllipsoidPointWithAltitudeAndUncertaintyElipsoid(),true);
 85		assertEquals( (boolean) supportedLCSCapabilityTest.getEllipsoidPointWithUncertaintyCircle(),true);
 86		assertEquals( (boolean) supportedLCSCapabilityTest.getEllipsoidPointWithUncertaintyEllipse(),true);
 87		assertEquals( (boolean) supportedLCSCapabilityTest.getPolygon(),true);
 88	}
 89
 90	@Test(groups = { "functional.encode","service.lsm"})
 91	public void testEncode() throws Exception {
 92
 93		SupportedGADShapesImpl supportedLCSCapabilityTest = new SupportedGADShapesImpl(true, true, true, true, true, true, true);
 94
 95		AsnOutputStream asnOS = new AsnOutputStream();
 96		supportedLCSCapabilityTest.encodeAll(asnOS);
 97
 98		byte[] encodedData = asnOS.toByteArray();
 99		byte[] rawData = getEncodedData();
100		assertTrue( Arrays.equals(rawData,encodedData));
101
102	}
103	
104	@Test(groups = { "functional.serialize", "service.lsm" })
105	public void testSerialization() throws Exception {
106		SupportedGADShapesImpl original = new SupportedGADShapesImpl(true, true, true, true, true, true, true);
107
108		// serialize
109		ByteArrayOutputStream out = new ByteArrayOutputStream();
110		ObjectOutputStream oos = new ObjectOutputStream(out);
111		oos.writeObject(original);
112		oos.close();
113
114		// deserialize
115		byte[] pickled = out.toByteArray();
116		InputStream in = new ByteArrayInputStream(pickled);
117		ObjectInputStream ois = new ObjectInputStream(in);
118		Object o = ois.readObject();
119		SupportedGADShapesImpl copy = (SupportedGADShapesImpl) o;
120		
121		//test result
122		assertEquals(copy, original);
123	}
124}