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;
021:
022: import java.util.TooManyListenersException;
023:
024: import javax.sip.ClientTransaction;
025: import javax.sip.RequestEvent;
026: import javax.sip.ServerTransaction;
027: import javax.sip.SipException;
028: import javax.sip.Timeout;
029: import javax.sip.TimeoutEvent;
030: import javax.sip.header.ContactHeader;
031: import javax.sip.header.ToHeader;
032: import javax.sip.message.Request;
033: import javax.sip.message.Response;
034:
035: import org.apache.log4j.Logger;
036:
037: import test.tck.TckInternalError;
038: import test.tck.TiUnexpectedError;
039:
040: /**
041: * Timeout test for invite client transactions -- test to see if an timeout
042: * event is delivered to the listener if the RI refuses to send OK to the INVITE
043: * Client Tx.
044: *
045: * @author M. Ranganathan
046: */
047:
048: public class TransactionTimeoutEventTest extends MessageFlowHarness {
049: private static Logger logger = Logger
050: .getLogger(InviteClientTransactionsStateMachineTest.class);
051:
052: public TransactionTimeoutEventTest(String name) {
053: super (name, false); // disable auto-dialog for the RI, else ACKs get
054: // filtered out
055: }
056:
057: // ==================== tests ==============================
058:
059: /**
060: * Test if the tx timeout is delivered.
061: */
062: public void testClientTransactionTimeout() {
063: try {
064: Request invite = createTiInviteRequest(null, null, null);
065: ClientTransaction tran = null;
066: try {
067: eventCollector.collectRequestEvent(riSipProvider);
068:
069: tran = tiSipProvider.getNewClientTransaction(invite);
070: tran.sendRequest();
071: } catch (SipException ex) {
072: throw new TiUnexpectedError(
073: "A SipExceptionOccurred while trying to send request!",
074: ex);
075: } catch (TooManyListenersException ex) {
076: throw new TckInternalError(
077: "Failed to regiest a SipListener with an RI SipProvider",
078: ex);
079: }
080: waitForMessage();
081: RequestEvent inviteReceivedEvent = eventCollector
082: .extractCollectedRequestEvent();
083: assertNotNull("RequestEvent", inviteReceivedEvent);
084: try {
085: eventCollector.collectTimeoutEvent(tiSipProvider);
086: } catch (TooManyListenersException ex) {
087: throw new TiUnexpectedError(
088: "Failed to register a SipListener with TI", ex);
089: }
090: waitForTimeout();
091: TimeoutEvent timeoutEvent = eventCollector
092: .extractCollectedTimeoutEvent();
093: assertNotNull("Timeout event", timeoutEvent);
094: assertTrue("Timeout event type ", timeoutEvent.getTimeout()
095: .equals(Timeout.TRANSACTION));
096: } catch (Exception ex) {
097: logger.error("unexpected exception ", ex);
098: ex.printStackTrace();
099: fail("unexpected exception");
100: }
101: }
102:
103: public void testServerTransactionForTimeout() {
104: try {
105: Request invite = createRiInviteRequest(null, null, null);
106: ClientTransaction tran = null;
107: try {
108: eventCollector.collectRequestEvent(tiSipProvider);
109: tran = riSipProvider.getNewClientTransaction(invite);
110: tran.sendRequest();
111: } catch (SipException ex) {
112: throw new TiUnexpectedError(
113: "A SipExceptionOccurred while trying to send request!",
114: ex);
115: } catch (TooManyListenersException ex) {
116: throw new TckInternalError(
117: "Failed to regiest a SipListener with an RI SipProvider",
118: ex);
119: }
120: waitForMessage();
121: RequestEvent inviteReceivedEvent = eventCollector
122: .extractCollectedRequestEvent();
123: assertNotNull("RequestEvent not seen at TI",
124: inviteReceivedEvent);
125: assertTrue("Server Transaction MUST be null",
126: inviteReceivedEvent.getServerTransaction() == null);
127: ServerTransaction st = tiSipProvider
128: .getNewServerTransaction(inviteReceivedEvent
129: .getRequest());
130: Response response = tiMessageFactory.createResponse(
131: Response.OK, inviteReceivedEvent.getRequest());
132: ToHeader toHeader = (ToHeader) response
133: .getHeader(ToHeader.NAME);
134: toHeader.setTag("123456");
135: ContactHeader contact = super .createTiContact();
136: response.setHeader(contact);
137: st.sendResponse(response);
138:
139: eventCollector.collectTimeoutEvent(tiSipProvider);
140: waitForTimeout();
141: TimeoutEvent timeoutEvent = eventCollector
142: .extractCollectedTimeoutEvent();
143: assertNotNull("Timeout event", timeoutEvent);
144: assertTrue("Timeout event type must be TRANSACTION ",
145: timeoutEvent.getTimeout().equals(
146: Timeout.TRANSACTION));
147:
148: } catch (Exception ex) {
149: logger.error("unexpected exception ", ex);
150: ex.printStackTrace();
151: fail("unexpected exception");
152: }
153: }
154:
155: public void testServerTransactionForRetransmissionAlerts() {
156: try {
157: Request invite = createRiInviteRequest(null, null, null);
158: ClientTransaction tran = null;
159: tiSipProvider.setAutomaticDialogSupportEnabled(false);
160: try {
161: eventCollector.collectRequestEvent(tiSipProvider);
162: tran = riSipProvider.getNewClientTransaction(invite);
163: tran.sendRequest();
164: } catch (SipException ex) {
165: throw new TiUnexpectedError(
166: "A SipExceptionOccurred while trying to send request!",
167: ex);
168: } catch (TooManyListenersException ex) {
169: throw new TckInternalError(
170: "Failed to regiest a SipListener with an RI SipProvider",
171: ex);
172: }
173: waitForMessage();
174: RequestEvent inviteReceivedEvent = eventCollector
175: .extractCollectedRequestEvent();
176: assertNotNull("RequestEvent not seen at TI",
177: inviteReceivedEvent);
178: assertTrue("Server Transaction MUST be null",
179: inviteReceivedEvent.getServerTransaction() == null);
180: ServerTransaction st = tiSipProvider
181: .getNewServerTransaction(inviteReceivedEvent
182: .getRequest());
183: Response response = tiMessageFactory.createResponse(
184: Response.OK, inviteReceivedEvent.getRequest());
185: ToHeader toHeader = (ToHeader) response
186: .getHeader(ToHeader.NAME);
187: toHeader.setTag("1234567");
188: ContactHeader contact = super .createTiContact();
189: response.setHeader(contact);
190: st.enableRetransmissionAlerts();
191: st.sendResponse(response);
192: eventCollector.collectTimeoutEvent(tiSipProvider);
193: waitForTimeout();
194: TimeoutEvent timeoutEvent = eventCollector
195: .extractCollectedTimeoutEvent();
196: assertNotNull("Timeout event not found ", timeoutEvent);
197: assertTrue("Timeout event type must be retransmit ",
198: timeoutEvent.getTimeout()
199: .equals(Timeout.RETRANSMIT));
200:
201: } catch (Exception ex) {
202: logger.error("unexpected exception ", ex);
203: ex.printStackTrace();
204: fail("unexpected exception");
205: }
206: }
207: }
|