PageRenderTime 92ms CodeModel.GetById 68ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 239 lines | 144 code | 57 blank | 38 comment | 3 complexity | 004a7ff2a54d18a74130be6c6ab0958b 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.IMSI;
 41import org.mobicents.protocols.ss7.map.api.primitives.NumberingPlan;
 42import org.mobicents.protocols.ss7.map.primitives.AddressStringImpl;
 43import org.mobicents.protocols.ss7.map.primitives.IMSIImpl;
 44import org.mobicents.protocols.ss7.map.primitives.LMSIImpl;
 45import org.testng.annotations.Test;
 46
 47/**
 48 * 
 49 * @author sergey vetyutnev
 50 *
 51 */
 52public class SM_RP_DATest {
 53	
 54	private byte[] getEncodedData_ServiceCentreAddressDA() {
 55		return new byte[] { -124, 7, -111, 33, 49, -107, 6, 105, 0 };
 56	}
 57	
 58	private byte[] getEncodedData_LMSI() {
 59		return new byte[] { (byte)129, 4, 0, 7, (byte)144, (byte)178 };
 60	}
 61	
 62	private byte[] getEncodedData_IMSI() {
 63		return new byte[] { -128, 8, 64, 1, 4, 34, 18, 22, 69, -9 };
 64	}
 65	
 66	private byte[] getEncodedData_No() {
 67		return new byte[] { (byte)133, 0 };
 68	}
 69	
 70	@Test(groups = { "functional.decode","service.sms"})
 71	public void testDecode() throws Exception {
 72		
 73		byte[] rawData = getEncodedData_ServiceCentreAddressDA();
 74		AsnInputStream asn = new AsnInputStream(rawData);
 75
 76		int tag = asn.readTag();
 77		SM_RP_DAImpl da = new SM_RP_DAImpl();
 78		da.decodeAll(asn);
 79
 80		assertEquals( tag,4);
 81		assertEquals( asn.getTagClass(),Tag.CLASS_CONTEXT_SPECIFIC);
 82		
 83		AddressString nnm = da.getServiceCentreAddressDA();
 84		assertEquals( nnm.getAddressNature(),AddressNature.international_number);
 85		assertEquals( nnm.getNumberingPlan(),NumberingPlan.ISDN);
 86		assertEquals( nnm.getAddress(),"121359609600");
 87		
 88		
 89		rawData = getEncodedData_LMSI();
 90		asn = new AsnInputStream(rawData);
 91
 92		tag = asn.readTag();
 93		da = new SM_RP_DAImpl();
 94		da.decodeAll(asn);
 95
 96		assertEquals( tag,1);
 97		assertEquals( asn.getTagClass(),Tag.CLASS_CONTEXT_SPECIFIC);
 98		
 99		assertTrue(Arrays.equals(new byte[] { 0, 7, -112, -78 }, da.getLMSI().getData()));
100		
101		
102		rawData = getEncodedData_IMSI();
103		asn = new AsnInputStream(rawData);
104
105		tag = asn.readTag();
106		da = new SM_RP_DAImpl();
107		da.decodeAll(asn);
108
109		assertEquals( tag,0);
110		assertEquals( asn.getTagClass(),Tag.CLASS_CONTEXT_SPECIFIC);
111
112		IMSI imsi = da.getIMSI();
113		assertEquals( imsi.getData(),"041040222161547");
114//		assertEquals( (long)imsi.getMCC(),41);
115//		assertEquals( (long)imsi.getMNC(),4);
116//		assertEquals( imsi.getMSIN(),"0222161547");
117		
118		
119		rawData = getEncodedData_No();
120		asn = new AsnInputStream(rawData);
121
122		tag = asn.readTag();
123		da = new SM_RP_DAImpl();
124		da.decodeAll(asn);
125
126		assertEquals( tag,5);
127		assertEquals( asn.getTagClass(),Tag.CLASS_CONTEXT_SPECIFIC);
128
129		assertTrue(da.getServiceCentreAddressDA() == null);		
130		assertTrue(da.getIMSI() == null);		
131		assertTrue(da.getLMSI() == null);		
132	}
133
134	@Test(groups = { "functional.encode","service.sms"})
135	public void testEncode() throws Exception {
136
137		AddressStringImpl astr = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "121359609600");
138		SM_RP_DAImpl da = new SM_RP_DAImpl(astr);
139		
140		AsnOutputStream asnOS = new AsnOutputStream();
141		da.encodeAll(asnOS);
142		
143		byte[] encodedData = asnOS.toByteArray();
144		byte[] rawData = getEncodedData_ServiceCentreAddressDA();		
145		assertTrue( Arrays.equals(rawData,encodedData));
146
147
148		LMSIImpl lmsi = new LMSIImpl(new byte[] { 0, 7, -112, -78 });
149		da = new SM_RP_DAImpl(lmsi);
150		
151		asnOS = new AsnOutputStream();
152		da.encodeAll(asnOS);
153		
154		encodedData = asnOS.toByteArray();
155		rawData = getEncodedData_LMSI();		
156		assertTrue( Arrays.equals(rawData,encodedData));
157
158		
159		IMSIImpl imsi = new IMSIImpl("041040222161547");		
160		da = new SM_RP_DAImpl(imsi);
161		
162		asnOS = new AsnOutputStream();
163		da.encodeAll(asnOS);
164		
165		encodedData = asnOS.toByteArray();
166		rawData = getEncodedData_IMSI();		
167		assertTrue( Arrays.equals(rawData,encodedData));
168		
169		
170		da = new SM_RP_DAImpl();
171		
172		asnOS = new AsnOutputStream();
173		da.encodeAll(asnOS);
174		
175		encodedData = asnOS.toByteArray();
176		rawData = getEncodedData_No();		
177		assertTrue( Arrays.equals(rawData,encodedData));
178	}
179	
180	@Test(groups = { "functional.serialize", "service.sms" })
181	public void testSerialization() throws Exception {
182		AddressStringImpl astr = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "121359609600");
183		SM_RP_DAImpl original = new SM_RP_DAImpl(astr);
184		
185		// serialize
186		ByteArrayOutputStream out = new ByteArrayOutputStream();
187		ObjectOutputStream oos = new ObjectOutputStream(out);
188		oos.writeObject(original);
189		oos.close();
190
191		// deserialize
192		byte[] pickled = out.toByteArray();
193		InputStream in = new ByteArrayInputStream(pickled);
194		ObjectInputStream ois = new ObjectInputStream(in);
195		Object o = ois.readObject();
196		SM_RP_DAImpl copy = (SM_RP_DAImpl) o;
197		
198		//test result
199		assertEquals(copy.getServiceCentreAddressDA(), original.getServiceCentreAddressDA());
200		
201		
202		LMSIImpl lmsi = new LMSIImpl(new byte[] { 0, 7, -112, -78 });
203		original = new SM_RP_DAImpl(lmsi);
204		// serialize
205		out = new ByteArrayOutputStream();
206		oos = new ObjectOutputStream(out);
207		oos.writeObject(original);
208		oos.close();
209
210		// deserialize
211		pickled = out.toByteArray();
212		in = new ByteArrayInputStream(pickled);
213		ois = new ObjectInputStream(in);
214		o = ois.readObject();
215		copy = (SM_RP_DAImpl) o;
216		
217		//test result
218		assertEquals(copy.getLMSI(), original.getLMSI());
219		
220		
221		IMSIImpl imsi = new IMSIImpl("041040222161547");		
222		original = new SM_RP_DAImpl(imsi);
223		// serialize
224		out = new ByteArrayOutputStream();
225		oos = new ObjectOutputStream(out);
226		oos.writeObject(original);
227		oos.close();
228
229		// deserialize
230		pickled = out.toByteArray();
231		in = new ByteArrayInputStream(pickled);
232		ois = new ObjectInputStream(in);
233		o = ois.readObject();
234		copy = (SM_RP_DAImpl) o;
235		
236		//test result
237		assertEquals(copy.getIMSI(), original.getIMSI());
238	}
239}