TestMultiNotifierspublic class TestMultiNotifiers extends com.sun.midp.i3test.TestCase implements SipServerConnectionListenerTest Multiple SipConnectionNotifiers on single host |
Fields Summary |
---|
javax.microedition.sip.SipConnectionNotifier | scn1Connection notifier. | javax.microedition.sip.SipConnectionNotifier | scn2Connection notifier. | javax.microedition.sip.SipClientConnection | scc1Client connection. | javax.microedition.sip.SipClientConnection | scc2Client connection. | String | clientMsgSIP request message from client to server |
Methods Summary |
---|
void | cleanup()Close all connections.
try {
if (scc1 != null) {
scc1.close();
}
if (scc2 != null) {
scc2.close();
}
if (scn1 != null) {
scn1.close();
}
if (scn2 != null) {
scn2.close();
}
} catch (IOException ioe) {
assertNull("Unexpected IOException during cleanup", ioe);
ioe.printStackTrace();
}
| public void | notifyRequest(javax.microedition.sip.SipConnectionNotifier scnLocal)Receive request from client
This method is declared in SipServerConnectionListener
try {
System.out.println("Local SCN port = " + scnLocal.getLocalPort());
} catch (IOException ioe) {
ioe.printStackTrace();
fail("IOException in TestMultiNotifiers");
}
| public void | runTests()Tests execute.
declare("Test TestMultiNotifiers ");
setup();
testInviteMsg(scc1, scn1);
synchronized (this) {
try {
wait(500);
} catch (InterruptedException e) {
System.out.println("Catch interrupt");
}
}
testInviteMsg(scc2, scn2);
synchronized (this) {
try {
wait(500);
} catch (InterruptedException e) {
System.out.println("Catch interrupt");
}
}
cleanup();
assertTrue("Failure in TestMultiNotifiers", true);
| void | setup()Open SipConnectionNotifier(SCN1 and SCN2) on ports 6080 and 5081.
Open two client connections connecting to SCN1 and SCN2
try {
// Open SipConnectionNotifier on port 6080
scn1 = (SipConnectionNotifier) Connector.open("sip:6080");
assertNotNull("scn1 is null", scn1);
scn1.setListener(this);
} catch (Exception ex) {
assertNull("Exception during scn1 open", scn1);
ex.printStackTrace();
}
try {
// Open SipConnectionNotifier on port 6081
scn2 = (SipConnectionNotifier) Connector.open("sip:6081");
assertNotNull("scn2 is null", scn2);
scn2.setListener(this);
} catch (Exception ex) {
assertNull("Exception during scn2 open", scn2);
ex.printStackTrace();
}
try {
// Open SIP client connection to the SCN ON PORT 6080
scc1 = (SipClientConnection)
Connector.open("sip:sippy.tester@localhost:6080");
assertNotNull("scc1 is null", scc1);
} catch (Exception ex) {
assertNull("Exception during scc1 open", scc1);
ex.printStackTrace();
cleanup();
}
try {
// Open SIP client connection to the SCN ON PORT 6081
scc2 = (SipClientConnection)
Connector.open("sip:sippy.tester@localhost:5081");
assertNotNull("scc2 is null", scc2);
} catch (Exception ex) {
assertNull("Exception during scc2 open", scc2);
ex.printStackTrace();
cleanup();
}
| public void | testInviteMsg(javax.microedition.sip.SipClientConnection scc, javax.microedition.sip.SipConnectionNotifier scn)Send a SIP INVITE message
try {
scc.initRequest("INVITE", scn);
scc.setHeader("From", "sip:sippy.tester@localhost");
scc.setHeader("Subject", "Hello...");
scc.setHeader("Contact", "sip:user@"+scn.getLocalAddress() +
":" + scn.getLocalPort());
// write message body
scc.setHeader("Content-Type", "text/plain");
scc.setHeader("Content-Length",
Integer.toString(clientMsg.length()));
OutputStream os = scc.openContentOutputStream();
os.write(clientMsg.getBytes());
os.close(); // close stream and send the message
// System.out.println("Inviting..." + scc.getHeader("To"));
} catch (IOException ioe) {
ioe.printStackTrace();
cleanup();
fail("IOException in TestMultiNotifiers");
}
|
|