PageRenderTime 25ms CodeModel.GetById 1ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://mobicents.googlecode.com/
Java | 242 lines | 165 code | 45 blank | 32 comment | 0 complexity | af17f0b99dcd9dea736d3927369ec900 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 org.mobicents.protocols.asn.AsnInputStream;
 28import org.mobicents.protocols.asn.AsnOutputStream;
 29import org.mobicents.protocols.asn.Tag;
 30import org.mobicents.protocols.ss7.map.api.primitives.AddressNature;
 31import org.mobicents.protocols.ss7.map.api.primitives.AddressString;
 32import org.mobicents.protocols.ss7.map.api.primitives.IMSI;
 33import org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString;
 34import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
 35import org.mobicents.protocols.ss7.map.api.primitives.NumberingPlan;
 36import org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_DA;
 37import org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_OA;
 38import org.mobicents.protocols.ss7.map.api.service.sms.SmsSignalInfo;
 39import org.mobicents.protocols.ss7.map.primitives.AddressStringImpl;
 40import org.mobicents.protocols.ss7.map.primitives.IMSIImpl;
 41import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
 42import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerTest;
 43
 44import static org.testng.Assert.*;
 45
 46import org.testng.*;import org.testng.annotations.*;
 47
 48/**
 49 * 
 50 * @author sergey vetyutnev
 51 *
 52 */
 53public class MoForwardShortMessageRequestIndicationTest  {
 54	
 55	private byte[] getEncodedDataSimple() {
 56		return new byte[] { 48, 38, -124, 7, -111, 34, 51, 67, -103, 32, 50, -126, 8, -111, 50, 17, 50, 33, 67, 51, -12, 4, 17, 11, 22, 33, 44, 55, 66, 77, 0,
 57				1, 2, 3, 4, 5, 6, 7, 9, 8 };
 58	}
 59		
 60	private byte[] getEncodedDataComplex() {
 61		return new byte[] { 48, 71, -124, 8, -111, 50, 17, 50, 33, 67, 51, -12, -126, 7, -111, 34, 51, 67, -103, 32, 50, 4, 40, 11, 22, 33, 44, 55, 66, 77, 0,
 62				1, 2, 3, 4, 5, 6, 7, 9, 8, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 8, 0, 1, 33, 50, 51, -108, 9, -14 };
 63	}
 64	
 65	private byte[] getEncodedDataNoDaOa() {
 66		return new byte[] { 48, 58, -123, 0, -123, 0, 4, 52, 11, 22, 33, 44, 55, 66, 77, 0, 1, 2, 3, 4, 5, 6, 7, 9, 8, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3,
 67				3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 99, 88, 77, 66, 55, 44, 44, 33, 22, 11, 11, 0 };
 68	}
 69	
 70	private byte[] getEncodedDataFull() {
 71		return new byte[] { 48, 80, -128, 8, 2, 1, 17, 50, 84, 118, -104, -16, -124, 6, -74, 16, 50, 84, 118, -104, 4, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99,
 72				48, 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, 23, 24, 25, 26, -95, 3, 31,
 73				32, 33, 4, 8, 66, -128, 24, 33, 50, 67, 84, -11 };
 74	}
 75	
 76	@Test(groups = { "functional.decode","service.sms"})
 77	public void testDecode() throws Exception {
 78		
 79		byte[] rawData = getEncodedDataSimple();
 80		AsnInputStream asn = new AsnInputStream(rawData);
 81
 82		int tag = asn.readTag();
 83		MoForwardShortMessageRequestIndicationImpl ind = new MoForwardShortMessageRequestIndicationImpl();
 84		ind.decodeAll(asn);
 85
 86		assertEquals( tag,Tag.SEQUENCE);
 87		assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
 88		
 89		SM_RP_DA da = ind.getSM_RP_DA();
 90		SM_RP_OA oa = ind.getSM_RP_OA();
 91		SmsSignalInfo ui = ind.getSM_RP_UI();
 92		assertEquals( da.getServiceCentreAddressDA().getAddressNature(),AddressNature.international_number);
 93		assertEquals( da.getServiceCentreAddressDA().getNumberingPlan(),NumberingPlan.ISDN);
 94		assertEquals( da.getServiceCentreAddressDA().getAddress(),"223334990223");
 95		assertEquals( oa.getMsisdn().getAddressNature(),AddressNature.international_number);
 96		assertEquals( oa.getMsisdn().getNumberingPlan(),NumberingPlan.ISDN);
 97		assertEquals( oa.getMsisdn().getAddress(),"2311231234334");
 98		assertTrue(Arrays.equals(ui.getData(), new byte[] { 11, 22, 33, 44, 55, 66, 77, 0, 1, 2, 3, 4, 5, 6, 7, 9, 8 }));
 99		
100		rawData = getEncodedDataComplex();
101		asn = new AsnInputStream(rawData);
102
103		tag = asn.readTag();
104		ind = new MoForwardShortMessageRequestIndicationImpl();
105		ind.decodeAll(asn);
106
107		assertEquals( tag,Tag.SEQUENCE);
108		assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
109		
110		da = ind.getSM_RP_DA();
111		oa = ind.getSM_RP_OA();
112		ui = ind.getSM_RP_UI();
113		IMSI imsi = ind.getIMSI();
114		assertEquals( da.getServiceCentreAddressDA().getAddressNature(),AddressNature.international_number);
115		assertEquals( da.getServiceCentreAddressDA().getNumberingPlan(),NumberingPlan.ISDN);
116		assertEquals( da.getServiceCentreAddressDA().getAddress(),"2311231234334");
117		assertEquals( oa.getMsisdn().getAddressNature(),AddressNature.international_number);
118		assertEquals( oa.getMsisdn().getNumberingPlan(),NumberingPlan.ISDN);
119		assertEquals( oa.getMsisdn().getAddress(),"223334990223");
120		assertTrue(Arrays.equals(ui.getData(), new byte[] { 11, 22, 33, 44, 55, 66, 77, 0, 1, 2, 3, 4, 5, 6, 7, 9, 8, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4 }));
121//		assertEquals( (long)imsi.getMCC(),1);
122//		assertEquals( (long)imsi.getMNC(),1);
123		assertEquals( imsi.getData(),"001012233349902");
124		
125		
126		rawData = getEncodedDataNoDaOa();
127		asn = new AsnInputStream(rawData);
128
129		tag = asn.readTag();
130		ind = new MoForwardShortMessageRequestIndicationImpl();
131		ind.decodeAll(asn);
132
133		assertEquals( tag,Tag.SEQUENCE);
134		assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
135		
136		da = ind.getSM_RP_DA();
137		oa = ind.getSM_RP_OA();
138		ui = ind.getSM_RP_UI();
139		assertNull(da.getServiceCentreAddressDA());
140		assertNull(da.getIMSI());
141		assertNull(da.getLMSI());
142		assertNull(oa.getMsisdn());
143		assertNull(oa.getServiceCentreAddressOA());
144		assertTrue(Arrays.equals(ui.getData(), new byte[] { 11, 22, 33, 44, 55, 66, 77, 0, 1, 2, 3, 4, 5, 6, 7, 9, 8, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,4, 4, 4, 4, 4, 4, 99, 88, 77, 66, 55, 44, 44, 33, 22, 11, 11, 0 }));
145		
146		rawData = getEncodedDataFull();
147		asn = new AsnInputStream(rawData);
148
149		tag = asn.readTag();
150		ind = new MoForwardShortMessageRequestIndicationImpl();
151		ind.decodeAll(asn);
152
153		assertEquals( tag,Tag.SEQUENCE);
154		assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
155		
156		da = ind.getSM_RP_DA();
157		oa = ind.getSM_RP_OA();
158		ui = ind.getSM_RP_UI();
159		imsi = ind.getIMSI();
160//		assertEquals( (long)da.getIMSI().getMCC(),201);
161//		assertEquals( (long)da.getIMSI().getMNC(),1);
162		assertEquals( da.getIMSI().getData(),"201011234567890");
163		assertEquals( oa.getServiceCentreAddressOA().getAddressNature(),AddressNature.network_specific_number);
164		assertEquals( oa.getServiceCentreAddressOA().getNumberingPlan(),NumberingPlan.land_mobile);
165		assertEquals( oa.getServiceCentreAddressOA().getAddress(),"0123456789");
166		assertTrue(Arrays.equals(ui.getData(), new byte[] { 11, 22, 33, 44, 55, 66, 77, 88, 99 }));
167//		assertEquals( (long)imsi.getMCC(),240);
168//		assertEquals( (long)imsi.getMNC(),88);
169		assertEquals( imsi.getData(),"240881122334455");
170		assertTrue(MAPExtensionContainerTest.CheckTestExtensionContainer(ind.getExtensionContainer()));
171	}
172
173	@Test(groups = { "functional.encode","service.sms"})
174	public void testEncode() throws Exception {
175
176		AddressString sca = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "223334990223");
177		SM_RP_DA sm_RP_DA = new SM_RP_DAImpl(sca);
178		ISDNAddressString msisdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "2311231234334");
179		SM_RP_OAImpl sm_RP_OA = new SM_RP_OAImpl();
180		sm_RP_OA.setMsisdn(msisdn);
181		SmsSignalInfo sm_RP_UI = new SmsSignalInfoImpl(new byte[] { 11, 22, 33, 44, 55, 66, 77, 0, 1, 2, 3, 4, 5, 6, 7, 9, 8 }, null);
182		MoForwardShortMessageRequestIndicationImpl ind = new MoForwardShortMessageRequestIndicationImpl(sm_RP_DA, sm_RP_OA, sm_RP_UI, null, null);
183		
184		AsnOutputStream asnOS = new AsnOutputStream();
185		ind.encodeAll(asnOS);
186		
187		byte[] encodedData = asnOS.toByteArray();
188		byte[] rawData = getEncodedDataSimple();		
189		assertTrue( Arrays.equals(rawData,encodedData));
190
191		
192		sca = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "2311231234334");
193		sm_RP_DA = new SM_RP_DAImpl(sca);
194		msisdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "223334990223");
195		sm_RP_OA = new SM_RP_OAImpl();
196		sm_RP_OA.setMsisdn(msisdn);
197		sm_RP_UI = new SmsSignalInfoImpl(new byte[] { 11, 22, 33, 44, 55, 66, 77, 0, 1, 2, 3, 4, 5, 6, 7, 9, 8, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3,
198				3, 4, 4, 4, 4, 4, 4 }, null);
199		IMSI imsi = new IMSIImpl("001012233349902");
200		ind = new MoForwardShortMessageRequestIndicationImpl(sm_RP_DA, sm_RP_OA, sm_RP_UI, null, imsi);
201		
202		asnOS = new AsnOutputStream();
203		ind.encodeAll(asnOS);
204		
205		encodedData = asnOS.toByteArray();
206		rawData = getEncodedDataComplex();		
207		assertTrue( Arrays.equals(rawData,encodedData));
208
209		
210		sm_RP_DA = new SM_RP_DAImpl();
211		sm_RP_OA = new SM_RP_OAImpl();
212		sm_RP_UI = new SmsSignalInfoImpl(new byte[] { 11, 22, 33, 44, 55, 66, 77, 0, 1, 2, 3, 4, 5, 6, 7, 9, 8, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3,
213				3, 4, 4, 4, 4, 4, 4, 99, 88, 77, 66, 55, 44, 44, 33, 22, 11, 11, 0 }, null);
214		ind = new MoForwardShortMessageRequestIndicationImpl(sm_RP_DA, sm_RP_OA, sm_RP_UI, null, null);
215
216		asnOS = new AsnOutputStream();
217		ind.encodeAll(asnOS);
218		
219		encodedData = asnOS.toByteArray();
220		rawData = getEncodedDataNoDaOa();		
221		assertTrue( Arrays.equals(rawData,encodedData));
222
223		
224		IMSI imsi0 = new IMSIImpl("201011234567890");
225		sm_RP_DA = new SM_RP_DAImpl(imsi0);
226		msisdn = new ISDNAddressStringImpl(AddressNature.network_specific_number, NumberingPlan.land_mobile, "0123456789");
227		sm_RP_OA = new SM_RP_OAImpl();
228		sm_RP_OA.setServiceCentreAddressOA(msisdn);
229		sm_RP_UI = new SmsSignalInfoImpl(new byte[] { 11, 22, 33, 44, 55, 66, 77, 88, 99 }, null);
230		MAPExtensionContainer extensionContainer = MAPExtensionContainerTest.GetTestExtensionContainer();
231		imsi = new IMSIImpl("240881122334455");
232		ind = new MoForwardShortMessageRequestIndicationImpl(sm_RP_DA, sm_RP_OA, sm_RP_UI, extensionContainer, imsi);
233		
234		asnOS = new AsnOutputStream();
235		ind.encodeAll(asnOS);
236
237		encodedData = asnOS.toByteArray();
238		rawData = getEncodedDataFull();		
239		assertTrue( Arrays.equals(rawData,encodedData));
240	}
241
242}