PageRenderTime 21ms CodeModel.GetById 10ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://mobicents.googlecode.com/
Java | 110 lines | 43 code | 18 blank | 49 comment | 1 complexity | 9d50caa6ea95839f7c56959f3ba82449 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 NetworkRoutingNumberTest extends ParameterHarness {
 48
 49	/**
 50	 * @throws IOException
 51	 */
 52	public NetworkRoutingNumberTest() throws IOException {
 53		super.badBodies.add(new byte[1]);
 54
 55		super.goodBodies.add(getBody(false,getSixDigits(), NetworkRoutingNumberImpl._NPI_ISDN_NP, NetworkRoutingNumberImpl._NAI_NRNI_NETWORK_SNF));
 56		super.goodBodies.add(getBody(true,getFiveDigits(), NetworkRoutingNumberImpl._NPI_ISDN_NP, NetworkRoutingNumberImpl._NAI_NRNI_NETWORK_SNF));
 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
 63	@Test(groups = { "functional.encode","functional.decode","parameter"})
 64	public void testBody1EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
 65		NetworkRoutingNumberImpl bci = new NetworkRoutingNumberImpl(getBody(false,getSixDigits(), NetworkRoutingNumberImpl._NPI_ISDN_NP, NetworkRoutingNumberImpl._NAI_NRNI_NETWORK_SNF));
 66
 67		String[] methodNames = { "isOddFlag", "getNumberingPlanIndicator", "getNatureOfAddressIndicator",  "getAddress" };
 68		Object[] expectedValues = { false, NetworkRoutingNumberImpl._NPI_ISDN_NP, NetworkRoutingNumberImpl._NAI_NRNI_NETWORK_SNF,getSixDigitsString() };
 69		super.testValues(bci, methodNames, expectedValues);
 70	}
 71	@Test(groups = { "functional.encode","functional.decode","parameter"})
 72	public void testBody2EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
 73		NetworkRoutingNumberImpl bci = new NetworkRoutingNumberImpl(getBody(true,getFiveDigits(), NetworkRoutingNumberImpl._NPI_ISDN_NP, NetworkRoutingNumberImpl._NAI_NRNI_NETWORK_SNF));
 74
 75		String[] methodNames = { "isOddFlag", "getNumberingPlanIndicator", "getNatureOfAddressIndicator",  "getAddress" };
 76		Object[] expectedValues = { true, NetworkRoutingNumberImpl._NPI_ISDN_NP, NetworkRoutingNumberImpl._NAI_NRNI_NETWORK_SNF,getFiveDigitsString() };
 77		super.testValues(bci, methodNames, expectedValues);
 78	}
 79
 80	private byte[] getBody(boolean isODD, byte[] digits, int npiIsdnNp, int naiNrniNetworkSnf) throws IOException {
 81		int b = 0;
 82		if(isODD)
 83		{
 84			b|=0x01<<7;
 85		}
 86		b|=npiIsdnNp<<4;
 87		b|=naiNrniNetworkSnf;
 88		ByteArrayOutputStream bos = new ByteArrayOutputStream();
 89		bos.write(b);
 90		bos.write(digits);
 91		return bos.toByteArray();
 92	}
 93
 94
 95
 96	
 97
 98	/*
 99	 * (non-Javadoc)
100	 * 
101	 * @see
102	 * org.mobicents.isup.messages.parameters.ParameterHarness#getTestedComponent
103	 * ()
104	 */
105	
106	public AbstractISUPParameter getTestedComponent() {
107		return new NetworkRoutingNumberImpl("1", 1, 1);
108	}
109
110}