/protocols/ss7/inap/inap-impl/src/test/java/org/mobicents/protocols/ss7/inap/primitives/LegIDTest.java
Java | 86 lines | 45 code | 15 blank | 26 comment | 0 complexity | 1ed46ef77bd0f07a8533a27fbcd14311 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.inap.primitives; 24 25import static org.testng.Assert.*; 26 27import java.util.Arrays; 28 29import org.mobicents.protocols.asn.AsnInputStream; 30import org.mobicents.protocols.asn.AsnOutputStream; 31import org.mobicents.protocols.ss7.inap.api.primitives.LegType; 32import org.testng.*;import org.testng.annotations.*; 33 34/** 35* 36* @author sergey vetyutnev 37* 38*/ 39public class LegIDTest { 40 41 private byte[] getData1() { 42 return new byte[] { (byte) 128, 1, 2 }; 43 } 44 45 private byte[] getData2() { 46 return new byte[] { (byte) 129, 1, 1 }; 47 } 48 49 @Test(groups = { "functional.decode","primitives"}) 50 public void testDecode() throws Exception { 51 52 byte[] data = this.getData1(); 53 AsnInputStream ais = new AsnInputStream(data); 54 LegIDImpl legId = new LegIDImpl(); 55 int tag = ais.readTag(); 56 legId.decodeAll(ais); 57 assertNotNull(legId.getSendingSideID()); 58 assertNull(legId.getReceivingSideID()); 59 assertEquals(legId.getSendingSideID(), LegType.leg2); 60 61 data = this.getData2(); 62 ais = new AsnInputStream(data); 63 legId = new LegIDImpl(); 64 tag = ais.readTag(); 65 legId.decodeAll(ais); 66 assertNull(legId.getSendingSideID()); 67 assertNotNull(legId.getReceivingSideID()); 68 assertEquals(legId.getReceivingSideID(), LegType.leg1); 69 70 } 71 72 @Test(groups = { "functional.encode","primitives"}) 73 public void testEncode() throws Exception { 74 75 LegIDImpl legId = new LegIDImpl(true, LegType.leg2); 76 AsnOutputStream aos = new AsnOutputStream(); 77 legId.encodeAll(aos); 78 assertTrue(Arrays.equals(aos.toByteArray(), this.getData1())); 79 80 legId = new LegIDImpl(false, LegType.leg1); 81 aos.reset(); 82 legId.encodeAll(aos); 83 assertTrue(Arrays.equals(aos.toByteArray(), this.getData2())); 84 85 } 86}