PageRenderTime 29ms CodeModel.GetById 2ms app.highlight 22ms RepoModel.GetById 2ms app.codeStats 0ms

/protocols/ss7/map/map-impl/src/test/java/org/mobicents/protocols/ss7/map/dialog/MAPOpenInfoTest.java

http://mobicents.googlecode.com/
Java | 202 lines | 123 code | 49 blank | 30 comment | 0 complexity | a48620495f592f96f570650ffafe382d 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.dialog;
 24
 25import java.util.Arrays;
 26
 27import static org.testng.Assert.*;
 28
 29import org.testng.annotations.*;
 30
 31import org.mobicents.protocols.asn.AsnInputStream;
 32import org.mobicents.protocols.asn.AsnOutputStream;
 33import org.mobicents.protocols.ss7.map.MAPParameterFactoryImpl;
 34import org.mobicents.protocols.ss7.map.api.MAPParameterFactory;
 35import org.mobicents.protocols.ss7.map.api.primitives.AddressNature;
 36import org.mobicents.protocols.ss7.map.api.primitives.AddressString;
 37import org.mobicents.protocols.ss7.map.api.primitives.NumberingPlan;
 38import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerTest;
 39
 40/**
 41 * 
 42 * @author amit bhayani
 43 * @author sergey vetyutnev
 44 * 
 45 */
 46public class MAPOpenInfoTest  {
 47
 48	private byte[] getDataFull() {
 49		return new byte[] { -96, 61, -128, 9, -106, 2, 36, -128, 3, 0, -128, 0, -14, -127, 7, -111, 19, 38, -104, -122, 3, -16, 48, 39, -96, 32, 48, 10, 6, 3,
 50				42, 3, 4, 11, 12, 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 };
 51	}
 52
 53	private byte[] getDataEri() {
 54		return new byte[] { -96, 35, -128, 6, 17, 33, 34, 17, 33, 34, -127, 7, -111, 19, 38, -104, -122, 3, -16, -126, 9, -106, 2, 36, -128, 3, 0, -128, 0,
 55				-14, -125, 5, -111, -128, 55, 33, -12 };
 56	}
 57	
 58	@Test(groups = { "functional.decode","dialog"})
 59	public void testDecode() throws Exception {
 60
 61		// The raw data is from packet 2 of nad1053.pcap
 62		byte[] data = new byte[] { (byte) 0xa0, (byte) 0x80, (byte) 0x80, 0x09, (byte) 0x96, 0x02, 0x24, (byte) 0x80,
 63				0x03, 0x00, (byte) 0x80, 0x00, (byte) 0xf2, (byte) 0x81, 0x07, (byte) 0x91, 0x13, 0x26, (byte) 0x98,
 64				(byte) 0x86, 0x03, (byte) 0xf0, 0x00, 0x00 };
 65
 66		AsnInputStream asnIs = new AsnInputStream(data);
 67
 68		int tag = asnIs.readTag();
 69		assertEquals( tag,0);
 70
 71		MAPOpenInfoImpl mapOpenInfoImpl = new MAPOpenInfoImpl();
 72		mapOpenInfoImpl.decodeAll(asnIs);
 73
 74		AddressString destRef = mapOpenInfoImpl.getDestReference();
 75		AddressString origRef = mapOpenInfoImpl.getOrigReference();
 76
 77		assertNotNull(destRef);
 78
 79		assertEquals( destRef.getAddressNature(),AddressNature.international_number);
 80		assertEquals( destRef.getNumberingPlan(),NumberingPlan.land_mobile);
 81		assertTrue(destRef.getAddress().endsWith("204208300008002"));
 82
 83		assertNotNull(origRef);
 84
 85		assertEquals( origRef.getAddressNature(),AddressNature.international_number);
 86		assertEquals( origRef.getNumberingPlan(),NumberingPlan.ISDN);
 87		assertTrue(origRef.getAddress().equals("31628968300"));
 88		assertFalse( mapOpenInfoImpl.getEriStyle());
 89
 90		
 91		asnIs = new AsnInputStream(this.getDataFull());
 92
 93		tag = asnIs.readTag();
 94		assertEquals( tag,0);
 95
 96		mapOpenInfoImpl = new MAPOpenInfoImpl();
 97		mapOpenInfoImpl.decodeAll(asnIs);
 98
 99		destRef = mapOpenInfoImpl.getDestReference();
100		origRef = mapOpenInfoImpl.getOrigReference();
101
102		assertNotNull(destRef);
103
104		assertEquals( destRef.getAddressNature(),AddressNature.international_number);
105		assertEquals(destRef.getNumberingPlan(), NumberingPlan.land_mobile);
106		assertTrue(destRef.getAddress().equals("204208300008002"));
107
108		assertNotNull(origRef);
109
110		assertEquals(origRef.getAddressNature(), AddressNature.international_number);
111		assertEquals(origRef.getNumberingPlan(), NumberingPlan.ISDN);
112		assertTrue(origRef.getAddress().equals("31628968300"));
113
114		assertTrue(MAPExtensionContainerTest.CheckTestExtensionContainer(mapOpenInfoImpl.getExtensionContainer()));
115		assertFalse( mapOpenInfoImpl.getEriStyle());
116
117		
118		asnIs = new AsnInputStream(this.getDataEri());
119		tag = asnIs.readTag();
120		assertEquals( tag,0);
121
122		mapOpenInfoImpl = new MAPOpenInfoImpl();
123		mapOpenInfoImpl.decodeAll(asnIs);
124
125		destRef = mapOpenInfoImpl.getDestReference();
126		origRef = mapOpenInfoImpl.getOrigReference();
127
128		assertNotNull(destRef);
129
130		assertEquals(destRef.getAddressNature(), AddressNature.international_number);
131		assertEquals(destRef.getNumberingPlan(), NumberingPlan.land_mobile);
132		assertTrue(destRef.getAddress().equals("204208300008002"));
133
134		assertNotNull(origRef);
135
136		assertEquals(origRef.getAddressNature(), AddressNature.international_number);
137		assertEquals(origRef.getNumberingPlan(), NumberingPlan.ISDN);
138		assertTrue(origRef.getAddress().equals("31628968300"));
139
140		assertNull(mapOpenInfoImpl.getExtensionContainer());
141		assertTrue( mapOpenInfoImpl.getEriStyle());
142		assertTrue( mapOpenInfoImpl.getEriImsi().getData().equals("111222111222"));
143
144		AddressString eriVlrNo = mapOpenInfoImpl.getEriVlrNo();
145		assertEquals(eriVlrNo.getAddressNature(), AddressNature.international_number);
146		assertEquals(eriVlrNo.getNumberingPlan(), NumberingPlan.ISDN);
147		assertTrue(eriVlrNo.getAddress().equals("0873124"));
148
149	}
150
151	@Test(groups = { "functional.encode","dialog"})
152	public void testEncode() throws Exception {
153
154		MAPParameterFactory servFact = new MAPParameterFactoryImpl();
155
156		MAPOpenInfoImpl mapOpenInfoImpl = new MAPOpenInfoImpl();
157		AddressString destReference = servFact.createAddressString(AddressNature.international_number,
158				NumberingPlan.land_mobile, "204208300008002");
159		mapOpenInfoImpl.setDestReference(destReference);
160		AddressString origReference = servFact.createAddressString(AddressNature.international_number,
161				NumberingPlan.ISDN, "31628968300");
162		mapOpenInfoImpl.setOrigReference(origReference);
163		AsnOutputStream asnOS = new AsnOutputStream();
164
165		mapOpenInfoImpl.encodeAll(asnOS);
166		byte[] data = asnOS.toByteArray();
167		// System.out.println(dump(data, data.length, false));
168		assertTrue(Arrays.equals(new byte[] { (byte) 0xa0, (byte) 0x14, (byte) 0x80, 0x09, (byte) 0x96, 0x02, 0x24,
169				(byte) 0x80, 0x03, 0x00, (byte) 0x80, 0x00, (byte) 0xf2, (byte) 0x81, 0x07, (byte) 0x91, 0x13, 0x26,
170				(byte) 0x98, (byte) 0x86, 0x03, (byte) 0xf0 }, data));
171
172		
173		mapOpenInfoImpl = new MAPOpenInfoImpl();
174		destReference = servFact.createAddressString(AddressNature.international_number, NumberingPlan.land_mobile, "204208300008002");
175		mapOpenInfoImpl.setDestReference(destReference);
176		origReference = servFact.createAddressString(AddressNature.international_number, NumberingPlan.ISDN, "31628968300");
177		mapOpenInfoImpl.setOrigReference(origReference);
178		mapOpenInfoImpl.setExtensionContainer(MAPExtensionContainerTest.GetTestExtensionContainer());
179
180		asnOS = new AsnOutputStream();
181		mapOpenInfoImpl.encodeAll(asnOS);
182		data = asnOS.toByteArray();
183		assertTrue(Arrays.equals(this.getDataFull(), data));
184		
185		// Eri
186		mapOpenInfoImpl = new MAPOpenInfoImpl();
187		destReference = servFact.createAddressString(AddressNature.international_number, NumberingPlan.land_mobile, "204208300008002");
188		mapOpenInfoImpl.setDestReference(destReference);
189		origReference = servFact.createAddressString(AddressNature.international_number, NumberingPlan.ISDN, "31628968300");
190		mapOpenInfoImpl.setOrigReference(origReference);
191		mapOpenInfoImpl.setExtensionContainer(MAPExtensionContainerTest.GetTestExtensionContainer());
192
193		mapOpenInfoImpl.setEriStyle(true);
194		mapOpenInfoImpl.setEriImsi(servFact.createIMSI("111222111222"));
195		mapOpenInfoImpl.setEriVlrNo(servFact.createAddressString(AddressNature.international_number, NumberingPlan.ISDN, "0873124"));
196
197		asnOS = new AsnOutputStream();
198		mapOpenInfoImpl.encodeAll(asnOS);
199		data = asnOS.toByteArray();
200		assertTrue(Arrays.equals(this.getDataEri(), data));
201	}
202}