PageRenderTime 41ms CodeModel.GetById 25ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 179 lines | 117 code | 36 blank | 26 comment | 0 complexity | 30d667b10b5c9d80197884d490142eaa 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.ISDNAddressString;
 33import org.mobicents.protocols.ss7.map.api.primitives.NumberingPlan;
 34import org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_MTI;
 35import org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_SMEA;
 36import org.mobicents.protocols.ss7.map.primitives.AddressStringImpl;
 37import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
 38import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerTest;
 39
 40import static org.testng.Assert.*;
 41
 42import org.testng.*;import org.testng.annotations.*;
 43
 44/**
 45 * 
 46 * @author sergey vetyutnev
 47 *
 48 */
 49public class SendRoutingInfoForSMRequestIndicationTest  {
 50	
 51	private byte[] getEncodedDataSimple() {
 52		return new byte[] { 48, 20, -128, 7, -111, 49, 84, 119, 84, 85, -15, -127, 1, 0, -126, 6, -111, -119, 18, 17, 51, 51 };
 53	}
 54
 55	private byte[] getEncodedDataComplex() {
 56		return new byte[] { 48, 30, -128, 7, -111, 49, 84, 119, 84, 85, -15, -127, 1, 0, -126, 6, -111, -119, 18, 17, 51, 51, -121, 0, -119, 6, -111, 105, 49,
 57				3, -105, 97 };
 58	}
 59	
 60	private byte[] getEncodedDataFull() {
 61		return new byte[] { 48, 70, -128, 6, -111, 17, 33, 34, 51, -13, -127, 1, -1, -126, 3, -72, 68, 68, -90, 39, -96, 32, 48, 10, 6, 3, 42, 3, 4, 11, 12,
 62				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, -121, 0, -120, 1, 1, -119, 6, -111, 105,
 63				49, 3, -105, 97 };
 64	}
 65	
 66	@Test(groups = { "functional.decode","service.sms"})
 67	public void testDecode() throws Exception {
 68		
 69		byte[] rawData = getEncodedDataSimple();
 70		AsnInputStream asn = new AsnInputStream(rawData);
 71
 72		int tag = asn.readTag();
 73		SendRoutingInfoForSMRequestIndicationImpl ind = new SendRoutingInfoForSMRequestIndicationImpl();
 74		ind.decodeAll(asn);
 75
 76		assertEquals( tag,Tag.SEQUENCE);
 77		assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
 78
 79		ISDNAddressString msisdn = ind.getMsisdn();
 80		assertEquals( msisdn.getAddressNature(),AddressNature.international_number);
 81		assertEquals( msisdn.getNumberingPlan(),NumberingPlan.ISDN);
 82		assertEquals( msisdn.getAddress(),"13457745551");
 83		assertEquals( (boolean) ind.getSm_RP_PRI(),false);		
 84		AddressString sca = ind.getServiceCentreAddress();
 85		assertEquals( sca.getAddressNature(),AddressNature.international_number);
 86		assertEquals( sca.getNumberingPlan(),NumberingPlan.ISDN);
 87		assertEquals( sca.getAddress(),"9821113333");
 88
 89		
 90		rawData = getEncodedDataComplex();
 91		asn = new AsnInputStream(rawData);
 92
 93		tag = asn.readTag();
 94		ind = new SendRoutingInfoForSMRequestIndicationImpl();
 95		ind.decodeAll(asn);
 96
 97		assertEquals( tag,Tag.SEQUENCE);
 98		assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
 99
100		msisdn = ind.getMsisdn();
101		assertEquals( msisdn.getAddressNature(),AddressNature.international_number);
102		assertEquals( msisdn.getNumberingPlan(),NumberingPlan.ISDN);
103		assertEquals( msisdn.getAddress(),"13457745551");
104		assertEquals( (boolean) ind.getSm_RP_PRI(),false);		
105		sca = ind.getServiceCentreAddress();
106		assertEquals( sca.getAddressNature(),AddressNature.international_number);
107		assertEquals( sca.getNumberingPlan(),NumberingPlan.ISDN);
108		assertEquals( sca.getAddress(),"9821113333");
109		assertEquals( (boolean) ind.getGprsSupportIndicator(),true);
110		assertTrue(Arrays.equals(new byte[] { -111, 105, 49, 3, -105, 97 }, ind.getSM_RP_SMEA().getData()));
111
112		
113		rawData = getEncodedDataFull();
114		asn = new AsnInputStream(rawData);
115
116		tag = asn.readTag();
117		ind = new SendRoutingInfoForSMRequestIndicationImpl();
118		ind.decodeAll(asn);
119
120		assertEquals( tag,Tag.SEQUENCE);
121		assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
122
123		msisdn = ind.getMsisdn();
124		assertEquals( msisdn.getAddressNature(),AddressNature.international_number);
125		assertEquals( msisdn.getNumberingPlan(),NumberingPlan.ISDN);
126		assertEquals( msisdn.getAddress(),"111222333");
127		assertEquals( (boolean) ind.getSm_RP_PRI(),true);		
128		sca = ind.getServiceCentreAddress();
129		assertEquals( sca.getAddressNature(),AddressNature.network_specific_number);
130		assertEquals( sca.getNumberingPlan(),NumberingPlan.national);
131		assertEquals( sca.getAddress(),"4444");
132		assertEquals( (boolean) ind.getGprsSupportIndicator(),true);
133		assertTrue(Arrays.equals(new byte[] { -111, 105, 49, 3, -105, 97 }, ind.getSM_RP_SMEA().getData()));
134		assertTrue(MAPExtensionContainerTest.CheckTestExtensionContainer(ind.getExtensionContainer()));
135		assertEquals( ind.getSM_RP_MTI(),SM_RP_MTI.SMS_Status_Report);
136	}
137
138	@Test(groups = { "functional.encode","service.sms"})
139	public void testEncode() throws Exception {
140
141		ISDNAddressString msisdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "13457745551");
142		AddressString sca = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "9821113333");
143		SendRoutingInfoForSMRequestIndicationImpl ind = new SendRoutingInfoForSMRequestIndicationImpl(msisdn, false, sca, null, false, null, null);
144		
145		AsnOutputStream asnOS = new AsnOutputStream();
146		ind.encodeAll(asnOS);
147		
148		byte[] encodedData = asnOS.toByteArray();
149		byte[] rawData = getEncodedDataSimple();		
150		assertTrue( Arrays.equals(rawData,encodedData));
151
152		
153		msisdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "13457745551");
154		sca = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "9821113333");
155		SM_RP_SMEA ui = new SM_RP_SMEAImpl(new byte[] { -111, 105, 49, 3, -105, 97 });
156		ind = new SendRoutingInfoForSMRequestIndicationImpl(msisdn, false, sca, null, true, null, ui);
157		
158		asnOS = new AsnOutputStream();
159		ind.encodeAll(asnOS);
160		
161		encodedData = asnOS.toByteArray();
162		rawData = getEncodedDataComplex();		
163		assertTrue( Arrays.equals(rawData,encodedData));
164
165		
166		msisdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "111222333");
167		sca = new AddressStringImpl(AddressNature.network_specific_number, NumberingPlan.national, "4444");
168		ui = new SM_RP_SMEAImpl(new byte[] { -111, 105, 49, 3, -105, 97 });
169		ind = new SendRoutingInfoForSMRequestIndicationImpl(msisdn, true, sca, MAPExtensionContainerTest.GetTestExtensionContainer(), true,
170				SM_RP_MTI.SMS_Status_Report, ui);
171		
172		asnOS = new AsnOutputStream();
173		ind.encodeAll(asnOS);
174		
175		encodedData = asnOS.toByteArray();
176		rawData = getEncodedDataFull();		
177		assertTrue( Arrays.equals(rawData,encodedData));
178	}
179}