|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjunit.framework.Assert
junit.framework.TestCase
org.cafesip.sipunit.SipTestCase
public class SipTestCase
The SipTestCase class provides a test environment and set of assert methods geared toward unit testing Java SIP applications. It uses the JUnit test framework and API (http://junit.sourceforge.net) and extends junit.framework.TestCase. A SIP application test program (a) uses the SipUnit API to invoke SIP operations against a test target and (b) uses the assert methods of this class in addition to any of the JUnit Assert methods to verify the results of the test.
To write a SIP application test class, or program:
The code in the SIP application test class creates SipUnit API objects, calls their methods to set up and initiate action toward a SIP test target, and verifies the results involving the test target using the assert methods of this class and the standard JUnit assert methods. Messages are only displayed when an assert fails. See below for an example test class.
To execute the test program and run the tests, use the standard JUnit test runners which can run a test suite and collect/output the results. This is commonly done using IDE Junit facilities or via the Ant junit target.
EXAMPLE SIP APPLICATION TEST CLASS: (see the SipUnit User Guide for more information on how to use the API effectively)
import org.cafesip.sipunit.*;
public class TestNoProxy extends SipTestCase
{
private SipStack sipStack;
private SipPhone ua;
private String thisHostAddr = "127.0.0.1";
public TestNoProxy(String arg0)
{
super(arg0);
}
public void setUp() throws Exception
{
sipStack = new SipStack(null, -1);
ua = sipStack.createSipPhone("sip:amit@nist.gov");
}
public void tearDown() throws Exception
{
ua.dispose();
sipStack.dispose();
}
public void testBothSides()
// test target: SipUnit API classes, incoming and outgoing SIP handling (a calls b)
{
try
{
SipPhone ub = sipStack.createSipPhone("sip:becky@nist.gov");
SipCall a = ua.createSipCall();
SipCall b = ub.createSipCall();
b.listenForIncomingCall(); // non-blocking
Thread.sleep(5);
a.initiateOutgoingCall("sip:becky@nist.gov", thisHostAddr
+ ":5060/UDP");
assertLastOperationSuccess("a initiate call - " + a.format(), a);
b.waitForIncomingCall(10000); // blocking
assertLastOperationSuccess("b wait incoming call - " + b.format(),
b);
b.sendIncomingCallResponse(Response.RINGING, null, -1);
assertLastOperationSuccess("b send RINGING - " + b.format(), b);
Thread.sleep(1000);
b.sendIncomingCallResponse(Response.OK, "Answer - Hello world", 0);
assertLastOperationSuccess("b send OK - " + b.format(), b);
a.waitOutgoingCallResponse(10000); // block waiting for a response
assertLastOperationSuccess("a wait 1st response - " + a.format(), a);
assertEquals("Unexpected 1st response received", Response.RINGING,
a.getReturnCode());
assertNotNull("Default response reason not sent", a
.getLastReceivedResponse().getReasonPhrase());
assertEquals("Unexpected default reason", "Ringing", a
.getLastReceivedResponse().getReasonPhrase());
a.waitOutgoingCallResponse(10000); // block waiting for next response
assertLastOperationSuccess("a wait 2nd response - " + a.format(), a);
assertEquals("Unexpected 2nd response received", Response.OK, a
.getReturnCode());
a.sendInviteOkAck();
assertLastOperationSuccess("Failure sending ACK - " + a.format(), a);
Thread.sleep(1000);
a.listenForDisconnect(); // non-blocking
assertLastOperationSuccess("a listen disc - " + a.format(), a);
b.disconnect();
assertLastOperationSuccess("b disc - " + b.format(), b);
a.waitForDisconnect(5000); // blocking
assertLastOperationSuccess("a wait disc - " + a.format(), a);
a.respondToDisconnect();
assertLastOperationSuccess("a respond to disc - " + a.format(), a);
ub.dispose();
}
catch (Exception e)
{
fail("Exception: " + e.getClass().getName() + ": " + e.getMessage());
}
}
| Constructor Summary | |
|---|---|
SipTestCase()
A no-arg constructor to enable serialization. |
|
SipTestCase(java.lang.String arg0)
A constructor for this test case. |
|
| Method Summary | |
|---|---|
void |
assertAnswered(SipCall call)
Asserts that the given incoming or outgoing call leg was answered. |
void |
assertAnswered(java.lang.String msg,
SipCall call)
Asserts that the given incoming or outgoing call leg was answered. |
void |
assertBodyContains(SipMessage sipMessage,
java.lang.String value)
Asserts that the given SIP message contains a body that includes the given value. |
void |
assertBodyContains(java.lang.String msg,
SipMessage sipMessage,
java.lang.String value)
Asserts that the given SIP message contains a body that includes the given value. |
void |
assertBodyNotContains(SipMessage sipMessage,
java.lang.String value)
Asserts that the body in the given SIP message does not contain the value given, or that there is no body in the message. |
void |
assertBodyNotContains(java.lang.String msg,
SipMessage sipMessage,
java.lang.String value)
Asserts that the body in the given SIP message does not contain the value given, or that there is no body in the message. |
void |
assertBodyNotPresent(SipMessage sipMessage)
Asserts that the given SIP message contains no body. |
void |
assertBodyNotPresent(java.lang.String msg,
SipMessage sipMessage)
Asserts that the given SIP message contains no body. |
void |
assertBodyPresent(SipMessage sipMessage)
Asserts that the given SIP message contains a body. |
void |
assertBodyPresent(java.lang.String msg,
SipMessage sipMessage)
Asserts that the given SIP message contains a body. |
void |
assertHeaderContains(SipMessage sipMessage,
java.lang.String header,
java.lang.String value)
Asserts that the given SIP message contains at least one occurrence of the specified header and that at least one occurrence of this header contains the given value. |
void |
assertHeaderContains(java.lang.String msg,
SipMessage sipMessage,
java.lang.String header,
java.lang.String value)
Asserts that the given SIP message contains at least one occurrence of the specified header and that at least one occurrence of this header contains the given value. |
void |
assertHeaderNotContains(SipMessage sipMessage,
java.lang.String header,
java.lang.String value)
Asserts that the given SIP message contains no occurrence of the specified header with the value given, or that there is no occurrence of the header in the message. |
void |
assertHeaderNotContains(java.lang.String msg,
SipMessage sipMessage,
java.lang.String header,
java.lang.String value)
Asserts that the given SIP message contains no occurrence of the specified header with the value given, or that there is no occurrence of the header in the message. |
void |
assertHeaderNotPresent(SipMessage sipMessage,
java.lang.String header)
Asserts that the given SIP message contains no occurrence of the specified header. |
void |
assertHeaderNotPresent(java.lang.String msg,
SipMessage sipMessage,
java.lang.String header)
Asserts that the given SIP message contains no occurrence of the specified header. |
void |
assertHeaderPresent(SipMessage sipMessage,
java.lang.String header)
Asserts that the given SIP message contains at least one occurrence of the specified header. |
void |
assertHeaderPresent(java.lang.String msg,
SipMessage sipMessage,
java.lang.String header)
Asserts that the given SIP message contains at least one occurrence of the specified header. |
void |
assertLastOperationFail(SipActionObject op)
Asserts that the last SIP operation performed by the given object failed. |
void |
assertLastOperationFail(java.lang.String msg,
SipActionObject op)
Asserts that the last SIP operation performed by the given object failed. |
void |
assertLastOperationSuccess(SipActionObject op)
Asserts that the last SIP operation performed by the given object was successful. |
void |
assertLastOperationSuccess(java.lang.String msg,
SipActionObject op)
Asserts that the last SIP operation performed by the given object was successful. |
void |
assertNoPresenceErrors(java.lang.String msg,
Subscription subscription)
Asserts that the given Subscription has not encountered any errors while processing received SUBSCRIBE responses and received NOTIFY requests. |
void |
assertNoPresenceErrors(Subscription subscription)
Asserts that the given Subscription has not encountered any errors while processing received SUBSCRIBE responses and received NOTIFY requests. |
void |
assertNotAnswered(SipCall call)
Asserts that the given incoming or outgoing call leg has not been answered. |
void |
assertNotAnswered(java.lang.String msg,
SipCall call)
Asserts that the given incoming or outgoing call leg has not been answered. |
void |
assertRequestNotReceived(java.lang.String method,
long sequenceNumber,
MessageListener obj)
Asserts that the given message listener object has not received a request with the indicated CSeq method and sequence number. |
void |
assertRequestNotReceived(java.lang.String method,
MessageListener obj)
Asserts that the given message listener object has not received a request with the indicated request method. |
void |
assertRequestNotReceived(java.lang.String msg,
java.lang.String method,
long sequenceNumber,
MessageListener obj)
Asserts that the given message listener object has not received a request with the indicated CSeq method and sequence number. |
void |
assertRequestNotReceived(java.lang.String msg,
java.lang.String method,
MessageListener obj)
Asserts that the given message listener object has not received a request with the indicated request method. |
void |
assertRequestReceived(java.lang.String method,
long sequenceNumber,
MessageListener obj)
Asserts that the given message listener object received a request with the indicated CSeq method and CSeq sequence number. |
void |
assertRequestReceived(java.lang.String method,
MessageListener obj)
Asserts that the given message listener object received a request with the indicated request method. |
void |
assertRequestReceived(java.lang.String msg,
java.lang.String method,
long sequenceNumber,
MessageListener obj)
Asserts that the given message listener object received a request with the indicated CSeq method and CSeq sequence number. |
void |
assertRequestReceived(java.lang.String msg,
java.lang.String method,
MessageListener obj)
Asserts that the given message listener object received a request with the indicated request method. |
void |
assertResponseNotReceived(int statusCode,
MessageListener obj)
Asserts that the given message listener object has not received a response with the indicated status code. |
void |
assertResponseNotReceived(int statusCode,
java.lang.String method,
long sequenceNumber,
MessageListener obj)
Asserts that the given message listener object has not received a response with the indicated status code, CSeq method and sequence number. |
void |
assertResponseNotReceived(java.lang.String msg,
int statusCode,
MessageListener obj)
Asserts that the given message listener object has not received a response with the indicated status code. |
void |
assertResponseNotReceived(java.lang.String msg,
int statusCode,
java.lang.String method,
long sequenceNumber,
MessageListener obj)
Asserts that the given message listener object has not received a response with the indicated status code, CSeq method and sequence number. |
void |
assertResponseReceived(int statusCode,
MessageListener obj)
Asserts that the given message listener object received a response with the indicated status code. |
void |
assertResponseReceived(int statusCode,
java.lang.String method,
long sequenceNumber,
MessageListener obj)
Asserts that the given message listener object received a response with the indicated status code, CSeq method and CSeq sequence number. |
void |
assertResponseReceived(java.lang.String msg,
int statusCode,
MessageListener obj)
Asserts that the given message listener object received a response with the indicated status code. |
void |
assertResponseReceived(java.lang.String msg,
int statusCode,
java.lang.String method,
long sequenceNumber,
MessageListener obj)
Asserts that the given message listener object received a response with the indicated status code, CSeq method and CSeq sequence number. |
void |
setUp()
Sets up the environment for each test method prior to execution. |
void |
tearDown()
Cleans up from the test method just executed. |
| Methods inherited from class junit.framework.TestCase |
|---|
countTestCases, getName, run, run, runBare, setName, toString |
| Methods inherited from class junit.framework.Assert |
|---|
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public SipTestCase(java.lang.String arg0)
arg0 - the name of the test casepublic SipTestCase()
| Method Detail |
|---|
public void setUp()
throws java.lang.Exception
setUp in class junit.framework.TestCasejava.lang.Exception
public void tearDown()
throws java.lang.Exception
tearDown in class junit.framework.TestCasejava.lang.Exceptionpublic void assertLastOperationSuccess(SipActionObject op)
op - the SipUnit object that executed an operation.
public void assertLastOperationSuccess(java.lang.String msg,
SipActionObject op)
msg - message text to output if the assertion fails.op - the SipUnit object that executed an operation.public void assertLastOperationFail(SipActionObject op)
op - the SipUnit object that executed an operation.
public void assertLastOperationFail(java.lang.String msg,
SipActionObject op)
msg - message text to output if the assertion fails.op - the SipUnit object that executed an operation.public void assertHeaderPresent(SipMessage sipMessage, java.lang.String header)
sipMessage - the SIP message.header - the string identifying the header, as specified in RFC-3261.
public void assertHeaderPresent(java.lang.String msg,
SipMessage sipMessage,
java.lang.String header)
msg - message text to output if the assertion fails.sipMessage - the SIP message.header - the string identifying the header as specified in RFC-3261.public void assertHeaderNotPresent(SipMessage sipMessage, java.lang.String header)
sipMessage - the SIP message.header - the string identifying the header as specified in RFC-3261.
public void assertHeaderNotPresent(java.lang.String msg,
SipMessage sipMessage,
java.lang.String header)
msg - message text to output if the assertion fails.sipMessage - the SIP message.header - the string identifying the header as specified in RFC-3261.public void assertHeaderContains(SipMessage sipMessage, java.lang.String header, java.lang.String value)
sipMessage - the SIP message.header - the string identifying the header as specified in RFC-3261.value - the string value within the header to look for. An exact
string match is done against the entire contents of the
header. The assertion will pass if any part of the header
matches the value given.
public void assertHeaderContains(java.lang.String msg,
SipMessage sipMessage,
java.lang.String header,
java.lang.String value)
msg - message text to output if the assertion fails.sipMessage - the SIP message.header - the string identifying the header as specified in RFC-3261.value - the string value within the header to look for. An exact
string match is done against the entire contents of the
header. The assertion will pass if any part of the header
matches the value given.public void assertHeaderNotContains(SipMessage sipMessage, java.lang.String header, java.lang.String value)
sipMessage - the SIP message.header - the string identifying the header as specified in RFC-3261.value - the string value within the header to look for. An exact
string match is done against the entire contents of the
header. The assertion will fail if any part of the header
matches the value given.
public void assertHeaderNotContains(java.lang.String msg,
SipMessage sipMessage,
java.lang.String header,
java.lang.String value)
msg - message text to output if the assertion fails.sipMessage - the SIP message.header - the string identifying the header as specified in RFC-3261.value - the string value within the header to look for. An exact
string match is done against the entire contents of the
header. The assertion will fail if any part of the header
matches the value given.
public void assertResponseReceived(int statusCode,
MessageListener obj)
statusCode - The response status code to check for (eg,
SipResponse.RINGING)obj - The MessageListener object (ie, SipCall, Subscription, etc.).
public void assertResponseReceived(int statusCode,
java.lang.String method,
long sequenceNumber,
MessageListener obj)
statusCode - The response status code to check for (eg,
SipResponse.RINGING)method - The CSeq method to look for (SipRequest.INVITE, etc.)sequenceNumber - The CSeq sequence number to look forobj - The MessageListener object (ie, SipCall, Subscription, etc.).
public void assertResponseReceived(java.lang.String msg,
int statusCode,
MessageListener obj)
msg - message text to output if the assertion fails.statusCode - The response status code to check for (eg,
SipResponse.RINGING)obj - The MessageListener object (ie, SipCall, Subscription, etc.).
public void assertResponseReceived(java.lang.String msg,
int statusCode,
java.lang.String method,
long sequenceNumber,
MessageListener obj)
msg - message text to output if the assertion fails.statusCode - The response status code to check for (eg,
SipResponse.RINGING)method - The CSeq method to look for (SipRequest.INVITE, etc.)sequenceNumber - The CSeq sequence number to look forobj - The MessageListener object (ie, SipCall, Subscription, etc.).
public void assertResponseNotReceived(int statusCode,
MessageListener obj)
statusCode - The response status code to verify absent (eg,
SipResponse.RINGING)obj - The MessageListener object (ie, SipCall, Subscription, etc.).
public void assertResponseNotReceived(java.lang.String msg,
int statusCode,
MessageListener obj)
msg - message text to output if the assertion fails.statusCode - The response status code to verify absent (eg,
SipResponse.RINGING)obj - The MessageListener object (ie, SipCall, Subscription, etc.).
public void assertResponseNotReceived(int statusCode,
java.lang.String method,
long sequenceNumber,
MessageListener obj)
statusCode - The response status code to verify absent (eg,
SipResponse.RINGING)method - The CSeq method to verify absent (SipRequest.INVITE, etc.)sequenceNumber - The CSeq sequence number to verify absentobj - The MessageListener object (ie, SipCall, Subscription, etc.).
public void assertResponseNotReceived(java.lang.String msg,
int statusCode,
java.lang.String method,
long sequenceNumber,
MessageListener obj)
msg - message text to output if the assertion fails.statusCode - The response status code to verify absent (eg,
SipResponse.RINGING)method - The CSeq method to verify absent (SipRequest.INVITE, etc.)sequenceNumber - The CSeq sequence number to verify absentobj - The MessageListener object (ie, SipCall, Subscription, etc.).
public void assertRequestReceived(java.lang.String method,
MessageListener obj)
method - The request method to check for (eg, SipRequest.BYE)obj - The MessageListener object (ie, SipCall, Subscription, etc.).
public void assertRequestReceived(java.lang.String method,
long sequenceNumber,
MessageListener obj)
method - The CSeq method to look for (SipRequest.REGISTER, etc.)sequenceNumber - The CSeq sequence number to look forobj - The MessageListener object (ie, SipCall, Subscription, etc.).
public void assertRequestReceived(java.lang.String msg,
java.lang.String method,
MessageListener obj)
msg - message text to output if the assertion fails.method - The request method to check for (eg, SipRequest.INVITE)obj - The MessageListener object (ie, SipCall, Subscription, etc.).
public void assertRequestReceived(java.lang.String msg,
java.lang.String method,
long sequenceNumber,
MessageListener obj)
msg - message text to output if the assertion fails.method - The CSeq method to look for (SipRequest.INVITE, etc.)sequenceNumber - The CSeq sequence number to look forobj - The MessageListener object (ie, SipCall, Subscription, etc.).
public void assertRequestNotReceived(java.lang.String method,
MessageListener obj)
method - The request method to verify absent (eg, SipRequest.BYE)obj - The MessageListener object (ie, SipCall, Subscription, etc.).
public void assertRequestNotReceived(java.lang.String msg,
java.lang.String method,
MessageListener obj)
msg - message text to output if the assertion fails.method - The request method to verify absent (eg, SipRequest.BYE)obj - The MessageListener object (ie, SipCall, Subscription, etc.).
public void assertRequestNotReceived(java.lang.String method,
long sequenceNumber,
MessageListener obj)
method - The CSeq method to verify absent (SipRequest.INVITE, etc.)sequenceNumber - The CSeq sequence number to verify absentobj - The MessageListener object (ie, SipCall, Subscription, etc.).
public void assertRequestNotReceived(java.lang.String msg,
java.lang.String method,
long sequenceNumber,
MessageListener obj)
msg - message text to output if the assertion fails.method - The CSeq method to verify absent (SipRequest.INVITE, etc.)sequenceNumber - The CSeq sequence number to verify absentobj - The MessageListener object (ie, SipCall, Subscription, etc.).public void assertAnswered(SipCall call)
call - The incoming or outgoing call leg.
public void assertAnswered(java.lang.String msg,
SipCall call)
msg - message text to output if the assertion fails.call - The incoming or outgoing call leg.public void assertNotAnswered(SipCall call)
call - The incoming or outgoing call leg.
public void assertNotAnswered(java.lang.String msg,
SipCall call)
msg - message text to output if the assertion fails.call - The incoming or outgoing call leg.public void assertBodyPresent(SipMessage sipMessage)
sipMessage - the SIP message.
public void assertBodyPresent(java.lang.String msg,
SipMessage sipMessage)
msg - message text to output if the assertion fails.sipMessage - the SIP message.public void assertBodyNotPresent(SipMessage sipMessage)
sipMessage - the SIP message.
public void assertBodyNotPresent(java.lang.String msg,
SipMessage sipMessage)
msg - message text to output if the assertion fails.sipMessage - the SIP message.public void assertBodyContains(SipMessage sipMessage, java.lang.String value)
sipMessage - the SIP message.value - the string value to look for in the body. An exact string
match is done against the entire contents of the body. The
assertion will pass if any part of the body matches the value
given. ??case sensitive?
public void assertBodyContains(java.lang.String msg,
SipMessage sipMessage,
java.lang.String value)
msg - message text to output if the assertion fails.sipMessage - the SIP message.value - the string value to look for in the body. An exact string
match is done against the entire contents of the body. The
assertion will pass if any part of the body matches the value
given.public void assertBodyNotContains(SipMessage sipMessage, java.lang.String value)
sipMessage - the SIP message.value - the string value to look for in the body. An exact string
match is done against the entire contents of the body. The
assertion will fail if any part of the body matches the value
given.
public void assertBodyNotContains(java.lang.String msg,
SipMessage sipMessage,
java.lang.String value)
msg - message text to output if the assertion fails.sipMessage - the SIP message.value - the string value to look for in the body. An exact string
match is done against the entire contents of the body. The
assertion will fail if any part of the body matches the value
given.public void assertNoPresenceErrors(Subscription subscription)
subscription - the Subscription in question.
public void assertNoPresenceErrors(java.lang.String msg,
Subscription subscription)
msg - message text to include if the assertion fails.subscription - the Subscription in question.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||