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

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

http://mobicents.googlecode.com/
Java | 121 lines | 55 code | 18 blank | 48 comment | 0 complexity | 1700b99ce54f48675fd6c2c491b8a740 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;
 36import java.util.Arrays;
 37
 38import org.mobicents.protocols.ss7.isup.ParameterException;
 39import org.testng.annotations.Test;
 40import static org.testng.Assert.*;
 41import org.testng.*;
 42import org.testng.annotations.*;
 43/**
 44 * Start time:14:11:03 2009-04-23<br>
 45 * Project: mobicents-isup-stack<br>
 46 * 
 47 * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski
 48 *         </a>
 49 */
 50public class RangeAndStatusTest extends ParameterHarness {
 51
 52	/**
 53	 * @throws IOException
 54	 */
 55	public RangeAndStatusTest() throws IOException {
 56		//super.badBodies.add(new byte[0]);
 57
 58	}
 59
 60	@Test(groups = { "functional.encode","functional.decode","parameter"})
 61	public void testBody1EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
 62		RangeAndStatusImpl bci = new RangeAndStatusImpl(getBody((byte)12,new byte[]{0x0F,0x04}));
 63		//not a best here. ech.
 64		String[] methodNames = { "getRange", 
 65								 "getStatus", 
 66								 };
 67		Object[] expectedValues = {(byte)12, 
 68									new byte[]{0x0F,0x04}};
 69		super.testValues(bci, methodNames, expectedValues);
 70	}
 71	@Test(groups = { "functional.flags","parameter"})
 72	public void testAffectedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
 73		RangeAndStatusImpl bci = new RangeAndStatusImpl(getBody((byte)12,new byte[]{0x0F,0x04}));
 74		assertEquals((byte)12, bci.getRange());
 75		
 76		assertTrue(bci.isAffected((byte) 0));
 77		assertTrue(bci.isAffected((byte) 1));
 78		assertTrue(bci.isAffected((byte) 2));
 79		assertTrue(bci.isAffected((byte) 3));
 80		
 81		assertTrue(!bci.isAffected((byte) 4));
 82		assertTrue(!bci.isAffected((byte) 5));
 83		assertTrue(!bci.isAffected((byte) 6));
 84		assertTrue(!bci.isAffected((byte) 7));
 85		
 86		assertTrue(!bci.isAffected((byte) 8));
 87		assertTrue(!bci.isAffected((byte) 9));
 88		assertTrue(bci.isAffected((byte) 10));
 89		
 90		bci.setAffected((byte)9, true);
 91		bci.setAffected((byte)10, false);
 92		
 93		assertTrue(!bci.isAffected((byte) 10));
 94		assertTrue(bci.isAffected((byte) 9));
 95		
 96		byte[] stat = bci.getStatus();
 97		assertTrue(Arrays.equals(new byte[]{0x0F,0x02}, stat));
 98	}
 99	
100	
101	
102	private byte[] getBody(byte rannge,byte[] enabled) throws IOException {
103		ByteArrayOutputStream bos = new ByteArrayOutputStream();
104		bos.write(rannge);
105		bos.write(enabled);
106		return bos.toByteArray();
107	}
108
109	/*
110	 * (non-Javadoc)
111	 * 
112	 * @see
113	 * org.mobicents.isup.messages.parameters.ParameterHarness#getTestedComponent
114	 * ()
115	 */
116	
117	public AbstractISUPParameter getTestedComponent() {
118		return new RangeAndStatusImpl();
119	}
120
121}