PageRenderTime 37ms CodeModel.GetById 11ms app.highlight 18ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 124 lines | 63 code | 23 blank | 38 comment | 12 complexity | a9c2f96e70214c7a694bf9605a2bbbaa 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:09:16:42 2009-04-22<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;
 32
 33import java.util.Arrays;
 34
 35import static org.testng.Assert.*;
 36import org.testng.*;
 37import org.testng.annotations.*;
 38
 39import org.mobicents.protocols.ss7.isup.ISUPMessageFactory;
 40import org.mobicents.protocols.ss7.isup.ISUPParameterFactory;
 41import org.mobicents.protocols.ss7.isup.impl.message.parameter.ISUPParameterFactoryImpl;
 42import org.mobicents.protocols.ss7.isup.message.ISUPMessage;
 43import org.mobicents.protocols.ss7.isup.message.parameter.CircuitIdentificationCode;
 44
 45/**
 46 * Start time:09:16:42 2009-04-22<br>
 47 * Project: mobicents-isup-stack<br>
 48 * 
 49 * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski </a>
 50 */
 51public abstract class MessageHarness {
 52	protected ISUPParameterFactory parameterFactory = new ISUPParameterFactoryImpl();
 53	protected ISUPMessageFactory messageFactory = new ISUPMessageFactoryImpl(parameterFactory);
 54
 55	// FIXME: add code to check values :)
 56	protected boolean makeCompare(byte[] b1, byte[] b2) {
 57		if (b1.length != b2.length)
 58			return false;
 59
 60		for (int index = 0; index < b1.length; index++) {
 61			if (b1[index] != b2[index])
 62				return false;
 63		}
 64
 65		return true;
 66
 67	}
 68
 69	protected String makeStringCompare(byte[] b1, byte[] b2) {
 70		int totalLength = 0;
 71		if (b1.length >= b2.length) {
 72			totalLength = b1.length;
 73		} else {
 74			totalLength = b2.length;
 75		}
 76
 77		String out = "";
 78
 79		for (int index = 0; index < totalLength; index++) {
 80			if (b1.length > index) {
 81				out += "b1[" + Integer.toHexString(b1[index]) + "]";
 82			} else {
 83				out += "b1[NOP]";
 84			}
 85
 86			if (b2.length > index) {
 87				out += "b2[" + Integer.toHexString(b2[index]) + "]";
 88			} else {
 89				out += "b2[NOP]";
 90			}
 91			out += "\n";
 92		}
 93
 94		return out;
 95	}
 96
 97	protected abstract byte[] getDefaultBody();
 98
 99	protected abstract ISUPMessage getDefaultMessage();
100
101	@Test(groups = { "functional.encode","functional.decode","message"})
102	public void testOne() throws Exception {
103
104		byte[] defaultBody = getDefaultBody();
105		// AddressCompleteMessageImpl acm=new
106		// AddressCompleteMessageImpl(this,message);
107		AbstractISUPMessage msg = (AbstractISUPMessage) getDefaultMessage();
108		msg.decode(defaultBody,parameterFactory);
109		byte[] encodedBody = msg.encode();
110		boolean equal = Arrays.equals(defaultBody, encodedBody);
111		assertTrue(equal,makeStringCompare(defaultBody, encodedBody));
112		CircuitIdentificationCode cic = msg.getCircuitIdentificationCode();
113		assertNotNull(cic,"CircuitIdentificationCode must not be null");
114		assertEquals( getDefaultCIC(),cic.getCIC(),"CircuitIdentificationCode value does not match");
115
116	}
117
118	protected long getDefaultCIC() {
119		return 0xB0C;
120	}
121
122
123
124}