PageRenderTime 262ms CodeModel.GetById 252ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 112 lines | 49 code | 16 blank | 47 comment | 0 complexity | 052fbb470805df683395cb652a0b5ccb 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.mobicents.protocols.ss7.isup.message.parameter.CalledINNumber;
 39import org.testng.annotations.Test;
 40
 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 CalledINNumberTest extends ParameterHarness {
 49
 50	/**
 51	 * @throws IOException
 52	 */
 53	public CalledINNumberTest() throws IOException {
 54		super.badBodies.add(new byte[1]);
 55		
 56
 57		super.goodBodies.add(getBody1());
 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
 65		bos.write(CalledINNumber._NAI_SUBSCRIBER_NUMBER);
 66		int v = CalledINNumberImpl._APRI_ALLOWED << 2;
 67		v |= CalledINNumberImpl._NPI_ISDN << 4;
 68		bos.write(v);
 69		bos.write(super.getSixDigits());
 70		return bos.toByteArray();
 71	}
 72
 73	private byte[] getBody2() throws IOException {
 74		ByteArrayOutputStream bos = new ByteArrayOutputStream();
 75
 76		bos.write(CalledINNumber._NAI_SUBSCRIBER_NUMBER | (0x01 << 7));
 77		int v = CalledINNumberImpl._APRI_ALLOWED << 2;
 78		v |= CalledINNumberImpl._NPI_ISDN << 4;
 79		bos.write(v);
 80		bos.write(super.getFiveDigits());
 81		return bos.toByteArray();
 82	}
 83	@Test(groups = { "functional.encode","functional.decode","parameter"})
 84	public void testBody1EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
 85		CalledINNumberImpl bci = new CalledINNumberImpl(getBody1());
 86	
 87		String[] methodNames = { "getNumberingPlanIndicator", "getAddressRepresentationRestrictedIndicator", "getNatureOfAddressIndicator", "isOddFlag", "getAddress" };
 88		Object[] expectedValues = { CalledINNumberImpl._NPI_ISDN, CalledINNumberImpl._APRI_ALLOWED, CalledINNumber._NAI_SUBSCRIBER_NUMBER, false, super.getSixDigitsString() };
 89		super.testValues(bci, methodNames, expectedValues);
 90	}
 91	@Test(groups = { "functional.encode","functional.decode","parameter"})
 92	public void testBody2EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
 93		CalledINNumberImpl bci = new CalledINNumberImpl(getBody2());
 94
 95		String[] methodNames = { "getNumberingPlanIndicator", "getAddressRepresentationRestrictedIndicator", "getNatureOfAddressIndicator", "isOddFlag", "getAddress" };
 96		Object[] expectedValues = { CalledINNumberImpl._NPI_ISDN, CalledINNumberImpl._APRI_ALLOWED, CalledINNumber._NAI_SUBSCRIBER_NUMBER, true, super.getFiveDigitsString() };
 97		super.testValues(bci, methodNames, expectedValues);
 98	}
 99
100	/*
101	 * (non-Javadoc)
102	 * 
103	 * @see
104	 * org.mobicents.isup.messages.parameters.ParameterHarness#getTestedComponent
105	 * ()
106	 */
107	
108	public AbstractISUPParameter getTestedComponent() {
109		return new CalledINNumberImpl(0, "1", 1, 1);
110	}
111
112}