001: /*
002: * Conditions Of Use
003: *
004: * This software was developed by employees of the National Institute of
005: * Standards and Technology (NIST), and others.
006: * This software is has been contributed to the public domain.
007: * As a result, a formal license is not needed to use the software.
008: *
009: * This software is provided "AS IS."
010: * NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
011: * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
012: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
013: * AND DATA ACCURACY. NIST does not warrant or make any representations
014: * regarding the use of the software or the results thereof, including but
015: * not limited to the correctness, accuracy, reliability or usefulness of
016: * the software.
017: *
018: *
019: */
020: /**
021: *
022: */package test.tck.msgflow.callflows.reinvite;
023:
024: import gov.nist.javax.sip.SipProviderImpl;
025:
026: import java.util.EventObject;
027: import java.util.Hashtable;
028: import java.util.Timer;
029: import java.util.TimerTask;
030:
031: import javax.sip.DialogTerminatedEvent;
032: import javax.sip.IOExceptionEvent;
033: import javax.sip.RequestEvent;
034: import javax.sip.ResponseEvent;
035: import javax.sip.SipListener;
036: import javax.sip.SipProvider;
037: import javax.sip.TimeoutEvent;
038: import javax.sip.TransactionTerminatedEvent;
039:
040: import org.apache.log4j.Appender;
041: import org.apache.log4j.ConsoleAppender;
042: import org.apache.log4j.FileAppender;
043: import org.apache.log4j.Logger;
044: import org.apache.log4j.PropertyConfigurator;
045: import org.apache.log4j.SimpleLayout;
046: import org.apache.log4j.helpers.NullEnumeration;
047:
048: import test.tck.msgflow.callflows.ProtocolObjects;
049: import test.tck.msgflow.callflows.ScenarioHarness;
050: import test.tck.TestHarness;
051:
052: import junit.framework.TestCase;
053:
054: /**
055: * @author M. Ranganathan
056: *
057: */
058: public class ReInviteTest extends ScenarioHarness implements
059: SipListener {
060:
061: protected Shootist shootist;
062:
063: private Shootme shootme;
064:
065: private static Logger logger = Logger.getLogger("test.tck");
066:
067: static {
068: if (!logger.isAttached(console))
069: logger.addAppender(console);
070: }
071:
072: private SipListener getSipListener(EventObject sipEvent) {
073: SipProvider source = (SipProvider) sipEvent.getSource();
074: SipListener listener = (SipListener) providerTable.get(source);
075: assertTrue(listener != null);
076: return listener;
077: }
078:
079: public ReInviteTest() {
080: super ("reinvitetest", true);
081: }
082:
083: public void setUp() {
084:
085: try {
086: this .transport = "udp";
087:
088: super .setUp();
089: shootist = new Shootist(riProtocolObjects);
090: SipProvider shootistProvider = shootist.createSipProvider();
091: providerTable.put(shootistProvider, shootist);
092:
093: shootme = new Shootme(tiProtocolObjects);
094: SipProvider shootmeProvider = shootme.createSipProvider();
095: providerTable.put(shootmeProvider, shootme);
096: shootistProvider.addSipListener(this );
097: shootmeProvider.addSipListener(this );
098:
099: riProtocolObjects.start();
100: if (tiProtocolObjects != riProtocolObjects)
101: tiProtocolObjects.start();
102: } catch (Exception ex) {
103: ex.printStackTrace();
104: fail("unexpected exception ");
105: }
106: }
107:
108: public void testSendInvite() {
109: this .shootist.sendInvite();
110: }
111:
112: public void tearDown() {
113: try {
114: Thread.sleep(2000);
115: this .shootist.checkState();
116: this .shootme.checkState();
117: tiProtocolObjects.destroy();
118: if (tiProtocolObjects != riProtocolObjects)
119: riProtocolObjects.destroy();
120: Thread.sleep(1000);
121: this .providerTable.clear();
122: logTestCompleted();
123: } catch (Exception ex) {
124: ex.printStackTrace();
125: }
126:
127: }
128:
129: public void processRequest(RequestEvent requestEvent) {
130: getSipListener(requestEvent).processRequest(requestEvent);
131:
132: }
133:
134: public void processResponse(ResponseEvent responseEvent) {
135: getSipListener(responseEvent).processResponse(responseEvent);
136:
137: }
138:
139: public void processTimeout(TimeoutEvent timeoutEvent) {
140: getSipListener(timeoutEvent).processTimeout(timeoutEvent);
141: }
142:
143: public void processIOException(IOExceptionEvent exceptionEvent) {
144: fail("unexpected exception");
145:
146: }
147:
148: public void processTransactionTerminated(
149: TransactionTerminatedEvent transactionTerminatedEvent) {
150: getSipListener(transactionTerminatedEvent)
151: .processTransactionTerminated(
152: transactionTerminatedEvent);
153:
154: }
155:
156: public void processDialogTerminated(
157: DialogTerminatedEvent dialogTerminatedEvent) {
158: getSipListener(dialogTerminatedEvent).processDialogTerminated(
159: dialogTerminatedEvent);
160:
161: }
162:
163: }
|