PageRenderTime 23ms CodeModel.GetById 1ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/ss7/map/map-impl/src/test/java/org/mobicents/protocols/ss7/map/service/sms/LocationInfoWithLMSITest.java

http://mobicents.googlecode.com/
Java | 157 lines | 99 code | 29 blank | 29 comment | 0 complexity | 3ddc05431f3a156ee538b709847ad02a 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.sms;
 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.mobicents.protocols.ss7.map.api.primitives.AdditionalNumberType;
 39import org.mobicents.protocols.ss7.map.api.primitives.AddressNature;
 40import org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString;
 41import org.mobicents.protocols.ss7.map.api.primitives.NumberingPlan;
 42import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
 43import org.mobicents.protocols.ss7.map.primitives.LMSIImpl;
 44import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerTest;
 45import org.testng.annotations.Test;
 46
 47/**
 48 * 
 49 * @author sergey vetyutnev
 50 *
 51 */
 52public class LocationInfoWithLMSITest  {
 53	
 54	private byte[] getEncodedData() {
 55		return new byte[] { -96, 15, -127, 7, -111, -105, 48, 115, 0, 34, -14, 4, 4, 0, 3, 98, 49 };
 56	}
 57
 58	private byte[] getEncodedDataFull() {
 59		return new byte[] { -96, 65, -127, 6, -88, 33, 67, 101, -121, 9, 4, 4, 4, 3, 2, 1, 48, 39, -96, 32, 48, 10, 6, 3, 42, 3, 4, 11, 12, 13, 14, 15, 48, 5,
 60				6, 3, 42, 3, 6, 48, 11, 6, 3, 42, 3, 5, 21, 22, 23, 24, 25, 26, -95, 3, 31, 32, 33, -123, 0, -122, 6, -71, -119, 103, 69, 35, -15 };
 61	}
 62
 63	@Test(groups = { "functional.decode","service.sms"})
 64	public void testDecode() throws Exception {
 65		
 66		byte[] rawData = getEncodedData();
 67		AsnInputStream asn = new AsnInputStream(rawData);
 68
 69		int tag = asn.readTag();
 70		LocationInfoWithLMSIImpl liw = new LocationInfoWithLMSIImpl();
 71		liw.decodeAll(asn);
 72
 73		assertEquals( tag,0);
 74		assertEquals( asn.getTagClass(),Tag.CLASS_CONTEXT_SPECIFIC);
 75		
 76		ISDNAddressString nnm = liw.getNetworkNodeNumber();
 77		assertEquals( nnm.getAddressNature(),AddressNature.international_number);
 78		assertEquals( nnm.getNumberingPlan(),NumberingPlan.ISDN);
 79		assertEquals( nnm.getAddress(),"79033700222");
 80		assertTrue(Arrays.equals(new byte[] { 0, 3, 98, 49 }, liw.getLMSI().getData()));
 81		
 82		
 83		rawData = getEncodedDataFull();
 84		asn = new AsnInputStream(rawData);
 85
 86		tag = asn.readTag();
 87		liw = new LocationInfoWithLMSIImpl();
 88		liw.decodeAll(asn);
 89
 90		assertEquals( tag,0);
 91		assertEquals( asn.getTagClass(),Tag.CLASS_CONTEXT_SPECIFIC);
 92		
 93		nnm = liw.getNetworkNodeNumber();
 94		assertEquals( nnm.getAddressNature(),AddressNature.national_significant_number);
 95		assertEquals( nnm.getNumberingPlan(),NumberingPlan.national);
 96		assertEquals( nnm.getAddress(),"1234567890");
 97		assertTrue(Arrays.equals(new byte[] { 4, 3, 2, 1 }, liw.getLMSI().getData()));
 98		assertTrue(MAPExtensionContainerTest.CheckTestExtensionContainer(liw.getExtensionContainer()));
 99		assertEquals( liw.getAdditionalNumberType(),AdditionalNumberType.sgsn);
100		nnm = liw.getAdditionalNumber();
101		assertEquals( nnm.getAddressNature(),AddressNature.network_specific_number);
102		assertEquals( nnm.getNumberingPlan(),NumberingPlan.private_plan);
103		assertEquals( nnm.getAddress(),"987654321");
104	}
105
106	@Test(groups = { "functional.encode","service.sms"})
107	public void testEncode() throws Exception {
108		
109		ISDNAddressString nnm = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "79033700222");
110		LMSIImpl lmsi = new LMSIImpl(new byte[] { 0, 3, 98, 49 });
111		LocationInfoWithLMSIImpl liw = new LocationInfoWithLMSIImpl(nnm, lmsi, null, null, null);
112		
113		AsnOutputStream asnOS = new AsnOutputStream();
114		liw.encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, 0);
115		
116		byte[] encodedData = asnOS.toByteArray();
117		byte[] rawData = getEncodedData();		
118		assertTrue( Arrays.equals(rawData,encodedData));
119		
120		nnm = new ISDNAddressStringImpl(AddressNature.national_significant_number, NumberingPlan.national, "1234567890");
121		ISDNAddressStringImpl an = new ISDNAddressStringImpl(AddressNature.network_specific_number, NumberingPlan.private_plan, "987654321");
122		lmsi = new LMSIImpl(new byte[] { 4, 3, 2, 1 });
123		liw = new LocationInfoWithLMSIImpl(nnm, lmsi, MAPExtensionContainerTest.GetTestExtensionContainer(), AdditionalNumberType.sgsn, an);
124		
125		asnOS.reset();
126		liw.encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, 0);
127		
128		encodedData = asnOS.toByteArray();
129		rawData = getEncodedDataFull();		
130		assertTrue( Arrays.equals(rawData,encodedData));
131		
132	}
133	
134	@Test(groups = { "functional.serialize", "service.sms" })
135	public void testSerialization() throws Exception {
136		ISDNAddressString nnm = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "79033700222");
137		LMSIImpl lmsi = new LMSIImpl(new byte[] { 0, 3, 98, 49 });
138		LocationInfoWithLMSIImpl original = new LocationInfoWithLMSIImpl(nnm, lmsi, null, null, null);
139		
140		// serialize
141		ByteArrayOutputStream out = new ByteArrayOutputStream();
142		ObjectOutputStream oos = new ObjectOutputStream(out);
143		oos.writeObject(original);
144		oos.close();
145
146		// deserialize
147		byte[] pickled = out.toByteArray();
148		InputStream in = new ByteArrayInputStream(pickled);
149		ObjectInputStream ois = new ObjectInputStream(in);
150		Object o = ois.readObject();
151		LocationInfoWithLMSIImpl copy = (LocationInfoWithLMSIImpl) o;
152		
153		//test result
154		assertEquals(copy.getNetworkNodeNumber(), original.getNetworkNodeNumber());
155		assertEquals(copy.getLMSI(), original.getLMSI());
156	}
157}