PageRenderTime 27ms CodeModel.GetById 20ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/ss7/isup/isup-impl/src/test/java/org/mobicents/protocols/ss7/isup/impl/message/parameter/ConnectionRequestTest.java

http://mobicents.googlecode.com/
Java | 134 lines | 61 code | 17 blank | 56 comment | 0 complexity | f13f5b2bcf42bff6498cd01d19ac0d75 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
 23/**
 24 * Start time:14:11:03 2009-04-23<br>
 25 * Project: mobicents-isup-stack<br>
 26 * 
 27 * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski
 28 *         </a>
 29 * 
 30 */
 31package org.mobicents.protocols.ss7.isup.impl.message.parameter;
 32
 33import java.io.ByteArrayOutputStream;
 34import java.io.IOException;
 35import java.lang.reflect.InvocationTargetException;
 36
 37import org.mobicents.protocols.ss7.isup.ParameterException;
 38import org.testng.annotations.Test;
 39
 40/**
 41 * Start time:14:11:03 2009-04-23<br>
 42 * Project: mobicents-isup-stack<br>
 43 * 
 44 * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski
 45 *         </a>
 46 */
 47public class ConnectionRequestTest extends ParameterHarness {
 48
 49	/**
 50	 * @throws IOException
 51	 */
 52	public ConnectionRequestTest() throws IOException {
 53		super.badBodies.add(new byte[1]);
 54
 55		super.goodBodies.add(getBody1());
 56		// This will fail, cause this body has APRI allowed, so hardcoded body
 57		// does nto match encoded body :)
 58		// super.goodBodies.add(getBody2());
 59	}
 60
 61	private byte[] getBody1() throws IOException {
 62		ByteArrayOutputStream bos = new ByteArrayOutputStream();
 63		// we will use odd number of digits, so we leave zero as MSB
 64		//Local reference
 65		bos.write(12);
 66		bos.write(120);
 67		bos.write(38);
 68		
 69		//Signaling point code
 70		bos.write(120);
 71		bos.write(45);
 72		//protocol class
 73		bos.write(120);
 74		//credit
 75		bos.write(69);
 76		return bos.toByteArray();
 77	}
 78	
 79	private byte[] getBody2() throws IOException {
 80		ByteArrayOutputStream bos = new ByteArrayOutputStream();
 81
 82		//Local reference
 83		bos.write(12);
 84		bos.write(120);
 85		bos.write(38);
 86		
 87		//Signaling point code
 88		bos.write(120);
 89		bos.write(12);
 90		return bos.toByteArray();
 91	}
 92	@Test(groups = { "functional.encode","functional.decode","parameter"})
 93	public void testBody1EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
 94		ConnectionRequestImpl bci = new ConnectionRequestImpl(getBody1());
 95		int localRef = 12;
 96		localRef|=120<<8;
 97		localRef|=38<<16;
 98		int signalingPointCode = 120;
 99		signalingPointCode |= 45<<8;
100		
101		int protocolClass = 120;
102		int credit = 69;
103		String[] methodNames = { "getLocalReference","getSignalingPointCode","getProtocolClass","getCredit"};
104		Object[] expectedValues = { localRef,signalingPointCode,protocolClass,credit};
105		super.testValues(bci, methodNames, expectedValues);
106	}
107	@Test(groups = { "functional.encode","functional.decode","parameter"})
108	public void testBody2EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
109		ConnectionRequestImpl bci = new ConnectionRequestImpl(getBody2());
110
111		int localRef = 12;
112		localRef|=120<<8;
113		localRef|=38<<16;
114		int signalingPointCode = 120;
115		signalingPointCode |= 12<<8;
116		
117		String[] methodNames = { "getLocalReference","getSignalingPointCode"};
118		Object[] expectedValues = { localRef,signalingPointCode};
119		super.testValues(bci, methodNames, expectedValues);
120	}
121
122	/*
123	 * (non-Javadoc)
124	 * 
125	 * @see
126	 * org.mobicents.isup.messages.parameters.ParameterHarness#getTestedComponent
127	 * ()
128	 */
129	
130	public AbstractISUPParameter getTestedComponent() throws ParameterException {
131		return new ConnectionRequestImpl(new byte[5]);
132	}
133
134}