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: package test.tck.msgflow.callflows.router;
021:
022: import javax.sip.SipListener;
023: import javax.sip.SipProvider;
024:
025: import org.apache.log4j.Appender;
026: import org.apache.log4j.ConsoleAppender;
027: import org.apache.log4j.Logger;
028: import org.apache.log4j.SimpleLayout;
029:
030: import test.tck.msgflow.callflows.NonSipUriRouter;
031: import test.tck.msgflow.callflows.ScenarioHarness;
032:
033: /**
034: *
035: * Implements common setup and tearDown sequence for Router test
036: *
037: * @author M. Ranganathan
038: *
039: */
040: public abstract class AbstractRouterTestCase extends ScenarioHarness
041: implements SipListener {
042:
043: protected Shootist shootist;
044:
045: protected Shootme shootme;
046:
047: private static Logger logger = Logger.getLogger("test.tck");
048:
049: static {
050: if (!logger.isAttached(console)) {
051: logger.addAppender(console);
052: }
053: }
054:
055: public AbstractRouterTestCase() {
056: super ("routeteluri", true);
057: }
058:
059: public void setUp() throws Exception {
060: try {
061: super .setUp();
062:
063: logger.info("RouterTest: setup()");
064: shootist = new Shootist(tiProtocolObjects);
065: SipProvider shootistProvider = shootist.createProvider();
066: providerTable.put(shootistProvider, shootist);
067:
068: shootme = new Shootme(riProtocolObjects);
069: SipProvider shootmeProvider = shootme.createProvider();
070: providerTable.put(shootmeProvider, shootme);
071:
072: shootistProvider.addSipListener(this );
073: shootmeProvider.addSipListener(this );
074:
075: if (tiProtocolObjects != riProtocolObjects)
076: tiProtocolObjects.start();
077: riProtocolObjects.start();
078: } catch (Exception ex) {
079: logger.error("unexpected excecption ", ex);
080: fail("unexpected exception");
081: }
082: }
083:
084: public void tearDown() throws Exception {
085: try {
086: Thread.sleep(2000);
087: this .shootist.checkState();
088: this .shootme.checkState();
089: assertTrue("Router was not consulted",
090: NonSipUriRouter.routerWasConsulted);
091: NonSipUriRouter.routerWasConsulted = false;
092: tiProtocolObjects.destroy();
093: if (riProtocolObjects != tiProtocolObjects)
094: riProtocolObjects.destroy();
095: Thread.sleep(1000);
096: this .providerTable.clear();
097:
098: logTestCompleted();
099: } catch (Exception ex) {
100: logger.error("unexpected exception", ex);
101: fail("unexpected exception ");
102: }
103: super.tearDown();
104: }
105:
106: }
|