PageRenderTime 18ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/ss7/map/map-impl/src/test/java/org/mobicents/protocols/ss7/map/service/sms/MWStatusTest.java

http://mobicents.googlecode.com/
Java | 108 lines | 58 code | 21 blank | 29 comment | 0 complexity | 656500ec1259614b21a3a8d1b281f8a4 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.sms;
 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.asn.Tag;
 38import org.testng.annotations.Test;
 39
 40/**
 41 * 
 42 * @author sergey vetyutnev
 43 *
 44 */
 45public class MWStatusTest  {
 46	
 47	private byte[] getEncodedData() {
 48		return new byte[] { 3, 2, 2, 64 };
 49	}
 50
 51	@Test(groups = { "functional.decode","service.sms"})
 52	public void testDecode() throws Exception {
 53		
 54		byte[] rawData = getEncodedData();
 55		AsnInputStream asn = new AsnInputStream(rawData);
 56
 57		int tag = asn.readTag();
 58		MWStatusImpl mws = new MWStatusImpl();
 59		mws.decodeAll(asn);
 60
 61		assertEquals( tag,Tag.STRING_BIT);
 62		assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
 63
 64		assertEquals( (boolean)mws.getMcefSet(),false);
 65		assertEquals( (boolean)mws.getMnrfSet(),true);
 66		assertEquals( (boolean)mws.getMnrgSet(),false);
 67		assertEquals( (boolean)mws.getScAddressNotIncluded(),false);
 68	}
 69
 70	@Test(groups = { "functional.encode","service.sms"})
 71	public void testEncode() throws Exception {
 72		
 73		MWStatusImpl mws = new MWStatusImpl(false, true, false, false);
 74		
 75		AsnOutputStream asnOS = new AsnOutputStream();
 76		mws.encodeAll(asnOS);
 77		
 78		byte[] encodedData = asnOS.toByteArray();
 79		byte[] rawData = getEncodedData();		
 80		assertTrue( Arrays.equals(rawData,encodedData));
 81		
 82	}
 83	
 84	@Test(groups = { "functional.serialize", "service.sms" })
 85	public void testSerialization() throws Exception {
 86		MWStatusImpl original = new MWStatusImpl(false, true, false, false);
 87		
 88		// serialize
 89		ByteArrayOutputStream out = new ByteArrayOutputStream();
 90		ObjectOutputStream oos = new ObjectOutputStream(out);
 91		oos.writeObject(original);
 92		oos.close();
 93
 94		// deserialize
 95		byte[] pickled = out.toByteArray();
 96		InputStream in = new ByteArrayInputStream(pickled);
 97		ObjectInputStream ois = new ObjectInputStream(in);
 98		Object o = ois.readObject();
 99		MWStatusImpl copy = (MWStatusImpl) o;
100		
101		//test result
102		assertEquals(copy.getMcefSet(), original.getMcefSet());
103		assertEquals(copy.getScAddressNotIncluded(), original.getScAddressNotIncluded());
104		assertEquals(copy.getMnrfSet(), original.getMnrfSet());
105		assertEquals(copy.getMnrgSet(), original.getMnrgSet());
106	}
107
108}