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

http://mobicents.googlecode.com/ · Java · 125 lines · 71 code · 32 blank · 22 comment · 1 complexity · 1c350060ef165256abb0ba03ea85f395 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.restartinprogress;
  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.RestartInProgress;
  28. import jain.protocol.ip.mgcp.message.RestartInProgressResponse;
  29. import jain.protocol.ip.mgcp.message.parms.EndpointIdentifier;
  30. import jain.protocol.ip.mgcp.message.parms.NotifiedEntity;
  31. import jain.protocol.ip.mgcp.message.parms.RestartMethod;
  32. import jain.protocol.ip.mgcp.message.parms.ReturnCode;
  33. import java.util.TooManyListenersException;
  34. import org.apache.log4j.Logger;
  35. import org.mobicents.protocols.mgcp.stack.JainMgcpExtendedListener;
  36. import org.mobicents.protocols.mgcp.stack.JainMgcpStackProviderImpl;
  37. import org.mobicents.protocols.mgcp.stack.test.auditendpoint.AuditEndpointTest;
  38. public class CA implements JainMgcpExtendedListener {
  39. private static Logger logger = Logger.getLogger(CA.class);
  40. private JainMgcpStackProviderImpl caProvider;
  41. private boolean responseSent = false;
  42. public CA(JainMgcpStackProviderImpl caProvider, JainMgcpStackProviderImpl mgwProvider) {
  43. this.caProvider = caProvider;
  44. try {
  45. this.caProvider.addJainMgcpListener(this);
  46. } catch (TooManyListenersException e) {
  47. e.printStackTrace();
  48. AuditEndpointTest.fail("Unexpected Exception");
  49. }
  50. }
  51. public void checkState() {
  52. AuditEndpointTest.assertTrue("Expect to send RSIP Response", responseSent);
  53. }
  54. public void transactionEnded(int handle) {
  55. logger.info("transactionEnded " + handle);
  56. }
  57. public void transactionRxTimedOut(JainMgcpCommandEvent command) {
  58. logger.info("transactionRxTimedOut " + command);
  59. }
  60. public void transactionTxTimedOut(JainMgcpCommandEvent command) {
  61. logger.info("transactionTxTimedOut " + command);
  62. }
  63. public void processMgcpCommandEvent(JainMgcpCommandEvent jainmgcpcommandevent) {
  64. logger.info("processMgcpCommandEvent " + jainmgcpcommandevent);
  65. switch (jainmgcpcommandevent.getObjectIdentifier()) {
  66. case Constants.CMD_RESTART_IN_PROGRESS:
  67. RestartInProgress restartInProgress = (RestartInProgress) jainmgcpcommandevent;
  68. EndpointIdentifier endpointIdentifier = restartInProgress.getEndpointIdentifier();
  69. RestartInProgressTest.assertNotNull(endpointIdentifier);
  70. RestartInProgressTest.assertEquals("media/trunk/Announcement/enp-1@127.0.0.1:"
  71. + this.caProvider.getJainMgcpStack().getPort(), endpointIdentifier.toString());
  72. RestartMethod restartMethod = restartInProgress.getRestartMethod();
  73. RestartInProgressTest.assertNotNull(restartMethod);
  74. RestartInProgressTest.assertEquals(RestartMethod.GRACEFUL, restartMethod.getRestartMethod());
  75. RestartInProgressTest.assertEquals(0, restartInProgress.getRestartDelay());
  76. RestartInProgressTest.assertNull(restartInProgress.getReasonCode());
  77. RestartInProgressResponse response = new RestartInProgressResponse(jainmgcpcommandevent.getSource(),
  78. ReturnCode.Transaction_Executed_Normally);
  79. NotifiedEntity notifiedEntity = new NotifiedEntity("127.0.0.1");
  80. response.setNotifiedEntity(notifiedEntity);
  81. response.setTransactionHandle(jainmgcpcommandevent.getTransactionHandle());
  82. caProvider.sendMgcpEvents(new JainMgcpEvent[] { response });
  83. responseSent = true;
  84. break;
  85. default:
  86. logger.warn("This REQUEST is unexpected " + jainmgcpcommandevent);
  87. break;
  88. }
  89. }
  90. public void processMgcpResponseEvent(JainMgcpResponseEvent jainmgcpresponseevent) {
  91. // logger.debug("processMgcpResponseEvent = " + jainmgcpresponseevent);
  92. }
  93. }