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

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

http://mobicents.googlecode.com/
Java | 125 lines | 75 code | 22 blank | 28 comment | 0 complexity | 812702ef86006667dc620ac49e4c7160 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;
 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.asn.Tag;
 39import org.mobicents.protocols.ss7.map.MAPParameterFactoryImpl;
 40import org.mobicents.protocols.ss7.map.api.MAPParameterFactory;
 41import org.mobicents.protocols.ss7.map.api.primitives.USSDString;
 42import org.testng.annotations.AfterClass;
 43import org.testng.annotations.AfterTest;
 44import org.testng.annotations.BeforeClass;
 45import org.testng.annotations.BeforeTest;
 46import org.testng.annotations.Test;
 47
 48/**
 49 * @author amit bhayani
 50 *
 51 */
 52public class LCSCodewordTest {
 53	MAPParameterFactory MAPParameterFactory = new MAPParameterFactoryImpl();
 54
 55	@BeforeClass
 56	public static void setUpClass() throws Exception {
 57	}
 58
 59	@AfterClass
 60	public static void tearDownClass() throws Exception {
 61	}
 62
 63	@BeforeTest
 64	public void setUp() {
 65	}
 66
 67	@AfterTest
 68	public void tearDown() {
 69	}
 70
 71	@Test(groups = { "functional.decode","service.lsm"})
 72	public void testDecode() throws Exception {
 73		byte[] data = new byte[] { 0x30, 0x13, (byte) 0x80, 0x01, 0x0f, (byte) 0x81, 0x0e, 0x6e, 0x72, (byte) 0xfb, 0x1c, (byte) 0x86, (byte) 0xc3, 0x65, 0x6e, 0x72,
 74				(byte) 0xfb, 0x1c, (byte) 0x86, (byte) 0xc3, 0x65 };
 75
 76		AsnInputStream asn = new AsnInputStream(data);
 77		int tag = asn.readTag();
 78
 79		LCSCodewordImpl lcsCodeword = new LCSCodewordImpl();
 80		lcsCodeword.decodeAll(asn);
 81
 82		assertEquals( lcsCodeword.getDataCodingScheme(),(byte) 0x0f);
 83		assertNotNull(lcsCodeword.getLCSCodewordString());
 84		assertEquals( lcsCodeword.getLCSCodewordString().getString(),"ndmgapp2ndmgapp2");
 85
 86	}
 87
 88	@Test(groups = { "functional.encode","service.lsm"})
 89	public void testEncode() throws Exception {
 90		byte[] data = new byte[] { 0x30, 0x13, (byte) 0x80, 0x01, 0x0f, (byte) 0x81, 0x0e, 0x6e, 0x72, (byte) 0xfb, 0x1c, (byte) 0x86, (byte) 0xc3, 0x65, 0x6e, 0x72,
 91				(byte) 0xfb, 0x1c, (byte) 0x86, (byte) 0xc3, 0x65 };
 92
 93		USSDString nameString = MAPParameterFactory.createUSSDString("ndmgapp2ndmgapp2");
 94		LCSCodewordImpl lcsCodeword = new LCSCodewordImpl((byte) 0x0f, nameString);
 95		AsnOutputStream asnOS = new AsnOutputStream();
 96		lcsCodeword.encodeAll(asnOS, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
 97		
 98		byte[] encodedData = asnOS.toByteArray();
 99
100		assertTrue( Arrays.equals(data,encodedData));
101	}
102	
103	@Test(groups = { "functional.serialize", "service.lsm" })
104	public void testSerialization() throws Exception {
105		USSDString nameString = MAPParameterFactory.createUSSDString("ndmgapp2ndmgapp2");
106		LCSCodewordImpl original = new LCSCodewordImpl((byte) 0x0f, nameString);
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		LCSCodewordImpl copy = (LCSCodewordImpl) o;
120		
121		//test result
122		assertEquals(copy.getDataCodingScheme(), original.getDataCodingScheme());
123		assertEquals(copy.getLCSCodewordString(), original.getLCSCodewordString());
124	}
125}