PageRenderTime 37ms CodeModel.GetById 24ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 116 lines | 58 code | 13 blank | 45 comment | 15 complexity | 0a97f81ce366b62b9a17e24fbeac2c94 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:40:20 2009-04-26<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;
 39import static org.testng.Assert.*;
 40import org.testng.*;
 41import org.testng.annotations.*;
 42/**
 43 * Start time:14:40:20 2009-04-26<br>
 44 * Project: mobicents-isup-stack<br>
 45 * 
 46 * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski
 47 *         </a>
 48 */
 49public class NetworkSpecificFacilityTest extends ParameterHarness {
 50
 51	public NetworkSpecificFacilityTest() {
 52		super(); // L1, ext bit,|| this byte
 53		// super.goodBodies.add(new byte[] { 1, (byte) 0x80, 11, 1, 2, 3, 4 });
 54	}
 55	@Test(groups = { "functional.encode","functional.decode","parameter"})
 56	public void testBody1EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
 57		NetworkSpecificFacilityImpl bci = new NetworkSpecificFacilityImpl(getBody(NetworkSpecificFacilityImpl._TNI_NNI, 1, new byte[] { 1, 2, 3, 4, 5, (byte) 0xAA }, new byte[10]));
 58
 59		String[] methodNames = { "isIncludeNetworkIdentification", "getLengthOfNetworkIdentification", "getTypeOfNetworkIdentification", "getNetworkIdentificationPlan" };
 60		Object[] expectedValues = { true, 6, NetworkSpecificFacilityImpl._TNI_NNI, 1 };
 61		super.testValues(bci, methodNames, expectedValues);
 62
 63		// now some custom part?
 64		byte[] body = bci.encode();
 65		
 66		for (int index = 2; index < 8; index++) {
 67			if (index == 7) {
 68				if (((body[index] >> 7) & 0x01) != 0) {
 69					fail("Last octet must have MSB set to zero to indicate last byte.");
 70				}
 71			} else {
 72				if (((body[index] >> 7) & 0x01) != 1) {
 73					fail("Last octet must have MSB set to one to indicate that there are more bytes.");
 74				}
 75			}
 76		}
 77	}
 78
 79	private byte[] getBody(int _TNI, int _NIP, byte[] ntwrkID, byte[] ntwrSpecificFacilityIndicator) throws IOException {
 80
 81		ByteArrayOutputStream bos = new ByteArrayOutputStream();
 82		int v = _NIP;
 83		v |= _TNI << 4;
 84		if (ntwrkID != null) {
 85			bos.write(ntwrkID.length);
 86			bos.write(v);
 87			for (int index = 0; index < ntwrkID.length; index++) {
 88				if (index == ntwrkID.length - 1) {
 89					ntwrkID[index] |= 0x01 << 7;
 90				} else {
 91					ntwrkID[index] &= 0x7F;
 92				}
 93			}
 94			bos.write(ntwrkID);
 95		} else {
 96			v |= 0x01 << 7;
 97			bos.write(v);
 98		}
 99
100		bos.write(ntwrSpecificFacilityIndicator);
101		return bos.toByteArray();
102	}
103
104	/*
105	 * (non-Javadoc)
106	 * 
107	 * @see
108	 * org.mobicents.isup.messages.parameters.ParameterHarness#getTestedComponent
109	 * ()
110	 */
111	
112	public AbstractISUPParameter getTestedComponent() throws ParameterException {
113		return new NetworkSpecificFacilityImpl(new byte[] { 1, (byte) 0xFF, 1, 2, 2 });
114	}
115
116}