PageRenderTime 63ms CodeModel.GetById 47ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 128 lines | 74 code | 24 blank | 30 comment | 0 complexity | 55b6b5534975074d1d08b41d0ce9eebd 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 * TODO : Self generated trace. Get real ones
 45 * 
 46 * @author amit bhayani
 47 *
 48 */
 49public class SupportedLCSCapabilitySetsTest {
 50	
 51	private byte[] getEncodedData() {
 52		return new byte[] { 3, 2, 4, 64 };
 53	}
 54	
 55	
 56	@BeforeClass
 57	public static void setUpClass() throws Exception {
 58	}
 59
 60	@AfterClass
 61	public static void tearDownClass() throws Exception {
 62	}
 63
 64	@BeforeTest
 65	public void setUp() {
 66	}
 67
 68	@AfterTest
 69	public void tearDown() {
 70	}
 71
 72	@Test(groups = { "functional.decode","service.lsm"})
 73	public void testDecode() throws Exception {
 74		byte[] rawData = getEncodedData();
 75		AsnInputStream asn = new AsnInputStream(rawData);
 76
 77		int tag = asn.readTag();
 78		SupportedLCSCapabilitySetsImpl supportedLCSCapabilityTest = new SupportedLCSCapabilitySetsImpl();
 79		supportedLCSCapabilityTest.decodeAll(asn);
 80
 81		assertEquals( tag,Tag.STRING_BIT);
 82		assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
 83
 84		assertEquals( (boolean)supportedLCSCapabilityTest.getLcsCapabilitySet1(),false);
 85		assertEquals( (boolean)supportedLCSCapabilityTest.getLcsCapabilitySet2(),true);
 86		assertEquals( (boolean)supportedLCSCapabilityTest.getLcsCapabilitySet3(),false);
 87		assertEquals( (boolean)supportedLCSCapabilityTest.getLcsCapabilitySet4(),false);
 88	}
 89	
 90	@Test(groups = { "functional.encode","service.lsm"})
 91	public void testEncode() throws Exception {
 92		
 93		SupportedLCSCapabilitySetsImpl supportedLCSCapabilityTest = new SupportedLCSCapabilitySetsImpl(false, true, false, false);
 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		SupportedLCSCapabilitySetsImpl original = new SupportedLCSCapabilitySetsImpl(false, true, false, false);
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		SupportedLCSCapabilitySetsImpl copy = (SupportedLCSCapabilitySetsImpl) o;
120		
121		//test result
122		assertEquals(copy.getLcsCapabilitySet1(), original.getLcsCapabilitySet1());
123		assertEquals(copy.getLcsCapabilitySet2(), original.getLcsCapabilitySet2());
124		assertEquals(copy.getLcsCapabilitySet3(), original.getLcsCapabilitySet3());
125		assertEquals(copy.getLcsCapabilitySet4(), original.getLcsCapabilitySet4());
126		
127	}
128}