PageRenderTime 47ms CodeModel.GetById 26ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://mobicents.googlecode.com/
Java | 89 lines | 47 code | 16 blank | 26 comment | 0 complexity | ac09de7261e083ae7357ec534f76cfc6 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.MAPOperationCode;
31import org.mobicents.protocols.ss7.map.api.primitives.AddressNature;
32import org.mobicents.protocols.ss7.map.api.primitives.AddressString;
33import org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString;
34import org.mobicents.protocols.ss7.map.api.primitives.NumberingPlan;
35import org.mobicents.protocols.ss7.map.primitives.AddressStringImpl;
36import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
37
38import static org.testng.Assert.*;import org.testng.*;import org.testng.annotations.*;
39
40/**
41 * 
42 * @author sergey vetyutnev
43 *
44 */
45public class AlertServiceCentreRequestIndicationTest  {
46	
47	private byte[] getEncodedData() {
48		return new byte[] { 48, 18, 4, 7, -111, -110, 17, 19, 50, 19, -15, 4, 7, -111, -108, -120, 115, 0, -110, -14 };
49	}
50	
51	@Test
52	public void testDecode() throws Exception {
53		
54		byte[] rawData = getEncodedData();
55		AsnInputStream asn = new AsnInputStream(rawData);
56
57		int tag = asn.readTag();
58		AlertServiceCentreRequestIndicationImpl asc = new AlertServiceCentreRequestIndicationImpl(MAPOperationCode.alertServiceCentre);
59		asc.decodeAll(asn);
60
61		assertEquals( tag,Tag.SEQUENCE);
62		assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
63		
64		ISDNAddressString msisdn = asc.getMsisdn();
65		assertEquals( msisdn.getAddressNature(),AddressNature.international_number);
66		assertEquals( msisdn.getNumberingPlan(),NumberingPlan.ISDN);
67		assertEquals( msisdn.getAddress(),"29113123311");
68		
69		AddressString sca = asc.getServiceCentreAddress();
70		assertEquals( sca.getAddressNature(),AddressNature.international_number);
71		assertEquals( sca.getNumberingPlan(),NumberingPlan.ISDN);
72		assertEquals( sca.getAddress(),"49883700292");
73	}
74
75	@Test(groups = { "functional.encode"})
76	public void testEncode() throws Exception {
77
78		ISDNAddressString msisdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "29113123311");
79		AddressString sca = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "49883700292");
80		AlertServiceCentreRequestIndicationImpl asc = new AlertServiceCentreRequestIndicationImpl(msisdn, sca);
81		
82		AsnOutputStream asnOS = new AsnOutputStream();
83		asc.encodeAll(asnOS);
84		
85		byte[] encodedData = asnOS.toByteArray();
86		byte[] rawData = getEncodedData();		
87		assertTrue( Arrays.equals(rawData,encodedData));
88	}
89}