PageRenderTime 37ms CodeModel.GetById 10ms app.highlight 21ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 113 lines | 54 code | 31 blank | 28 comment | 0 complexity | 121729b8e5a961a83ea84f822e0bf08d 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.*;import org.testng.annotations.*;
 30
 31import org.mobicents.protocols.asn.AsnInputStream;
 32import org.mobicents.protocols.asn.AsnOutputStream;
 33import org.mobicents.protocols.ss7.map.api.dialog.MAPProviderAbortReason;
 34import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerTest;
 35
 36/**
 37 * 
 38 * @author amit bhayani
 39 *
 40 */
 41public class MAPProviderAbortInfoTest  {
 42	
 43	private byte[] getDataFull() {
 44		return new byte[] { -91, 44, 10, 1, 1, 48, 39, -96, 32, 48, 10, 6, 3, 42, 3, 4, 11, 12, 13, 14, 15, 48, 5, 6, 3, 42, 3, 6, 48, 11, 6, 3, 42, 3, 5, 21,
 45				22, 23, 24, 25, 26, -95, 3, 31, 32, 33 };
 46	}
 47
 48	@Test(groups = { "functional.decode","dialog"})
 49	public void testDecode() throws Exception {
 50		// The raw data is from last packet of long ussd-abort from msc2.txt
 51		byte[] data = new byte[] { (byte) 0xA5, 0x03, (byte) 0x0A, 0x01, 0x00 };
 52
 53		AsnInputStream asnIs = new AsnInputStream(data);
 54		int tag = asnIs.readTag();
 55		assertEquals( tag,5);
 56
 57		MAPProviderAbortInfoImpl mapProviderAbortInfo = new MAPProviderAbortInfoImpl();
 58		mapProviderAbortInfo.decodeAll(asnIs);
 59
 60		MAPProviderAbortReason reason = mapProviderAbortInfo
 61				.getMAPProviderAbortReason();
 62
 63		assertNotNull(reason);
 64
 65		assertEquals( reason,MAPProviderAbortReason.abnormalDialogue);
 66
 67		
 68		data = this.getDataFull();
 69		asnIs = new AsnInputStream(data);
 70		tag = asnIs.readTag();
 71		assertEquals( tag,5);
 72
 73		mapProviderAbortInfo = new MAPProviderAbortInfoImpl();
 74		mapProviderAbortInfo.decodeAll(asnIs);
 75		reason = mapProviderAbortInfo.getMAPProviderAbortReason();
 76
 77		assertNotNull(reason);
 78		assertEquals( reason,MAPProviderAbortReason.invalidPDU);
 79		assertTrue(MAPExtensionContainerTest.CheckTestExtensionContainer(mapProviderAbortInfo.getExtensionContainer()));
 80	
 81	}
 82
 83	@Test(groups = { "functional.encode","dialog"})
 84	public void testEncode() throws Exception {
 85
 86		MAPProviderAbortInfoImpl mapProviderAbortInfo = new MAPProviderAbortInfoImpl();
 87		mapProviderAbortInfo.setMAPProviderAbortReason(MAPProviderAbortReason.invalidPDU);
 88
 89		AsnOutputStream asnOS = new AsnOutputStream();
 90
 91		mapProviderAbortInfo.encodeAll(asnOS);
 92
 93		byte[] data = asnOS.toByteArray();
 94
 95		// System.out.println(dump(data, data.length, false));
 96
 97		assertTrue(Arrays.equals(new byte[] { (byte) 0xA5, 0x03, (byte) 0x0A,
 98				0x01, 0x01 }, data));
 99		
100
101		mapProviderAbortInfo = new MAPProviderAbortInfoImpl();
102		mapProviderAbortInfo.setMAPProviderAbortReason(MAPProviderAbortReason.invalidPDU);
103		mapProviderAbortInfo.setExtensionContainer(MAPExtensionContainerTest.GetTestExtensionContainer());
104
105		asnOS = new AsnOutputStream();
106		mapProviderAbortInfo.encodeAll(asnOS);
107
108		data = asnOS.toByteArray();
109		assertTrue(Arrays.equals(this.getDataFull(), data));
110		
111	}
112
113}