PageRenderTime 35ms CodeModel.GetById 17ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 1ms

/protocols/ss7/map/map-impl/src/test/java/org/mobicents/protocols/ss7/map/primitives/CellGlobalIdOrServiceAreaIdOrLAITest.java

http://mobicents.googlecode.com/
Java | 125 lines | 71 code | 26 blank | 28 comment | 0 complexity | 9cdb141c33d1ae92ad4a76453ba286f7 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.primitives;
 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.ss7.map.MAPParameterFactoryImpl;
 39import org.mobicents.protocols.ss7.map.api.MAPParameterFactory;
 40import org.mobicents.protocols.ss7.map.api.primitives.CellGlobalIdOrServiceAreaIdFixedLength;
 41import org.testng.annotations.AfterClass;
 42import org.testng.annotations.AfterTest;
 43import org.testng.annotations.BeforeClass;
 44import org.testng.annotations.BeforeTest;
 45import org.testng.annotations.Test;
 46
 47/**
 48 * @author amit bhayani
 49 * 
 50 */
 51public class CellGlobalIdOrServiceAreaIdOrLAITest {
 52	MAPParameterFactory MAPParameterFactory = new MAPParameterFactoryImpl();
 53
 54	@BeforeClass
 55	public static void setUpClass() throws Exception {
 56	}
 57
 58	@AfterClass
 59	public static void tearDownClass() throws Exception {
 60	}
 61
 62	@BeforeTest
 63	public void setUp() {
 64	}
 65
 66	@AfterTest
 67	public void tearDown() {
 68	}
 69
 70	@Test(groups = { "functional.decode","service.lsm"})
 71	public void testDecode() throws Exception {
 72		byte[] data = new byte[] { (byte) 0x80, 0x07, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b };
 73
 74		AsnInputStream asn = new AsnInputStream(data);
 75		int tag = asn.readTag();
 76
 77
 78		CellGlobalIdOrServiceAreaIdOrLAIImpl cellGlobalIdOrServiceAreaIdOrLAI = new CellGlobalIdOrServiceAreaIdOrLAIImpl();
 79		cellGlobalIdOrServiceAreaIdOrLAI.decodeAll(asn);
 80
 81		assertNotNull(cellGlobalIdOrServiceAreaIdOrLAI.getCellGlobalIdOrServiceAreaIdFixedLength());
 82		assertTrue(Arrays.equals(new byte[] { 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b }, cellGlobalIdOrServiceAreaIdOrLAI
 83				.getCellGlobalIdOrServiceAreaIdFixedLength().getData()));
 84
 85	}
 86
 87	@Test(groups = { "functional.encode","service.lsm"})
 88	public void testEncode() throws Exception {
 89
 90		byte[] data = new byte[] { (byte) 0x80, 0x07, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b };
 91
 92		CellGlobalIdOrServiceAreaIdFixedLength par = new CellGlobalIdOrServiceAreaIdFixedLengthImpl(new byte[] { 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b });
 93		CellGlobalIdOrServiceAreaIdOrLAIImpl cellGlobalIdOrServiceAreaIdOrLAI = new CellGlobalIdOrServiceAreaIdOrLAIImpl(par);
 94		AsnOutputStream asnOS = new AsnOutputStream();
 95		cellGlobalIdOrServiceAreaIdOrLAI.encodeAll(asnOS);
 96		
 97		byte[] encodedData = asnOS.toByteArray();
 98
 99		assertTrue( Arrays.equals(data,encodedData));
100
101	}
102	
103	@Test(groups = { "functional.serialize", "service.lsm" })
104	public void testSerialization() throws Exception {
105		CellGlobalIdOrServiceAreaIdFixedLength par = new CellGlobalIdOrServiceAreaIdFixedLengthImpl(new byte[] { 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b });
106		CellGlobalIdOrServiceAreaIdOrLAIImpl original = new CellGlobalIdOrServiceAreaIdOrLAIImpl(par);
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		CellGlobalIdOrServiceAreaIdOrLAIImpl copy = (CellGlobalIdOrServiceAreaIdOrLAIImpl) o;
120		
121		//test result
122		assertEquals(copy, original);
123		
124	}
125}