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

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

http://mobicents.googlecode.com/
Java | 129 lines | 76 code | 23 blank | 30 comment | 0 complexity | a8390afc6fee6b9f34602466a4557695 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.assertNull;
 28import static org.testng.Assert.assertTrue;
 29
 30import java.io.ByteArrayInputStream;
 31import java.io.ByteArrayOutputStream;
 32import java.io.InputStream;
 33import java.io.ObjectInputStream;
 34import java.io.ObjectOutputStream;
 35import java.util.Arrays;
 36
 37import org.mobicents.protocols.asn.AsnInputStream;
 38import org.mobicents.protocols.asn.AsnOutputStream;
 39import org.mobicents.protocols.asn.Tag;
 40import org.mobicents.protocols.ss7.map.MAPParameterFactoryImpl;
 41import org.mobicents.protocols.ss7.map.api.MAPParameterFactory;
 42import org.mobicents.protocols.ss7.map.api.primitives.USSDString;
 43import org.testng.annotations.AfterClass;
 44import org.testng.annotations.AfterTest;
 45import org.testng.annotations.BeforeClass;
 46import org.testng.annotations.BeforeTest;
 47import org.testng.annotations.Test;
 48
 49/**
 50 * TODO Add test for LCS-FormatIndicator
 51 * 
 52 * @author amit bhayani
 53 * 
 54 */
 55public class LCSRequestorIDTest {
 56
 57	MAPParameterFactory MAPParameterFactory = new MAPParameterFactoryImpl();
 58
 59	@BeforeClass
 60	public static void setUpClass() throws Exception {
 61	}
 62
 63	@AfterClass
 64	public static void tearDownClass() throws Exception {
 65	}
 66
 67	@BeforeTest
 68	public void setUp() {
 69	}
 70
 71	@AfterTest
 72	public void tearDown() {
 73	}
 74
 75	@Test(groups = { "functional.decode","service.lsm"})
 76	public void testDecode() throws Exception {
 77		byte[] data = new byte[] { (byte) 0xb0, 0x13, (byte) 0x80, 0x01, 0x0f, (byte) 0x81, 0x0e, 0x6e, 0x72, (byte) 0xfb, 0x1c, (byte) 0x86, (byte) 0xc3,
 78				0x65, 0x6e, 0x72, (byte) 0xfb, 0x1c, (byte) 0x86, (byte) 0xc3, 0x65 };
 79
 80		AsnInputStream asn = new AsnInputStream(data);
 81		int tag = asn.readTag();
 82
 83		LCSRequestorIDImpl lcsRequestorID = new LCSRequestorIDImpl();
 84		lcsRequestorID.decodeAll(asn);
 85
 86		assertEquals( lcsRequestorID.getDataCodingScheme(),(byte) 0x0f);
 87		assertNotNull(lcsRequestorID.getRequestorIDString());
 88		assertEquals( lcsRequestorID.getRequestorIDString().getString(),"ndmgapp2ndmgapp2");
 89
 90		assertNull(lcsRequestorID.getLCSFormatIndicator());
 91	}
 92
 93	@Test(groups = { "functional.encode","service.lsm"})
 94	public void testEncode() throws Exception {
 95		byte[] data = new byte[] { (byte) 0xb0, 0x13, (byte) 0x80, 0x01, 0x0f, (byte) 0x81, 0x0e, 0x6e, 0x72, (byte) 0xfb, 0x1c, (byte) 0x86, (byte) 0xc3,
 96				0x65, 0x6e, 0x72, (byte) 0xfb, 0x1c, (byte) 0x86, (byte) 0xc3, 0x65 };
 97
 98		USSDString nameString = MAPParameterFactory.createUSSDString("ndmgapp2ndmgapp2");
 99		LCSRequestorIDImpl lcsRequestorID = new LCSRequestorIDImpl((byte) 0x0f, nameString, null);
100		AsnOutputStream asnOS = new AsnOutputStream();
101		lcsRequestorID.encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, Tag.SEQUENCE);
102
103		byte[] encodedData = asnOS.toByteArray();
104
105		assertTrue( Arrays.equals(data,encodedData));
106	}
107	
108	@Test(groups = { "functional.serialize", "service.lsm" })
109	public void testSerialization() throws Exception {
110		USSDString nameString = MAPParameterFactory.createUSSDString("ndmgapp2ndmgapp2");
111		LCSRequestorIDImpl original = new LCSRequestorIDImpl((byte) 0x0f, nameString, null);
112
113		// serialize
114		ByteArrayOutputStream out = new ByteArrayOutputStream();
115		ObjectOutputStream oos = new ObjectOutputStream(out);
116		oos.writeObject(original);
117		oos.close();
118
119		// deserialize
120		byte[] pickled = out.toByteArray();
121		InputStream in = new ByteArrayInputStream(pickled);
122		ObjectInputStream ois = new ObjectInputStream(in);
123		Object o = ois.readObject();
124		LCSRequestorIDImpl copy = (LCSRequestorIDImpl) o;
125		
126		//test result
127		assertEquals(copy, original);
128	}
129}