PageRenderTime 20ms CodeModel.GetById 2ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

/protocols/jain-mgcp/stack/src/test/java/org/mobicents/protocols/mgcp/stack/test/MessageHandlerTest.java

http://mobicents.googlecode.com/
Java | 89 lines | 50 code | 18 blank | 21 comment | 2 complexity | c0c9aad06a5d1830e1e87c3fb6d89013 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.mgcp.stack.test;
24
25import junit.framework.TestCase;
26
27import org.junit.After;
28import org.junit.AfterClass;
29import org.junit.Before;
30import org.junit.BeforeClass;
31import org.junit.Test;
32import org.mobicents.protocols.mgcp.parser.UtilsFactory;
33import org.mobicents.protocols.mgcp.stack.JainMgcpStackImpl;
34import org.mobicents.protocols.mgcp.stack.MessageHandler;
35
36public class MessageHandlerTest extends TestCase {
37	private MessageHandler handler = null;
38	private JainMgcpStackImpl stack = null;
39	private UtilsFactory factory = null;
40
41	@BeforeClass
42	public static void setUpClass() throws Exception {
43	}
44
45	@AfterClass
46	public static void tearDownClass() throws Exception {
47	}
48
49	@Before
50	public void setUp() throws Exception {
51		factory = new UtilsFactory(1);
52		stack = new JainMgcpStackImpl();
53		stack.setUtilsFactory(factory);
54		handler = new MessageHandler(stack);
55	}
56
57	@After
58	public void tearDown() {
59	}
60
61	@Test
62	public void testPiggyDismount() throws Exception {
63		String message = "200 2005 OK\n.\nDLCX 1244 card23/21@tgw-7.example.net MGCP 1.0\nC: A3C47F21456789F0\nI: FDE234C8\naakkkxxcd";
64		byte[] rawByte = message.getBytes();
65
66		String[] messages = handler.piggyDismount(rawByte, rawByte.length-9);
67		assertEquals("200 2005 OK\n", messages[0]);
68
69		boolean flag = messages[1].startsWith("DLCX") && messages[1].endsWith("FDE234C8\n");
70		assertTrue(flag);
71		
72		assertEquals("DLCX 1244 card23/21@tgw-7.example.net MGCP 1.0\nC: A3C47F21456789F0\nI: FDE234C8\n",messages[1] );
73 
74	}
75
76	@Test
77	public void testNoPiggyDismount() throws Exception {
78		String message = "DLCX 1244 card23/21@tgw-7.example.net MGCP 1.0\nC: A3C47F21456789F0\nI: FDE234C8\n";
79		byte[] rawByte = message.getBytes();
80
81		String[] messages = handler.piggyDismount(rawByte, rawByte.length);
82
83		assertEquals(1, messages.length);
84		boolean flag = messages[0].startsWith("DLCX") && messages[0].endsWith("FDE234C8\n");
85		assertTrue(flag);
86
87	}
88
89}