PageRenderTime 22ms CodeModel.GetById 10ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

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

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