PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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

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