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