PageRenderTime 74ms CodeModel.GetById 28ms app.highlight 41ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 146 lines | 94 code | 26 blank | 26 comment | 0 complexity | 2223e63dff470a6493f2f28569ce2f92 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_DA;
 35import org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_OA;
 36import org.mobicents.protocols.ss7.map.api.service.sms.SmsSignalInfo;
 37import org.mobicents.protocols.ss7.map.primitives.AddressStringImpl;
 38import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
 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 ForwardShortMessageRequestIndicationTest {
 50	
 51	private byte[] getEncodedDataSimple() {
 52		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,
 53				1, 2, 3, 4, 5, 6, 7, 9, 8 };
 54	}
 55
 56	private byte[] getEncodedDataComplex() {
 57		return new byte[] { 48, 63, -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,
 58				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, 5, 0 };
 59	}
 60	
 61	@Test(groups = { "functional.decode","service.sms"})
 62	public void testDecode() throws Exception {
 63		
 64		byte[] rawData = getEncodedDataSimple();
 65		AsnInputStream asn = new AsnInputStream(rawData);
 66
 67		int tag = asn.readTag();
 68		ForwardShortMessageRequestIndicationImpl ind = new ForwardShortMessageRequestIndicationImpl();
 69		ind.decodeAll(asn);
 70
 71		assertEquals(Tag.SEQUENCE, tag);
 72		assertEquals(Tag.CLASS_UNIVERSAL, asn.getTagClass());
 73		
 74		SM_RP_DA da = ind.getSM_RP_DA();
 75		SM_RP_OA oa = ind.getSM_RP_OA();
 76		SmsSignalInfo ui = ind.getSM_RP_UI();
 77		assertEquals(AddressNature.international_number, da.getServiceCentreAddressDA().getAddressNature());
 78		assertEquals(NumberingPlan.ISDN, da.getServiceCentreAddressDA().getNumberingPlan());
 79		assertEquals("223334990223", da.getServiceCentreAddressDA().getAddress());
 80		assertEquals(AddressNature.international_number, oa.getMsisdn().getAddressNature());
 81		assertEquals(NumberingPlan.ISDN, oa.getMsisdn().getNumberingPlan());
 82		assertEquals("2311231234334", oa.getMsisdn().getAddress());
 83		assertTrue(Arrays.equals(ui.getData(), new byte[] { 11, 22, 33, 44, 55, 66, 77, 0, 1, 2, 3, 4, 5, 6, 7, 9, 8 }));
 84		assertFalse(ind.getMoreMessagesToSend());
 85		
 86		rawData = getEncodedDataComplex();
 87		asn = new AsnInputStream(rawData);
 88
 89		tag = asn.readTag();
 90		ind = new ForwardShortMessageRequestIndicationImpl();
 91		ind.decodeAll(asn);
 92
 93		assertEquals(Tag.SEQUENCE, tag);
 94		assertEquals(Tag.CLASS_UNIVERSAL, asn.getTagClass());
 95		
 96		da = ind.getSM_RP_DA();
 97		oa = ind.getSM_RP_OA();
 98		ui = ind.getSM_RP_UI();
 99		assertEquals(AddressNature.international_number, da.getServiceCentreAddressDA().getAddressNature());
100		assertEquals(NumberingPlan.ISDN, da.getServiceCentreAddressDA().getNumberingPlan());
101		assertEquals("2311231234334", da.getServiceCentreAddressDA().getAddress());
102		assertEquals(AddressNature.international_number, oa.getMsisdn().getAddressNature());
103		assertEquals(NumberingPlan.ISDN, oa.getMsisdn().getNumberingPlan());
104		assertEquals("223334990223", oa.getMsisdn().getAddress());
105		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,
106				3, 3, 3, 4, 4, 4, 4, 4, 4 }));
107		assertTrue(ind.getMoreMessagesToSend());
108	}
109
110	@Test(groups = { "functional.decode","service.sms"})
111	public void testEncode() throws Exception {
112
113		AddressString sca = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "223334990223");
114		SM_RP_DA sm_RP_DA = new SM_RP_DAImpl(sca);
115		ISDNAddressString msisdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "2311231234334");
116		SM_RP_OAImpl sm_RP_OA = new SM_RP_OAImpl();
117		sm_RP_OA.setMsisdn(msisdn);
118		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);
119		ForwardShortMessageRequestIndicationImpl ind = new ForwardShortMessageRequestIndicationImpl(sm_RP_DA, sm_RP_OA, sm_RP_UI, false);
120		
121		AsnOutputStream asnOS = new AsnOutputStream();
122		ind.encodeAll(asnOS);
123		
124		byte[] encodedData = asnOS.toByteArray();
125		byte[] rawData = getEncodedDataSimple();		
126		assertTrue(Arrays.equals(rawData, encodedData));
127
128		
129		sca = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "2311231234334");
130		sm_RP_DA = new SM_RP_DAImpl(sca);
131		msisdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "223334990223");
132		sm_RP_OA = new SM_RP_OAImpl();
133		sm_RP_OA.setMsisdn(msisdn);
134		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,
135				3, 4, 4, 4, 4, 4, 4 }, null);
136		ind = new ForwardShortMessageRequestIndicationImpl(sm_RP_DA, sm_RP_OA, sm_RP_UI, true);
137		
138		asnOS = new AsnOutputStream();
139		ind.encodeAll(asnOS);
140		
141		encodedData = asnOS.toByteArray();
142		rawData = getEncodedDataComplex();		
143		assertTrue(Arrays.equals(rawData, encodedData));
144	}
145
146}