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

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

http://mobicents.googlecode.com/
Java | 104 lines | 52 code | 23 blank | 29 comment | 0 complexity | 7b0e8759b8b870aff38cc093f561bc6a 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.assertTrue;
 27
 28import java.io.ByteArrayInputStream;
 29import java.io.ByteArrayOutputStream;
 30import java.io.InputStream;
 31import java.io.ObjectInputStream;
 32import java.io.ObjectOutputStream;
 33import java.util.Arrays;
 34
 35import org.mobicents.protocols.asn.AsnInputStream;
 36import org.mobicents.protocols.asn.AsnOutputStream;
 37import org.mobicents.protocols.asn.Tag;
 38import org.testng.annotations.Test;
 39
 40/**
 41 * 
 42 * @author sergey vetyutnev
 43 *
 44 */
 45public class LMSITest  {
 46	
 47	private byte[] getEncodedData() {
 48		return new byte[] { 4, 4, 0, 3, 98, 49 };
 49	}
 50
 51	@Test(groups = { "functional.decode","primitives"})
 52	public void testDecode() throws Exception {
 53		
 54		byte[] rawData = getEncodedData();
 55		
 56		AsnInputStream asn = new AsnInputStream(rawData);
 57
 58		int tag = asn.readTag();
 59		LMSIImpl lmsi = new LMSIImpl();
 60		lmsi.decodeAll(asn);
 61
 62		assertEquals( tag,Tag.STRING_OCTET);
 63		assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
 64		
 65		assertTrue(Arrays.equals(new byte[] { 0, 3, 98, 49 }, lmsi.getData()));
 66	}
 67	
 68	@Test(groups = { "functional.encode","primitives"})
 69	public void testEncode() throws Exception {
 70		
 71		LMSIImpl lmsi = new LMSIImpl(new byte[] { 0, 3, 98, 49 });
 72		AsnOutputStream asnOS = new AsnOutputStream();
 73		
 74		lmsi.encodeAll(asnOS, Tag.CLASS_UNIVERSAL, Tag.STRING_OCTET);
 75		
 76		byte[] encodedData = asnOS.toByteArray();
 77		
 78		byte[] rawData = getEncodedData();		
 79		
 80		assertTrue( Arrays.equals(rawData,encodedData));
 81		
 82	}
 83	
 84	@Test(groups = { "functional.serialize", "primitives" })
 85	public void testSerialization() throws Exception {
 86		LMSIImpl original = new LMSIImpl(new byte[] { 0, 3, 98, 49 });
 87		// serialize
 88		ByteArrayOutputStream out = new ByteArrayOutputStream();
 89		ObjectOutputStream oos = new ObjectOutputStream(out);
 90		oos.writeObject(original);
 91		oos.close();
 92
 93		// deserialize
 94		byte[] pickled = out.toByteArray();
 95		InputStream in = new ByteArrayInputStream(pickled);
 96		ObjectInputStream ois = new ObjectInputStream(in);
 97		Object o = ois.readObject();
 98		LMSIImpl copy = (LMSIImpl) o;
 99		
100		//test result
101		assertEquals(copy.getData(), original.getData());
102		
103	}
104}