PageRenderTime 53ms CodeModel.GetById 13ms app.highlight 35ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://mobicents.googlecode.com/
Java | 192 lines | 117 code | 43 blank | 32 comment | 0 complexity | 6cfdca90d6d11f75804291274e89f979 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 static org.testng.Assert.assertEquals;
 26import static org.testng.Assert.assertTrue;
 27
 28import java.io.ByteArrayInputStream;
 29import java.io.ByteArrayOutputStream;
 30import java.io.InputStream;
 31import java.io.ObjectInputStream;
 32import java.io.ObjectOutputStream;
 33import java.util.Arrays;
 34
 35import org.mobicents.protocols.asn.AsnInputStream;
 36import org.mobicents.protocols.asn.AsnOutputStream;
 37import org.mobicents.protocols.asn.Tag;
 38import org.mobicents.protocols.ss7.map.api.primitives.AddressNature;
 39import org.mobicents.protocols.ss7.map.api.primitives.AddressString;
 40import org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString;
 41import org.mobicents.protocols.ss7.map.api.primitives.NumberingPlan;
 42import org.mobicents.protocols.ss7.map.primitives.AddressStringImpl;
 43import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
 44import org.testng.annotations.Test;
 45/**
 46 * 
 47 * @author sergey vetyutnev
 48 *
 49 */
 50public class SM_RP_OATest {
 51	
 52	private byte[] getEncodedData_Msisdn() {
 53		return new byte[] { (byte)130, 7, (byte)145, (byte)147, 51, 88, 38, 101, 89 };
 54	}
 55	
 56	private byte[] getEncodedData_ServiceCentreAddressOA() {
 57		return new byte[] { -124, 7, -111, -127, 16, 7, 17, 17, -15 };
 58	}
 59	
 60	private byte[] getEncodedData_No() {
 61		return new byte[] { (byte)133, 0 };
 62	}
 63	
 64	@Test(groups = { "functional.decode","service.sms"})
 65	public void testDecode() throws Exception {
 66		
 67		byte[] rawData = getEncodedData_ServiceCentreAddressOA();
 68		AsnInputStream asn = new AsnInputStream(rawData);
 69
 70		int tag = asn.readTag();
 71		SM_RP_OAImpl oa = new SM_RP_OAImpl();
 72		oa.decodeAll(asn);
 73
 74		assertEquals( tag,4);
 75		assertEquals( asn.getTagClass(),Tag.CLASS_CONTEXT_SPECIFIC);
 76		
 77		AddressString nnm = oa.getServiceCentreAddressOA();
 78		assertEquals( nnm.getAddressNature(),AddressNature.international_number);
 79		assertEquals( nnm.getNumberingPlan(),NumberingPlan.ISDN);
 80		assertEquals( nnm.getAddress(),"18017011111");
 81
 82		
 83		rawData = getEncodedData_Msisdn();
 84		asn = new AsnInputStream(rawData);
 85
 86		tag = asn.readTag();
 87		oa = new SM_RP_OAImpl();
 88		oa.decodeAll(asn);
 89
 90		assertEquals( tag,2);
 91		assertEquals( asn.getTagClass(),Tag.CLASS_CONTEXT_SPECIFIC);
 92		
 93		ISDNAddressString msisdn = oa.getMsisdn();
 94		assertEquals( msisdn.getAddressNature(),AddressNature.international_number);
 95		assertEquals( msisdn.getNumberingPlan(),NumberingPlan.ISDN);
 96		assertEquals( msisdn.getAddress(),"393385625695");
 97
 98		
 99		rawData = getEncodedData_No();
100		asn = new AsnInputStream(rawData);
101
102		tag = asn.readTag();
103		oa = new SM_RP_OAImpl();
104		oa.decodeAll(asn);
105
106		assertEquals( tag,5);
107		assertEquals( asn.getTagClass(),Tag.CLASS_CONTEXT_SPECIFIC);
108		
109		assertEquals( oa.getServiceCentreAddressOA(),null);
110		assertEquals( oa.getMsisdn(),null);
111	}
112
113	@Test(groups = { "functional.encode","service.sms"})
114	public void testEncode() throws Exception {
115		
116		AddressStringImpl astr = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "18017011111");
117		SM_RP_OAImpl oa = new SM_RP_OAImpl();
118		oa.setServiceCentreAddressOA(astr);
119		
120		AsnOutputStream asnOS = new AsnOutputStream();
121		oa.encodeAll(asnOS);
122		
123		byte[] encodedData = asnOS.toByteArray();
124		byte[] rawData = getEncodedData_ServiceCentreAddressOA();		
125		assertTrue( Arrays.equals(rawData,encodedData));
126		
127		
128		ISDNAddressStringImpl isdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "393385625695");
129		oa = new SM_RP_OAImpl();
130		oa.setMsisdn(isdn);
131		
132		asnOS = new AsnOutputStream();
133		oa.encodeAll(asnOS);
134		
135		encodedData = asnOS.toByteArray();
136		rawData = getEncodedData_Msisdn();		
137		assertTrue( Arrays.equals(rawData,encodedData));
138		
139		
140		oa = new SM_RP_OAImpl();
141		
142		asnOS = new AsnOutputStream();
143		oa.encodeAll(asnOS);
144		
145		encodedData = asnOS.toByteArray();
146		rawData = getEncodedData_No();		
147		assertTrue( Arrays.equals(rawData,encodedData));
148	}
149	
150	@Test(groups = { "functional.serialize", "service.sms" })
151	public void testSerialization() throws Exception {
152		AddressStringImpl astr = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "18017011111");
153		SM_RP_OAImpl original = new SM_RP_OAImpl();
154		
155		// serialize
156		ByteArrayOutputStream out = new ByteArrayOutputStream();
157		ObjectOutputStream oos = new ObjectOutputStream(out);
158		oos.writeObject(original);
159		oos.close();
160
161		// deserialize
162		byte[] pickled = out.toByteArray();
163		InputStream in = new ByteArrayInputStream(pickled);
164		ObjectInputStream ois = new ObjectInputStream(in);
165		Object o = ois.readObject();
166		SM_RP_OAImpl copy = (SM_RP_OAImpl) o;
167		
168		//test result
169		assertEquals(copy.getServiceCentreAddressOA(), original.getServiceCentreAddressOA());
170		
171		
172		
173		ISDNAddressStringImpl isdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "393385625695");
174		original = new SM_RP_OAImpl();
175		original.setMsisdn(isdn);
176		// serialize
177		out = new ByteArrayOutputStream();
178		oos = new ObjectOutputStream(out);
179		oos.writeObject(original);
180		oos.close();
181
182		// deserialize
183		pickled = out.toByteArray();
184		in = new ByteArrayInputStream(pickled);
185		ois = new ObjectInputStream(in);
186		o = ois.readObject();
187		copy = (SM_RP_OAImpl) o;
188		
189		//test result
190		assertEquals(copy.getMsisdn(), original.getMsisdn());
191	}
192}