/protocols/jain-mgcp/stack/src/test/java/org/mobicents/protocols/mgcp/stack/test/deleteconnection/CA.java
Java | 119 lines | 70 code | 27 blank | 22 comment | 5 complexity | da798ed8f7c3378f0217af795bd843af 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 23package org.mobicents.protocols.mgcp.stack.test.deleteconnection; 24 25import jain.protocol.ip.mgcp.JainMgcpCommandEvent; 26import jain.protocol.ip.mgcp.JainMgcpEvent; 27import jain.protocol.ip.mgcp.JainMgcpResponseEvent; 28import jain.protocol.ip.mgcp.message.Constants; 29import jain.protocol.ip.mgcp.message.DeleteConnection; 30import jain.protocol.ip.mgcp.message.parms.ConnectionIdentifier; 31import jain.protocol.ip.mgcp.message.parms.EndpointIdentifier; 32import jain.protocol.ip.mgcp.message.parms.ReturnCode; 33 34import org.apache.log4j.Logger; 35import org.mobicents.protocols.mgcp.stack.JainMgcpExtendedListener; 36import org.mobicents.protocols.mgcp.stack.JainMgcpStackProviderImpl; 37 38public class CA implements JainMgcpExtendedListener { 39 40 private static Logger logger = Logger.getLogger(CA.class); 41 42 private JainMgcpStackProviderImpl caProvider; 43 private int mgStack = 0; 44 private boolean responseReceived = false; 45 46 public CA(JainMgcpStackProviderImpl caProvider, JainMgcpStackProviderImpl mgwProvider) { 47 this.caProvider = caProvider; 48 mgStack = mgwProvider.getJainMgcpStack().getPort(); 49 } 50 51 public void sendDeleteConnection() { 52 53 try { 54 caProvider.addJainMgcpListener(this); 55 56 EndpointIdentifier endpointID = new EndpointIdentifier("media/trunk/Announcement/enp14", "127.0.0.1:" 57 + mgStack); 58 59 ConnectionIdentifier connectionIdentifier = new ConnectionIdentifier((caProvider.getUniqueCallIdentifier()) 60 .toString()); 61 62 DeleteConnection deleteConnection = new DeleteConnection(this, endpointID); 63 deleteConnection.setConnectionIdentifier(connectionIdentifier); 64 deleteConnection.setTransactionHandle(caProvider.getUniqueTransactionHandler()); 65 66 caProvider.sendMgcpEvents(new JainMgcpEvent[] { deleteConnection }); 67 68 logger.debug(" DeleteConnection command sent for TxId " + deleteConnection.getTransactionHandle() 69 + " and ConnectionIdentifier " + connectionIdentifier); 70 } catch (Exception e) { 71 // TODO Auto-generated catch block 72 e.printStackTrace(); 73 DeleteConnectionTest.fail("Unexpected Exception"); 74 } 75 } 76 77 public void checkState() { 78 DeleteConnectionTest.assertTrue("Expect to receive DLCX Response", responseReceived); 79 80 } 81 82 public void transactionEnded(int handle) { 83 logger.info("transactionEnded " + handle); 84 85 } 86 87 public void transactionRxTimedOut(JainMgcpCommandEvent command) { 88 logger.info("transactionRxTimedOut " + command); 89 90 } 91 92 public void transactionTxTimedOut(JainMgcpCommandEvent command) { 93 logger.info("transactionTxTimedOut " + command); 94 95 } 96 97 public void processMgcpCommandEvent(JainMgcpCommandEvent jainmgcpcommandevent) { 98 logger.info("processMgcpCommandEvent " + jainmgcpcommandevent); 99 } 100 101 public void processMgcpResponseEvent(JainMgcpResponseEvent jainmgcpresponseevent) { 102 logger.debug("processMgcpResponseEvent = " + jainmgcpresponseevent); 103 switch (jainmgcpresponseevent.getObjectIdentifier()) { 104 case Constants.RESP_DELETE_CONNECTION: 105 if (jainmgcpresponseevent.getReturnCode().getValue() == ReturnCode.UNKNOWN_CALL_ID 106 || jainmgcpresponseevent.getReturnCode().getValue() == ReturnCode.TRANSACTION_EXECUTED_NORMALLY) { 107 responseReceived = true; 108 } 109 break; 110 default: 111 logger.warn("This RESPONSE is unexpected " + jainmgcpresponseevent); 112 DeleteConnectionTest.fail("Incorrect response for DLCX command "); 113 break; 114 115 } 116 117 } 118 119}