001: /**
002: *
003: */package examples.cancel;
004:
005: import java.util.EventObject;
006: import java.util.Hashtable;
007: import java.util.Timer;
008: import java.util.TimerTask;
009:
010: import javax.sip.DialogTerminatedEvent;
011: import javax.sip.IOExceptionEvent;
012: import javax.sip.RequestEvent;
013: import javax.sip.ResponseEvent;
014: import javax.sip.SipListener;
015: import javax.sip.SipProvider;
016: import javax.sip.TimeoutEvent;
017: import javax.sip.TransactionTerminatedEvent;
018:
019: import org.apache.log4j.Appender;
020: import org.apache.log4j.ConsoleAppender;
021: import org.apache.log4j.FileAppender;
022: import org.apache.log4j.Logger;
023: import org.apache.log4j.PropertyConfigurator;
024: import org.apache.log4j.SimpleLayout;
025: import org.apache.log4j.helpers.NullEnumeration;
026:
027: import junit.framework.TestCase;
028:
029: /**
030: * @author M. Ranganathan
031: *
032: */
033: public abstract class AbstractCancelTest extends TestCase implements
034: SipListener {
035:
036: private Hashtable providerTable;
037:
038: protected Shootist shootist;
039:
040: private static Logger logger = Logger
041: .getLogger(AbstractCancelTest.class);
042:
043: static {
044: if (logger.getAllAppenders() instanceof NullEnumeration)
045: PropertyConfigurator.configure("log4j.properties");
046:
047: }
048:
049: //private Appender appender;
050:
051: private SipListener getSipListener(EventObject sipEvent) {
052: SipProvider source = (SipProvider) sipEvent.getSource();
053: SipListener listener = (SipListener) providerTable.get(source);
054: assertTrue(listener != null);
055: return listener;
056: }
057:
058: public AbstractCancelTest() {
059:
060: try {
061: ProtocolObjects.logFileDirectory = "logs/";
062: ProtocolObjects.init("canceltest");
063: providerTable = new Hashtable();
064: shootist = new Shootist();
065: SipProvider shootistProvider = shootist.createSipProvider();
066: providerTable.put(shootistProvider, shootist);
067: Shootme shootme = new Shootme();
068: SipProvider shootmeProvider = shootme.createProvider();
069: providerTable.put(shootmeProvider, shootme);
070: shootistProvider.addSipListener(this );
071: shootmeProvider.addSipListener(this );
072: ProtocolObjects.start();
073: } catch (Exception ex) {
074: fail("unexpected exception ");
075: }
076: }
077:
078: public void setUp() {
079:
080: try {
081: //appender = new ConsoleAppender(new SimpleLayout());
082: //logger.addAppender(appender);
083:
084: } catch (Exception ex) {
085: throw new RuntimeException(
086: "Unexpected error initializing logging", ex);
087: }
088:
089: }
090:
091: public void tearDown() {
092:
093: ProtocolObjects.destroy();
094: //logger.removeAppender(appender);
095:
096: }
097:
098: public void processRequest(RequestEvent requestEvent) {
099: getSipListener(requestEvent).processRequest(requestEvent);
100:
101: }
102:
103: public void processResponse(ResponseEvent responseEvent) {
104: getSipListener(responseEvent).processResponse(responseEvent);
105:
106: }
107:
108: public void processTimeout(TimeoutEvent timeoutEvent) {
109: getSipListener(timeoutEvent).processTimeout(timeoutEvent);
110: }
111:
112: public void processIOException(IOExceptionEvent exceptionEvent) {
113: fail("unexpected exception");
114:
115: }
116:
117: public void processTransactionTerminated(
118: TransactionTerminatedEvent transactionTerminatedEvent) {
119: getSipListener(transactionTerminatedEvent)
120: .processTransactionTerminated(
121: transactionTerminatedEvent);
122:
123: }
124:
125: public void processDialogTerminated(
126: DialogTerminatedEvent dialogTerminatedEvent) {
127: getSipListener(dialogTerminatedEvent).processDialogTerminated(
128: dialogTerminatedEvent);
129:
130: }
131:
132: }
|