Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * Conditions Of Use
  *
  * This software was developed by employees of the National Institute of
  * Standards and Technology (NIST), and others.
  * This software is has been contributed to the public domain.
  * As a result, a formal license is not needed to use the software.
  *
  * This software is provided "AS IS."
 * NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
 * AND DATA ACCURACY.  NIST does not warrant or make any representations
 * regarding the use of the software or the results thereof, including but
 * not limited to the correctness, accuracy, reliability or usefulness of
 * the software.
 *
 *
 */
 package test.tck.msgflow;
 
 import  junit.framework.*;
 
 import javax.sip.*;
 import java.util.*;
 import java.text.*;
 import test.tck.*;

Title: TCK

Description: JAIN SIP 1.1 Technology Compatibility Kit

Author(s):
Emil Ivov Network Research Team, Louis Pasteur University, Strasbourg, France This code is in the public domain.
Version:
1.0
 
 
 public class ClientTransactionTest extends MessageFlowHarness {
 
     public ClientTransactionTest(String name) {
         super(name);
     }
 
     //==================== tests ==============================
 
    
Creates an invite request using the Tested Implementation and then tests creating a cancel for the same invite request.
 
     public void testCreateCancel() {
         try {
             Request invite = createTiInviteRequest(nullnullnull);
             ClientTransaction tran = null;
             try {
                 tran = .getNewClientTransaction(invite);
             } catch (TransactionUnavailableException exc) {
                 throw new TiUnexpectedError(
                     "A TransactionUnavailableException was thrown while trying to "
                         + "create a new client transaction",
                     exc);
             }
 
             // see if creating a dialog matters
             tran.getDialog();
 
             Request cancel = null;
             try {
                 cancel = tran.createCancel();
             } catch (SipException ex) {
                 ex.printStackTrace();
                 fail("Failed to create cancel request!");
             }
             assertEquals(
                 "The created request did not have a CANCEL method.",
                 cancel.getMethod(),
                 .);
             assertEquals(
                 "Request-URIs of the original and the cancel request do not match",
                 cancel.getRequestURI(),
                 invite.getRequestURI());
             assertEquals(
                 "Call-IDs of the original and the cancel request do not match",
                 cancel.getHeader(.),
                 invite.getHeader(.));
             assertEquals(
                 "ToHeaders of the original and the cancel request do not match",
                 cancel.getHeader(.),
                 invite.getHeader(.));
             assertTrue(
                 "The CSeqHeader's sequence number of the original and "
                     + "the cancel request do not match",
                 ((CSeqHeadercancel.getHeader(.))
                     .getSeqNumber()
                     == ((CSeqHeaderinvite.getHeader(.))
                         .getSeqNumber());
             assertEquals(
                 "The CSeqHeader's method of the cancel request was not CANCEL",
                ((CSeqHeadercancel.getHeader(.)).getMethod(),
                .);
            assertTrue(
                "There was no ViaHeader in the cancel request",
                cancel.getHeaders(.).hasNext());
            Iterator cancelVias = cancel.getHeaders(.);
            ViaHeader cancelVia = ((ViaHeadercancelVias.next());
            ViaHeader inviteVia =
                ((ViaHeaderinvite.getHeaders(.).next());
            assertEquals(
                "ViaHeaders of the original and the cancel request do not match!",
                cancelVia,
                inviteVia);
            assertFalse(
                "Cancel request had more than one ViaHeader.",
                cancelVias.hasNext());
            assertEquals"To tags must match",
                ((ToHeaderinvite.getHeader("to")).getTag(),
                ((ToHeadercancel.getHeader("to")).getTag()
            );
            assertEquals"From tags must match",
                    ((FromHeaderinvite.getHeader("from")).getTag(),
                    ((FromHeadercancel.getHeader("from")).getTag()
            );
            assertEquals"Max-Forwards must match",
                    invite.getHeader. ),
                    cancel.getHeader. )
            );
        } catch (Throwable exc) {
            exc.printStackTrace();
            fail(exc.getClass().getName() + ": " + exc.getMessage());
        }
        assertTrue(new Exception().getStackTrace()[0].toString(), true);
    }

    
Tests sending a request from a ClientTransaction.
    public void testSendRequest() {
        try {
            Request invite = createTiInviteRequest(nullnullnull);
            RequestEvent receivedRequestEvent = null;
            ClientTransaction tran = null;
            try {
                tran = .getNewClientTransaction(invite);
                .collectRequestEvent();
                tran.sendRequest();
                waitForMessage();
                receivedRequestEvent =
                    .extractCollectedRequestEvent();
                assertNotNull(
                    "The sent request was not received by the RI!",
                    receivedRequestEvent);
                assertNotNull(
                    "The sent request was not received by the RI!",
                    receivedRequestEvent.getRequest());
            } catch (TransactionUnavailableException exc) {
                throw new TiUnexpectedError(
                    "A TransactionUnavailableException was thrown while trying to "
                        + "create a new client transaction",
                    exc);
            } catch (SipException exc) {
                exc.printStackTrace();
                fail("The SipException was thrown while trying to send the request.");
            } catch (TooManyListenersException exc) {
                throw new TckInternalError(
                    "A  TooManyListenersException was thrown while trying "
                        + "to add a SipListener to an RI SipProvider",
                    exc);
            }
        } catch (Throwable exc) {
            exc.printStackTrace();
            fail(exc.getClass().getName() + ": " + exc.getMessage());
        }
        assertTrue(new Exception().getStackTrace()[0].toString(), true);
    }
    //mranga: removed testCreateAck -- should not test for deprecated functionality
    // in the TCK.
    //==================== end of tests
    //====== STATIC JUNIT ==========
    public static Test suite() {
        return new TestSuite(ClientTransactionTest.class);
    }
New to GrepCode? Check out our FAQ X