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

http://mobicents.googlecode.com/ · Java · 121 lines · 70 code · 27 blank · 24 comment · 1 complexity · b358dadc86ea718817c567c6fdd54f94 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.notify;
  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.Notify;
  28. import jain.protocol.ip.mgcp.message.parms.ConnectionIdentifier;
  29. import jain.protocol.ip.mgcp.message.parms.EndpointIdentifier;
  30. import jain.protocol.ip.mgcp.message.parms.EventName;
  31. import jain.protocol.ip.mgcp.message.parms.NotifiedEntity;
  32. import jain.protocol.ip.mgcp.pkg.MgcpEvent;
  33. import jain.protocol.ip.mgcp.pkg.PackageName;
  34. import org.apache.log4j.Logger;
  35. import org.mobicents.protocols.mgcp.stack.JainMgcpExtendedListener;
  36. import org.mobicents.protocols.mgcp.stack.JainMgcpStackProviderImpl;
  37. public class CA implements JainMgcpExtendedListener {
  38. private static Logger logger = Logger.getLogger(CA.class);
  39. private JainMgcpStackProviderImpl caProvider;
  40. private int mgStack = 0;
  41. private boolean responseReceived = false;
  42. public CA(JainMgcpStackProviderImpl caProvider, JainMgcpStackProviderImpl mgwProvider) {
  43. this.caProvider = caProvider;
  44. mgStack = mgwProvider.getJainMgcpStack().getPort();
  45. }
  46. public void sendNotify() {
  47. try {
  48. caProvider.addJainMgcpListener(this);
  49. EndpointIdentifier endpointID = new EndpointIdentifier("media/trunk/Announcement/enp-1", "127.0.0.1:"
  50. + mgStack);
  51. Notify notify = new Notify(this, endpointID, caProvider.getUniqueRequestIdentifier(),
  52. new EventName[] { new EventName(PackageName.Announcement, MgcpEvent.oc, new ConnectionIdentifier(
  53. "1")) });
  54. notify.setTransactionHandle(caProvider.getUniqueTransactionHandler());
  55. // TODO We are forced to set the NotifiedEntity, but this should
  56. // happen automatically. Fix this in MGCP Stack
  57. NotifiedEntity notifiedEntity = new NotifiedEntity("127.0.0.1", "127.0.0.1", mgStack);
  58. notify.setNotifiedEntity(notifiedEntity);
  59. caProvider.sendMgcpEvents(new JainMgcpEvent[] { notify });
  60. logger.debug(" Notify command sent for TxId " + notify.getTransactionHandle());
  61. } catch (Exception e) {
  62. // TODO Auto-generated catch block
  63. e.printStackTrace();
  64. NotifyTest.fail("Unexpected Exception");
  65. }
  66. }
  67. public void checkState() {
  68. NotifyTest.assertTrue("Expect to receive NTFY Response", responseReceived);
  69. }
  70. public void transactionEnded(int handle) {
  71. logger.info("transactionEnded " + handle);
  72. }
  73. public void transactionRxTimedOut(JainMgcpCommandEvent command) {
  74. logger.info("transactionRxTimedOut " + command);
  75. }
  76. public void transactionTxTimedOut(JainMgcpCommandEvent command) {
  77. logger.info("transactionTxTimedOut " + command);
  78. }
  79. public void processMgcpCommandEvent(JainMgcpCommandEvent jainmgcpcommandevent) {
  80. logger.info("processMgcpCommandEvent " + jainmgcpcommandevent);
  81. }
  82. public void processMgcpResponseEvent(JainMgcpResponseEvent jainmgcpresponseevent) {
  83. logger.debug("processMgcpResponseEvent = " + jainmgcpresponseevent);
  84. switch (jainmgcpresponseevent.getObjectIdentifier()) {
  85. case Constants.RESP_NOTIFY:
  86. responseReceived = true;
  87. break;
  88. default:
  89. logger.warn("This RESPONSE is unexpected " + jainmgcpresponseevent);
  90. responseReceived = false;
  91. break;
  92. }
  93. }
  94. }