PageRenderTime 23ms CodeModel.GetById 13ms 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/LocationNumberTest.java

http://mobicents.googlecode.com/
Java | 109 lines | 42 code | 15 blank | 52 comment | 1 complexity | 9de6edc27f39c31205587377d88fc964 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.LocationNumber;
 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 LocationNumberTest extends ParameterHarness {
 49
 50	/**
 51	 * @throws IOException
 52	 */
 53	public LocationNumberTest() throws IOException {
 54		super.badBodies.add(new byte[1]);
 55
 56//		super.goodBodies.add(getBody( false, LocationNumber._NAI_NATIONAL_SN, LocationNumberImpl._INN_ROUTING_ALLOWED, LocationNumberImpl._NPI_ISDN,
 57//				LocationNumberImpl._APRI_NOT_AVAILABLE, LocationNumberImpl._SI_NETWORK_PROVIDED, getSixDigits()));
 58		super.goodBodies.add(getBody( false, LocationNumber._NAI_NATIONAL_SN, LocationNumberImpl._INN_ROUTING_ALLOWED, LocationNumberImpl._NPI_ISDN,
 59				LocationNumberImpl._APRI_ALLOWED, LocationNumberImpl._SI_NETWORK_PROVIDED, getSixDigits()));
 60
 61	}
 62
 63	private byte[] getBody(boolean isODD, int _NAI, int _INN, int _NPI, int _APR, int _SI, byte[] digits) throws IOException {
 64		ByteArrayOutputStream bos = new ByteArrayOutputStream();
 65		// we will use odd number of digits, so we leave zero as MSB
 66
 67		int nai = _NAI;
 68		if (isODD)
 69			nai |= 0x01 << 7;
 70		int bit3 = _SI;
 71		bit3 |= _APR << 2;
 72		bit3 |= _NPI << 4;
 73		bit3 |= _INN << 7;
 74
 75
 76		bos.write(nai);
 77		bos.write(bit3);
 78		bos.write(digits);
 79		return bos.toByteArray();
 80	}
 81	@Test(groups = { "functional.encode","functional.decode","parameter"})
 82	public void testBody1EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
 83		LocationNumberImpl bci = new LocationNumberImpl(getBody( false, LocationNumber._NAI_NATIONAL_SN, LocationNumberImpl._INN_ROUTING_ALLOWED, LocationNumberImpl._NPI_ISDN,
 84				LocationNumberImpl._APRI_NOT_AVAILABLE, LocationNumberImpl._SI_NETWORK_PROVIDED, getSixDigits()));
 85
 86		String[] methodNames = { "isOddFlag", "getNatureOfAddressIndicator", "getInternalNetworkNumberIndicator", "getNumberingPlanIndicator", "getAddressRepresentationRestrictedIndicator",
 87				"getScreeningIndicator", "getAddress" };
 88		Object[] expectedValues = { false, LocationNumber._NAI_NATIONAL_SN, LocationNumberImpl._INN_ROUTING_ALLOWED, LocationNumberImpl._NPI_ISDN,
 89				LocationNumberImpl._APRI_NOT_AVAILABLE, LocationNumberImpl._SI_NETWORK_PROVIDED, getSixDigitsString() };
 90		super.testValues(bci, methodNames, expectedValues);
 91	}
 92
 93	/*
 94	 * (non-Javadoc)
 95	 * 
 96	 * @see
 97	 * org.mobicents.isup.messages.parameters.ParameterHarness#getTestedComponent
 98	 * ()
 99	 */
100	
101	public AbstractISUPParameter getTestedComponent() {
102//		return new LocationNumberImpl(1,"1",1,1,1,1);
103		return new LocationNumberImpl(LocationNumber._NAI_NATIONAL_SN, getSixDigitsString(), LocationNumberImpl._NPI_ISDN,
104				LocationNumberImpl._INN_ROUTING_ALLOWED, LocationNumberImpl._APRI_ALLOWED, LocationNumberImpl._SI_NETWORK_PROVIDED);
105//		public LocationNumberImpl(int natureOfAddresIndicator, String address, int numberingPlanIndicator, int internalNetworkNumberIndicator, int addressRepresentationREstrictedIndicator,
106//				int screeningIndicator) {
107	}
108
109}