001: package test.tck.msgflow.callflows;
002:
003: import java.util.EventObject;
004: import java.util.Hashtable;
005:
006: import javax.sip.DialogTerminatedEvent;
007: import javax.sip.IOExceptionEvent;
008: import javax.sip.RequestEvent;
009: import javax.sip.ResponseEvent;
010: import javax.sip.SipListener;
011: import javax.sip.SipProvider;
012: import javax.sip.TimeoutEvent;
013: import javax.sip.TransactionTerminatedEvent;
014:
015: import test.tck.TckInternalError;
016: import test.tck.TestHarness;
017: import test.tck.TiUnexpectedError;
018:
019: public abstract class ScenarioHarness extends TestHarness {
020: protected test.tck.msgflow.callflows.ProtocolObjects tiProtocolObjects;
021:
022: protected ProtocolObjects riProtocolObjects;
023:
024: protected String transport;
025:
026: protected Hashtable providerTable;
027:
028: // this flag determines whether the tested SIP Stack is shootist or shootme
029: protected boolean testedImplFlag;
030:
031: public void setUp() throws Exception {
032: if (testedImplFlag) {
033: this .tiProtocolObjects = new ProtocolObjects("ti"
034: + super .getName(), "gov.nist", transport, true);
035:
036: this .riProtocolObjects = new ProtocolObjects("ri"
037: + super .getName(), super .getImplementationPath(),
038: transport, true);
039: /*
040: * if (!getImplementationPath().equals("gov.nist"))
041: * this.riProtocolObjects = new ProtocolObjects( super.getName(),
042: * super.getImplementationPath(), transport, true); else
043: * this.riProtocolObjects = tiProtocolObjects;
044: */
045:
046: } else {
047: this .tiProtocolObjects = new ProtocolObjects("ti"
048: + super .getName(), getImplementationPath(),
049: transport, true);
050: this .riProtocolObjects = new ProtocolObjects("ri"
051: + super .getName(), "gov.nist", transport, true);
052:
053: /*
054: * if (!getImplementationPath().equals("gov.nist"))
055: * this.riProtocolObjects = new ProtocolObjects( super.getName(),
056: * super.getImplementationPath(), transport, true); else
057: * this.riProtocolObjects = tiProtocolObjects;
058: */
059:
060: }
061: }
062:
063: public void setUp(boolean riAutoDialog) throws Exception {
064: if (testedImplFlag) {
065: this .tiProtocolObjects = new ProtocolObjects("ti"
066: + super .getName(), "gov.nist", transport, true);
067:
068: this .riProtocolObjects = new ProtocolObjects("ri"
069: + super .getName(), super .getImplementationPath(),
070: transport, riAutoDialog);
071: /*
072: * if (!getImplementationPath().equals("gov.nist"))
073: * this.riProtocolObjects = new ProtocolObjects( super.getName(),
074: * super.getImplementationPath(), transport, true); else
075: * this.riProtocolObjects = tiProtocolObjects;
076: */
077:
078: } else {
079: this .tiProtocolObjects = new ProtocolObjects("ti"
080: + super .getName(), getImplementationPath(),
081: transport, true);
082: this .riProtocolObjects = new ProtocolObjects("ri"
083: + super .getName(), "gov.nist", transport,
084: riAutoDialog);
085:
086: /*
087: * if (!getImplementationPath().equals("gov.nist"))
088: * this.riProtocolObjects = new ProtocolObjects( super.getName(),
089: * super.getImplementationPath(), transport, true); else
090: * this.riProtocolObjects = tiProtocolObjects;
091: */
092:
093: }
094: }
095:
096: private SipListener getSipListener(EventObject sipEvent) {
097: SipProvider source = (SipProvider) sipEvent.getSource();
098: SipListener listener = (SipListener) providerTable.get(source);
099: if (listener == null)
100: throw new TckInternalError("Unexpected null listener");
101: return listener;
102: }
103:
104: public void processRequest(RequestEvent requestEvent) {
105: getSipListener(requestEvent).processRequest(requestEvent);
106:
107: }
108:
109: public void processResponse(ResponseEvent responseEvent) {
110: getSipListener(responseEvent).processResponse(responseEvent);
111:
112: }
113:
114: public void processTimeout(TimeoutEvent timeoutEvent) {
115: getSipListener(timeoutEvent).processTimeout(timeoutEvent);
116: }
117:
118: public void processIOException(IOExceptionEvent exceptionEvent) {
119: fail("unexpected exception");
120:
121: }
122:
123: public void processTransactionTerminated(
124: TransactionTerminatedEvent transactionTerminatedEvent) {
125: getSipListener(transactionTerminatedEvent)
126: .processTransactionTerminated(
127: transactionTerminatedEvent);
128:
129: }
130:
131: public void processDialogTerminated(
132: DialogTerminatedEvent dialogTerminatedEvent) {
133: getSipListener(dialogTerminatedEvent).processDialogTerminated(
134: dialogTerminatedEvent);
135:
136: }
137:
138: protected ScenarioHarness(String name, boolean autoDialog) {
139:
140: super (name, autoDialog);
141: this .providerTable = new Hashtable();
142:
143: }
144:
145: }
|