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