PageRenderTime 16ms CodeModel.GetById 1ms app.highlight 12ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 157 lines | 95 code | 34 blank | 28 comment | 0 complexity | 6c9bcc6d1c83bdfbee62b6298eaa7d29 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;
 24import static org.testng.Assert.assertEquals;
 25import static org.testng.Assert.assertNotNull;
 26import static org.testng.Assert.assertNull;
 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.ss7.map.api.service.lsm.DeferredLocationEventType;
 39import org.mobicents.protocols.ss7.map.api.service.lsm.LocationEstimateType;
 40import org.testng.annotations.AfterClass;
 41import org.testng.annotations.AfterTest;
 42import org.testng.annotations.BeforeClass;
 43import org.testng.annotations.BeforeTest;
 44import org.testng.annotations.Test;
 45
 46/**
 47 * @author amit bhayani
 48 * 
 49 */
 50public class LocationTypeTest {
 51
 52	@BeforeClass
 53	public static void setUpClass() throws Exception {
 54	}
 55
 56	@AfterClass
 57	public static void tearDownClass() throws Exception {
 58	}
 59
 60	@BeforeTest
 61	public void setUp() {
 62	}
 63
 64	@AfterTest
 65	public void tearDown() {
 66	}
 67
 68	@Test(groups = { "functional.decode","service.lsm"})
 69	public void testDecode() throws Exception {
 70		byte[] data = new byte[] { 0x30, 0x03, (byte) 0x80, 0x01, 0x00 };
 71		AsnInputStream asn = new AsnInputStream(data);
 72		int tag = asn.readTag();
 73
 74		LocationTypeImpl locType = new LocationTypeImpl();
 75		locType.decodeAll(asn);
 76
 77		assertNotNull(locType.getLocationEstimateType());
 78		assertEquals( locType.getLocationEstimateType(),LocationEstimateType.currentLocation);
 79		assertNull(locType.getDeferredLocationEventType());
 80
 81	}
 82
 83	@Test(groups = { "functional.encode","service.lsm"})
 84	public void testEncode() throws Exception {
 85		byte[] data = new byte[] { 0x30, 0x03, (byte) 0x80, 0x01, 0x00 };
 86
 87		LocationTypeImpl locType = new LocationTypeImpl(LocationEstimateType.currentLocation, null);
 88		AsnOutputStream asnOS = new AsnOutputStream();
 89		locType.encodeAll(asnOS);
 90
 91		byte[] encodedData = asnOS.toByteArray();
 92
 93		assertTrue( Arrays.equals(data,encodedData));
 94
 95	}
 96
 97	@Test(groups = { "functional.decode","service.lsm"})
 98	public void testDecode1() throws Exception {
 99		byte[] data = new byte[] { 0x30, 0x07, (byte) 0x80, 0x01, 0x00, (byte) 0x81, 0x02, 0x04, (byte) -16 };
100		AsnInputStream asn = new AsnInputStream(data);
101		int tag = asn.readTag();
102
103		LocationTypeImpl locType = new LocationTypeImpl();
104		locType.decodeAll(asn);
105
106		assertNotNull(locType.getLocationEstimateType());
107		assertEquals( locType.getLocationEstimateType(),LocationEstimateType.currentLocation);
108		assertNotNull(locType.getDeferredLocationEventType());
109
110		assertNotNull(locType.getDeferredLocationEventType());
111		assertTrue(locType.getDeferredLocationEventType().getEnteringIntoArea());
112		assertTrue(locType.getDeferredLocationEventType().getMsAvailable());
113		assertTrue(locType.getDeferredLocationEventType().getLeavingFromArea());
114		assertTrue(locType.getDeferredLocationEventType().getBeingInsideArea());
115
116	}
117
118	@Test(groups = { "functional.encode","service.lsm"})
119	public void testEncode1() throws Exception {
120		byte[] data = new byte[] { 0x30, 0x07, (byte) 0x80, 0x01, 0x00, (byte) 0x81, 0x02, 0x04, (byte) -16 };
121
122		DeferredLocationEventType deferredLocationEventType = new DeferredLocationEventTypeImpl(true, true, true, true);
123
124		LocationTypeImpl locType = new LocationTypeImpl(LocationEstimateType.currentLocation, deferredLocationEventType);
125
126		AsnOutputStream asnOS = new AsnOutputStream();
127		locType.encodeAll(asnOS);
128
129		byte[] encodedData = asnOS.toByteArray();
130
131		assertTrue( Arrays.equals(data,encodedData));
132	}
133	
134	@Test(groups = { "functional.serialize", "service.lsm" })
135	public void testSerialization() throws Exception {
136		DeferredLocationEventType deferredLocationEventType = new DeferredLocationEventTypeImpl(true, true, true, true);
137
138		LocationTypeImpl original = new LocationTypeImpl(LocationEstimateType.currentLocation, deferredLocationEventType);
139
140		// serialize
141		ByteArrayOutputStream out = new ByteArrayOutputStream();
142		ObjectOutputStream oos = new ObjectOutputStream(out);
143		oos.writeObject(original);
144		oos.close();
145
146		// deserialize
147		byte[] pickled = out.toByteArray();
148		InputStream in = new ByteArrayInputStream(pickled);
149		ObjectInputStream ois = new ObjectInputStream(in);
150		Object o = ois.readObject();
151		LocationTypeImpl copy = (LocationTypeImpl) o;
152		
153		//test result
154		assertEquals(copy, original);
155	}
156
157}