PageRenderTime 101ms CodeModel.GetById 94ms 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/ConnectedNumberTest.java

http://mobicents.googlecode.com/
Java | 121 lines | 55 code | 15 blank | 51 comment | 0 complexity | 751f6a18f64515d038acb5c8c3e59947 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.ConnectedNumber;
 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 ConnectedNumberTest extends ParameterHarness {
 49
 50	/**
 51	 * @throws IOException
 52	 */
 53	public ConnectedNumberTest() throws IOException {
 54		super.badBodies.add(new byte[1]);
 55
 56		super.goodBodies.add(getBody1());
 57		// This will fail, cause this body has APRI allowed, so hardcoded body
 58		// does nto match encoded body :)
 59		// super.goodBodies.add(getBody2());
 60	}
 61
 62	private byte[] getBody1() throws IOException {
 63		ByteArrayOutputStream bos = new ByteArrayOutputStream();
 64		// we will use odd number of digits, so we leave zero as MSB
 65		int v = ConnectedNumber._NAI_SUBSCRIBER_NUMBER;
 66		bos.write(v);
 67		v = 0;
 68		v = ConnectedNumberImpl._NPI_TELEX << 4;
 69		v |= ConnectedNumberImpl._APRI_NOT_AVAILABLE << 2;
 70		v |= ConnectedNumberImpl._SI_NETWORK_PROVIDED;
 71		bos.write(v & 0x7F);
 72
 73		bos.write(super.getSixDigits());
 74		return bos.toByteArray();
 75	}
 76
 77	private byte[] getBody2() throws IOException {
 78		ByteArrayOutputStream bos = new ByteArrayOutputStream();
 79
 80		// We have odd number
 81		int v = ConnectedNumber._NAI_SUBSCRIBER_NUMBER | (0x01 << 7);
 82		bos.write(v);
 83		v = 0;
 84		v = ConnectedNumberImpl._NPI_TELEX << 4;
 85		v |= ConnectedNumberImpl._APRI_ALLOWED << 2;
 86		v |= ConnectedNumberImpl._SI_NETWORK_PROVIDED;
 87		bos.write(v & 0x7F);
 88		bos.write(super.getFiveDigits());
 89		return bos.toByteArray();
 90	}
 91	@Test(groups = { "functional.encode","functional.decode","parameter"})
 92	public void testBody1EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
 93		ConnectedNumberImpl bci = new ConnectedNumberImpl(getBody1());
 94
 95		String[] methodNames = { "getNumberingPlanIndicator", "getAddressRepresentationRestrictedIndicator", "getNatureOfAddressIndicator", "getScreeningIndicator", "isOddFlag", "getAddress" };
 96		Object[] expectedValues = { ConnectedNumberImpl._NPI_TELEX, ConnectedNumberImpl._APRI_NOT_AVAILABLE, ConnectedNumber._NAI_SUBSCRIBER_NUMBER, ConnectedNumberImpl._SI_NETWORK_PROVIDED, false,
 97				super.getSixDigitsString() };
 98		super.testValues(bci, methodNames, expectedValues);
 99	}
100	@Test(groups = { "functional.encode","functional.decode","parameter"})
101	public void testBody2EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
102		ConnectedNumberImpl bci = new ConnectedNumberImpl(getBody2());
103		
104		String[] methodNames = { "getNumberingPlanIndicator", "getAddressRepresentationRestrictedIndicator", "getNatureOfAddressIndicator", "getScreeningIndicator", "isOddFlag", "getAddress" };
105		Object[] expectedValues = { ConnectedNumberImpl._NPI_TELEX, ConnectedNumberImpl._APRI_ALLOWED, ConnectedNumber._NAI_SUBSCRIBER_NUMBER, ConnectedNumberImpl._SI_NETWORK_PROVIDED, true, super.getFiveDigitsString() };
106		super.testValues(bci, methodNames, expectedValues);
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 ConnectedNumberImpl(1, "1", 1, 1, 1);
119	}
120
121}