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

/protocols/ss7/map/map-impl/src/test/java/org/mobicents/protocols/ss7/map/service/lsm/ResponseTimeTest.java

http://mobicents.googlecode.com/
Java | 117 lines | 66 code | 23 blank | 28 comment | 0 complexity | 3276290bfa1761620608ea22b2e9d624 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
 23package org.mobicents.protocols.ss7.map.service.lsm;
 24
 25import static org.testng.Assert.assertEquals;
 26import static org.testng.Assert.assertTrue;
 27
 28import java.io.ByteArrayInputStream;
 29import java.io.ByteArrayOutputStream;
 30import java.io.InputStream;
 31import java.io.ObjectInputStream;
 32import java.io.ObjectOutputStream;
 33import java.util.Arrays;
 34
 35import org.mobicents.protocols.asn.AsnInputStream;
 36import org.mobicents.protocols.asn.AsnOutputStream;
 37import org.mobicents.protocols.ss7.map.MAPParameterFactoryImpl;
 38import org.mobicents.protocols.ss7.map.api.MAPParameterFactory;
 39import org.mobicents.protocols.ss7.map.api.service.lsm.ResponseTimeCategory;
 40import org.testng.annotations.AfterClass;
 41import org.testng.annotations.AfterTest;
 42import org.testng.annotations.BeforeClass;
 43import org.testng.annotations.BeforeTest;
 44import org.testng.annotations.Test;
 45
 46/**
 47 * @author amit bhayani
 48 * 
 49 */
 50public class ResponseTimeTest {
 51	MAPParameterFactory MAPParameterFactory = new MAPParameterFactoryImpl();
 52
 53	@BeforeClass
 54	public static void setUpClass() throws Exception {
 55	}
 56
 57	@AfterClass
 58	public static void tearDownClass() throws Exception {
 59	}
 60
 61	@BeforeTest
 62	public void setUp() {
 63	}
 64
 65	@AfterTest
 66	public void tearDown() {
 67	}
 68
 69	@Test(groups = { "functional.decode","service.lsm"})
 70	public void testDecode() throws Exception {
 71		byte[] data = new byte[] { 0x30, 0x03, 0x0a, 0x01, 0x00 };
 72
 73		AsnInputStream asn = new AsnInputStream(data);
 74		int tag = asn.readTag();
 75
 76		ResponseTimeImpl responseTime = new ResponseTimeImpl();
 77		responseTime.decodeAll(asn);
 78
 79		assertEquals( responseTime.getResponseTimeCategory(),ResponseTimeCategory.lowdelay);
 80
 81	}
 82
 83	@Test(groups = { "functional.encode","service.lsm"})
 84	public void testEncode() throws Exception {
 85		byte[] data = new byte[] { 0x30, 0x03, 0x0a, 0x01, 0x00 };
 86
 87		ResponseTimeImpl responseTime = new ResponseTimeImpl(ResponseTimeCategory.lowdelay);
 88
 89		AsnOutputStream asnOS = new AsnOutputStream();
 90		responseTime.encodeAll(asnOS);
 91
 92		byte[] encodedData = asnOS.toByteArray();
 93
 94		assertTrue( Arrays.equals(data,encodedData));
 95	}
 96	
 97	@Test(groups = { "functional.serialize", "service.lsm" })
 98	public void testSerialization() throws Exception {
 99		ResponseTimeImpl original = new ResponseTimeImpl(ResponseTimeCategory.lowdelay);
100
101		// serialize
102		ByteArrayOutputStream out = new ByteArrayOutputStream();
103		ObjectOutputStream oos = new ObjectOutputStream(out);
104		oos.writeObject(original);
105		oos.close();
106
107		// deserialize
108		byte[] pickled = out.toByteArray();
109		InputStream in = new ByteArrayInputStream(pickled);
110		ObjectInputStream ois = new ObjectInputStream(in);
111		Object o = ois.readObject();
112		ResponseTimeImpl copy = (ResponseTimeImpl) o;
113		
114		//test result
115		assertEquals(copy, original);
116	}
117}