PageRenderTime 45ms CodeModel.GetById 1ms app.highlight 39ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 151 lines | 94 code | 27 blank | 30 comment | 0 complexity | 7fdb9af1b5ede4f342ad6ce74cc6ca9a 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 java.util.Arrays;
 26
 27import static org.testng.Assert.*;
 28import org.testng.*;import org.testng.annotations.*;
 29
 30import org.mobicents.protocols.asn.AsnInputStream;
 31import org.mobicents.protocols.asn.AsnOutputStream;
 32import org.mobicents.protocols.asn.Tag;
 33import org.mobicents.protocols.ss7.map.api.primitives.AdditionalNumberType;
 34import org.mobicents.protocols.ss7.map.api.primitives.AddressNature;
 35import org.mobicents.protocols.ss7.map.api.primitives.IMSI;
 36import org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString;
 37import org.mobicents.protocols.ss7.map.api.primitives.LMSI;
 38import org.mobicents.protocols.ss7.map.api.primitives.NumberingPlan;
 39import org.mobicents.protocols.ss7.map.api.service.sms.LocationInfoWithLMSI;
 40import org.mobicents.protocols.ss7.map.primitives.IMSIImpl;
 41import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
 42import org.mobicents.protocols.ss7.map.primitives.LMSIImpl;
 43import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerTest;
 44
 45/**
 46 * 
 47 * @author sergey vetyutnev
 48 *
 49 */
 50public class SendRoutingInfoForSMResponseIndicationTest  {
 51	
 52	private byte[] getEncodedData() {
 53		return new byte[] { 48, 27, 4, 8, 2, -112, 9, 2, 16, 17, 34, -9, -96, 15, -127, 7, -111, 33, 48, 18, 0, -110, -11, 4, 4, 0, 3, 98, 49 };
 54	}
 55	
 56	private byte[] getEncodedDataFull() {
 57		return new byte[] { 48, 115, 4, 7, 17, 1, 35, 34, 51, 19, 17, -96, 63, -127, 5, -58, 0, 0, 17, 17, 4, 4, 0, 2, 1, 0, 48, 39, -96, 32, 48, 10, 6, 3, 42,
 58				3, 4, 11, 12, 13, 14, 15, 48, 5, 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, 5, -90,
 59				-103, -103, -103, -103, -92, 39, -96, 32, 48, 10, 6, 3, 42, 3, 4, 11, 12, 13, 14, 15, 48, 5, 6, 3, 42, 3, 6, 48, 11, 6, 3, 42, 3, 5, 21, 22,
 60				23, 24, 25, 26, -95, 3, 31, 32, 33 };
 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		SendRoutingInfoForSMResponseIndicationImpl ind = new SendRoutingInfoForSMResponseIndicationImpl();
 71		ind.decodeAll(asn);
 72
 73		assertEquals( tag,Tag.SEQUENCE);
 74		assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
 75
 76		IMSI imsi = ind.getIMSI();
 77//		assertEquals( (long)imsi.getMCC(),200L);
 78//		assertEquals( (long)imsi.getMNC(),99L);
 79		assertEquals( imsi.getData(),"200990200111227");
 80		LocationInfoWithLMSI li = ind.getLocationInfoWithLMSI();
 81		ISDNAddressString nnn = li.getNetworkNodeNumber();
 82		assertEquals( nnn.getAddressNature(),AddressNature.international_number);
 83		assertEquals( nnn.getNumberingPlan(),NumberingPlan.ISDN);
 84		assertEquals( nnn.getAddress(),"12032100295");
 85		LMSI lmsi = li.getLMSI();
 86		assertTrue(Arrays.equals(new byte[] { 0, 3, 98, 49 }, lmsi.getData()));
 87
 88		
 89		rawData = getEncodedDataFull();
 90		asn = new AsnInputStream(rawData);
 91
 92		tag = asn.readTag();
 93		ind = new SendRoutingInfoForSMResponseIndicationImpl();
 94		ind.decodeAll(asn);
 95
 96		assertEquals( tag,Tag.SEQUENCE);
 97		assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
 98
 99		imsi = ind.getIMSI();
100//		assertEquals( (long)imsi.getMCC(),111L);
101//		assertEquals( (long)imsi.getMNC(),3L);
102		assertEquals( imsi.getData(),"11103222333111");
103		li = ind.getLocationInfoWithLMSI();
104		nnn = li.getNetworkNodeNumber();
105		assertEquals( nnn.getAddressNature(),AddressNature.subscriber_number);
106		assertEquals( nnn.getNumberingPlan(),NumberingPlan.land_mobile);
107		assertEquals( nnn.getAddress(),"00001111");
108		lmsi = li.getLMSI();
109		assertTrue(MAPExtensionContainerTest.CheckTestExtensionContainer(li.getExtensionContainer()));
110		assertEquals( li.getAdditionalNumberType(),AdditionalNumberType.sgsn);
111		ISDNAddressString an = li.getAdditionalNumber();
112		assertEquals( an.getAddressNature(),AddressNature.national_significant_number);
113		assertEquals( an.getNumberingPlan(),NumberingPlan.land_mobile);
114		assertEquals( an.getAddress(),"99999999");
115		assertTrue(MAPExtensionContainerTest.CheckTestExtensionContainer(ind.getExtensionContainer()));
116	}
117
118	@Test(groups = { "functional.encode","service.sms"})
119	public void testEncode() throws Exception {
120		
121		IMSI imsi = new IMSIImpl("200990200111227");
122		ISDNAddressString nnn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "12032100295");
123		LMSI lmsi = new LMSIImpl(new byte[] { 0, 3, 98, 49 });
124
125		LocationInfoWithLMSI li = new LocationInfoWithLMSIImpl(nnn, lmsi, null, null, null);
126		SendRoutingInfoForSMResponseIndicationImpl ind = new SendRoutingInfoForSMResponseIndicationImpl(imsi, li, null);
127		
128		AsnOutputStream asnOS = new AsnOutputStream();
129		ind.encodeAll(asnOS);
130		
131		byte[] encodedData = asnOS.toByteArray();
132		byte[] rawData = getEncodedData();		
133		assertTrue( Arrays.equals(rawData,encodedData));
134
135		
136		imsi = new IMSIImpl("11103222333111");
137		nnn = new ISDNAddressStringImpl(AddressNature.subscriber_number, NumberingPlan.land_mobile, "00001111");
138		lmsi = new LMSIImpl(new byte[] { 0, 2, 1, 0 });
139		ISDNAddressString additionalNumber = new ISDNAddressStringImpl(AddressNature.national_significant_number, NumberingPlan.land_mobile, "99999999");
140		li = new LocationInfoWithLMSIImpl(nnn, lmsi, MAPExtensionContainerTest.GetTestExtensionContainer(), AdditionalNumberType.sgsn, additionalNumber);
141		ind = new SendRoutingInfoForSMResponseIndicationImpl(imsi, li, MAPExtensionContainerTest.GetTestExtensionContainer());
142		
143		asnOS = new AsnOutputStream();
144		ind.encodeAll(asnOS);
145		
146		encodedData = asnOS.toByteArray();
147		rawData = getEncodedDataFull();		
148		assertTrue( Arrays.equals(rawData,encodedData));
149	}
150
151}