PageRenderTime 26ms CodeModel.GetById 19ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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