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

/protocols/ss7/mtp/mtp-api/src/test/java/org/mobicents/protocols/ss7/mtp/Mtp3TransferMessageTest.java

http://mobicents.googlecode.com/
Java | 79 lines | 31 code | 16 blank | 32 comment | 0 complexity | 37d388e4f89db434afe28d81b406d32b 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.mtp;
24
25import static org.testng.Assert.assertEquals;
26import static org.testng.Assert.assertTrue;
27
28import java.util.Arrays;
29
30import org.testng.*;import org.testng.annotations.*;
31
32/**
33 * @author sergey vetyutnev
34 * 
35 */
36public class Mtp3TransferMessageTest {
37
38	private byte[] getMsg() {
39		return new byte[] { (byte) 0x83, (byte) 232, 3, (byte) 244, (byte) 161, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
40	}
41
42	private byte[] getData() {
43		return new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
44	}
45	
46	// si = 3 (SCCP)
47	// ni = 2
48	// mp = 0
49	// sio = (si + (ni << 6) + (mt << 4))
50	// dpc = 1000
51	// opc = 2000
52	// sls = 10
53	
54	
55	@Test(groups = { "Mtp3TransferMessageTest", "decode" })
56	public void testDecode() throws Exception {
57		Mtp3TransferPrimitive msg = new Mtp3TransferPrimitive();
58		msg.decodeMtp3(this.getMsg());
59		
60		assertEquals(msg.getSi(), 3);
61		assertEquals(msg.getNi(), 2);
62		assertEquals(msg.getMp(), 0);
63		assertEquals(msg.getDpc(), 1000);
64		assertEquals(msg.getOpc(), 2000);
65		assertEquals(msg.getSls(), 10);
66		assertTrue(Arrays.equals(msg.getData(), this.getData()));
67	
68	}
69	
70	@Test(groups = { "Mtp3TransferMessageTest", "encode" })
71	public void testEncode() throws Exception {
72		Mtp3TransferPrimitive msg = new Mtp3TransferPrimitive(3, 2, 0, 2000, 1000, 10, this.getData());
73		
74		byte[] res = msg.encodeMtp3();
75		
76		assertTrue(Arrays.equals(res, this.getMsg()));
77	
78	}
79}