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

http://mobicents.googlecode.com/ · Java · 109 lines · 61 code · 27 blank · 21 comment · 1 complexity · 5f7c7dd40bc859aba34a4fc553f52a48 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.auditendpoint;
  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.AuditEndpoint;
  27. import jain.protocol.ip.mgcp.message.Constants;
  28. import jain.protocol.ip.mgcp.message.parms.EndpointIdentifier;
  29. import jain.protocol.ip.mgcp.message.parms.InfoCode;
  30. import org.apache.log4j.Logger;
  31. import org.mobicents.protocols.mgcp.stack.JainMgcpExtendedListener;
  32. import org.mobicents.protocols.mgcp.stack.JainMgcpStackProviderImpl;
  33. public class CA implements JainMgcpExtendedListener {
  34. private static Logger logger = Logger.getLogger(CA.class);
  35. private JainMgcpStackProviderImpl caProvider;
  36. private int mgStack = 0;
  37. private boolean responseReceived = false;
  38. public CA(JainMgcpStackProviderImpl caProvider, JainMgcpStackProviderImpl mgwProvider) {
  39. this.caProvider = caProvider;
  40. mgStack = mgwProvider.getJainMgcpStack().getPort();
  41. }
  42. public void sendAuditEndpoint() {
  43. try {
  44. caProvider.addJainMgcpListener(this);
  45. EndpointIdentifier endpointID = new EndpointIdentifier("media/trunk/Announcement/enp-1", "127.0.0.1:"
  46. + mgStack);
  47. AuditEndpoint auditEndpoint = new AuditEndpoint(this, endpointID, new InfoCode[]{InfoCode.Capabilities});
  48. auditEndpoint.setTransactionHandle(caProvider.getUniqueTransactionHandler());
  49. caProvider.sendMgcpEvents(new JainMgcpEvent[] { auditEndpoint });
  50. logger.debug(" AuditEndpoint command sent for TxId " + auditEndpoint.getTransactionHandle());
  51. } catch (Exception e) {
  52. e.printStackTrace();
  53. AuditEndpointTest.fail("Unexpected Exception");
  54. }
  55. }
  56. public void checkState() {
  57. AuditEndpointTest.assertTrue("Expect to receive AUEP Response", responseReceived);
  58. }
  59. public void transactionEnded(int handle) {
  60. logger.info("transactionEnded " + handle);
  61. }
  62. public void transactionRxTimedOut(JainMgcpCommandEvent command) {
  63. logger.info("transactionRxTimedOut " + command);
  64. }
  65. public void transactionTxTimedOut(JainMgcpCommandEvent command) {
  66. logger.info("transactionTxTimedOut " + command);
  67. }
  68. public void processMgcpCommandEvent(JainMgcpCommandEvent jainmgcpcommandevent) {
  69. logger.info("processMgcpCommandEvent " + jainmgcpcommandevent);
  70. }
  71. public void processMgcpResponseEvent(JainMgcpResponseEvent jainmgcpresponseevent) {
  72. logger.debug("processMgcpResponseEvent = " + jainmgcpresponseevent);
  73. switch (jainmgcpresponseevent.getObjectIdentifier()) {
  74. case Constants.RESP_AUDIT_ENDPOINT :
  75. responseReceived = true;
  76. break;
  77. default:
  78. logger.warn("This RESPONSE is unexpected " + jainmgcpresponseevent);
  79. break;
  80. }
  81. }
  82. }