PageRenderTime 33ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 109 lines | 61 code | 27 blank | 21 comment | 1 complexity | abdb415abb24f02d11c097b788e1ec8a MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  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.endpointconfiguration;
  23. import jain.protocol.ip.mgcp.JainMgcpCommandEvent;
  24. import jain.protocol.ip.mgcp.JainMgcpEvent;
  25. import jain.protocol.ip.mgcp.JainMgcpResponseEvent;
  26. import jain.protocol.ip.mgcp.message.Constants;
  27. import jain.protocol.ip.mgcp.message.EndpointConfiguration;
  28. import jain.protocol.ip.mgcp.message.EndpointConfigurationResponse;
  29. import jain.protocol.ip.mgcp.message.parms.BearerInformation;
  30. import jain.protocol.ip.mgcp.message.parms.ReturnCode;
  31. import java.util.TooManyListenersException;
  32. import org.apache.log4j.Logger;
  33. import org.mobicents.protocols.mgcp.stack.JainMgcpExtendedListener;
  34. import org.mobicents.protocols.mgcp.stack.JainMgcpStackProviderImpl;
  35. public class MGW implements JainMgcpExtendedListener {
  36. private static Logger logger = Logger.getLogger(MGW.class);
  37. private boolean responseSent = false;
  38. JainMgcpStackProviderImpl mgwProvider;
  39. public MGW(JainMgcpStackProviderImpl mgwProvider) {
  40. this.mgwProvider = mgwProvider;
  41. try {
  42. this.mgwProvider.addJainMgcpListener(this);
  43. } catch (TooManyListenersException e) {
  44. e.printStackTrace();
  45. EndpointConfigurationTest.fail("Unexpected Exception");
  46. }
  47. }
  48. public void checkState() {
  49. EndpointConfigurationTest.assertTrue("Expect to sent CRCX Response", responseSent);
  50. }
  51. public void transactionEnded(int handle) {
  52. logger.info("transactionEnded " + handle);
  53. }
  54. public void transactionRxTimedOut(JainMgcpCommandEvent command) {
  55. logger.info("transactionRxTimedOut " + command);
  56. }
  57. public void transactionTxTimedOut(JainMgcpCommandEvent command) {
  58. logger.info("transactionTxTimedOut " + command);
  59. EndpointConfigurationTest.fail("Transaction Timed Out while sending the EPCF Response");
  60. }
  61. public void processMgcpCommandEvent(JainMgcpCommandEvent jainmgcpcommandevent) {
  62. logger.info("processMgcpCommandEvent " + jainmgcpcommandevent);
  63. switch (jainmgcpcommandevent.getObjectIdentifier()) {
  64. case Constants.CMD_ENDPOINT_CONFIGURATION:
  65. EndpointConfiguration endpointConfiguration = (EndpointConfiguration) jainmgcpcommandevent;
  66. BearerInformation b = endpointConfiguration.getBearerInformation();
  67. EndpointConfigurationTest.assertEquals(BearerInformation.ENC_METHOD_A_LAW, b.getEncodingMethod());
  68. EndpointConfigurationResponse response = new EndpointConfigurationResponse(
  69. jainmgcpcommandevent.getSource(), ReturnCode.Transaction_Executed_Normally);
  70. response.setTransactionHandle(jainmgcpcommandevent.getTransactionHandle());
  71. mgwProvider.sendMgcpEvents(new JainMgcpEvent[] { response });
  72. responseSent = true;
  73. break;
  74. default:
  75. logger.warn("This REQUEST is unexpected " + jainmgcpcommandevent);
  76. break;
  77. }
  78. }
  79. public void processMgcpResponseEvent(JainMgcpResponseEvent jainmgcpresponseevent) {
  80. logger.info("processMgcpResponseEvent " + jainmgcpresponseevent);
  81. }
  82. }