PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 144 lines | 76 code | 21 blank | 47 comment | 0 complexity | 200d6b045c03010f8f74cf03f6a0479b 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.IOException;
 34import java.lang.reflect.InvocationTargetException;
 35
 36import org.mobicents.protocols.ss7.isup.ParameterException;
 37import org.testng.annotations.Test;
 38import static org.testng.Assert.*;
 39import org.testng.*;
 40import org.testng.annotations.*;
 41/**
 42 * Start time:14:11:03 2009-04-23<br>
 43 * Project: mobicents-isup-stack<br>
 44 * 
 45 * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski
 46 *         </a>
 47 */
 48public class CircuitAssigmentMapTest extends ParameterHarness {
 49
 50	/**
 51	 * @throws IOException
 52	 */
 53	public CircuitAssigmentMapTest() throws IOException {
 54		super.badBodies.add(new byte[1]);
 55		super.badBodies.add(new byte[6]);
 56
 57		super.goodBodies.add(getBody1());
 58		
 59	}
 60
 61	private byte[] getBody1() throws IOException {
 62		
 63		// we will use odd number of digits, so we leave zero as MSB
 64		byte[] body = new byte[5];
 65		body[0]=12;
 66		body[1]=120;
 67		body[2]=67;
 68		return body;
 69	}
 70	@Test(groups = { "functional.encode","functional.decode","parameter"})
 71	public void testBody1EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
 72		CircuitAssigmentMapImpl bci = new CircuitAssigmentMapImpl(getBody1());
 73	
 74		int format = 120;
 75	
 76		format |= 67 << 8;
 77		format |= 0 << 16;
 78		format |= 0 << 24;
 79		String[] methodNames = { "getMapType","getMapFormat"};
 80		Object[] expectedValues = { 12, format};
 81		super.testValues(bci, methodNames, expectedValues);
 82	}
 83	@Test(groups = { "functional.flags","parameter"})
 84	public void testBoundries() throws IOException, ParameterException
 85	{
 86		CircuitAssigmentMapImpl bci = new CircuitAssigmentMapImpl(getBody1());
 87		
 88		try{
 89			bci.disableCircuit(0);
 90			fail("Failed, disabled circuit 0");
 91		}catch(IllegalArgumentException e)
 92		{
 93			
 94		}
 95		try{
 96			bci.disableCircuit(32);
 97			fail("Failed, disabled circuit 32");
 98		}catch(IllegalArgumentException e)
 99		{
100			
101		}
102		
103		try{
104			bci.enableCircuit(0);
105			fail("Enabled, disabled circuit 0");
106		}catch(IllegalArgumentException e)
107		{
108			
109		}
110		try{
111			bci.enableCircuit(32);
112			fail("Enabled, disabled circuit 32");
113		}catch(IllegalArgumentException e)
114		{
115			
116		}
117	}
118	@Test(groups = { "functional.flags","parameter"})
119	public void testEnableDissable() throws IOException, ParameterException
120	{
121		CircuitAssigmentMapImpl bci = new CircuitAssigmentMapImpl(getBody1());
122		
123		assertFalse(bci.isCircuitEnabled(30),"Circuit was enabled, it should not.");
124		bci.enableCircuit(30);
125		assertTrue(bci.isCircuitEnabled(30),"Circuit was not enabled, it should not.");
126		bci.disableCircuit(30);
127		assertFalse(bci.isCircuitEnabled(30),"Circuit was not disabled, it should not.");
128		super.makeCompare(getBody1(), bci.encode());
129		
130	}
131	
132	/*
133	 * (non-Javadoc)
134	 * 
135	 * @see
136	 * org.mobicents.isup.messages.parameters.ParameterHarness#getTestedComponent
137	 * ()
138	 */
139	
140	public AbstractISUPParameter getTestedComponent() throws ParameterException {
141		return new CircuitAssigmentMapImpl(new byte[5]);
142	}
143
144}