/** * 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(null, null, null); ClientTransaction tran = null; try { tran = tiSipProvider.getNewClientTransaction(invite); } catch (TransactionUnavailableException exc) { throw new TiUnexpectedError( "A TransactionUnavailableException was thrown while trying to " + "create a new client transaction", exc); } 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(), Request.CANCEL); 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(CallIdHeader.NAME), invite.getHeader(CallIdHeader.NAME)); assertEquals( "ToHeaders of the original and the cancel request do not match", cancel.getHeader(ToHeader.NAME), invite.getHeader(ToHeader.NAME)); assertTrue( "The CSeqHeader's sequence number of the original and " + "the cancel request do not match", ((CSeqHeader) cancel.getHeader(CSeqHeader.NAME)).getSequenceNumber() == ((CSeqHeader) invite.getHeader(CSeqHeader.NAME)).getSequenceNumber()); assertEquals( "The CSeqHeader's method of the cancel request was not CANCEL", ((CSeqHeader) cancel.getHeader(CSeqHeader.NAME)).getMethod(), Request.CANCEL); assertTrue( "There was no ViaHeader in the cancel request", cancel.getHeaders(ViaHeader.NAME).hasNext()); Iterator cancelVias = cancel.getHeaders(ViaHeader.NAME); ViaHeader cancelVia = ((ViaHeader) cancelVias.next()); ViaHeader inviteVia = ((ViaHeader) invite.getHeaders(ViaHeader.NAME).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()); } catch (Throwable exc) { exc.printStackTrace(); fail(exc.getClass().getName() + ": " + exc.getMessage()); } assertTrue(new Exception().getStackTrace()[0].toString(), true); }