Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * This source code has been contributed to the public domain by Mobicents
   *
   * This software is provided by NIST as a service and is expressly
   * 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.
  *
  * Permission to use this software is contingent upon your acceptance
  * of the terms of this agreement.
  */
  package test.unit.gov.nist.javax.sip.stack.dialog.timeout;
 
 
 
 
 import  test.tck.msgflow.callflows.ProtocolObjects;
 import  test.tck.msgflow.callflows.ScenarioHarness;

Testing if Dialog Timeout Event is correctly passed to the application layer on both sides if the ACK is not sent by the UAC and the autodialog flag is false only

Author(s):
jean deruelle
 
 public class DialogTimeoutTest extends ScenarioHarness {
 
 	private ProtocolObjects shootistProtocolObjs;
 
 	private ProtocolObjects shootmeProtocolObjs;
 
 	    
     protected Shootist shootist;
     
 
     private Shootme shootme;
     
 
     private static final Logger logger = Logger.getLogger("test.tck");
     private static final int TIMEOUT = 60000;
 
     static {
         if (!.isAttached(console))
             .addAppender(console);
     }
 
     public DialogTimeoutTest() {
         super("DialogTerminationOn500Test"true);
 
     }
 
     public void setUp() {
         doSetUp();
 
     }
 
     private void doSetUp() {
         try {            
             super.setUp();            
         } catch (Exception ex) {
             ex.printStackTrace();
             fail("unexpected exception ");
         }
     }
 
     // check that the apps gets called for timeout event when no ack is received nor sent
     public void testDialogTimeoutSipListenerExt() {
         
             try {
             	this. = new ProtocolObjects("shootist""gov.nist""udp"false,falsetrue);
                  = new Shootist();
                 SipProvider shootistProvider = .createSipProvider();
 
                 this. = new ProtocolObjects("shootme""gov.nist""udp"false,falsetrue);
                 ((SipStackImpl).).setAggressiveCleanup(true);
                  = new Shootme();
                 SipProvider shootmeProvider = .createSipProvider();
                
                 .init();
                 providerTable.put(shootistProvider);
 
                 .init();
                 providerTable.put(shootmeProvider);
                 shootistProvider.addSipListener();
                 shootmeProvider.addSipListener();
 
                 getRiProtocolObjects().start();
                 if (getTiProtocolObjects() != getRiProtocolObjects())
                     getTiProtocolObjects().start();
                
                this..sendInviteRequest();
                Thread.currentThread().sleep();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                fail("unexpected exception ");
            }
            if (!this..checkState() || !this..checkState()) {
                fail("Test Failed - Didnt receive Dialog Timeout Event");
                return;
            }
            doTearDown(false);
            doSetUp();
    }
    
    // check that the apps gets called for timeout event when no ack is received nor sent
    // and for terminated event after the BYE is sent
        
        try {
        	this. = new ProtocolObjects("shootist""gov.nist""udp"false,falsetrue);
             = new Shootist();
            .setSendByeOnDialogTimeout(true);
            SipProvider shootistProvider = .createSipProvider();
            this. = new ProtocolObjects("shootme""gov.nist""udp"false,falsetrue);
             = new Shootme();
            .setReceiveBye(true);
            SipProvider shootmeProvider = .createSipProvider();
           
            .init();
            providerTable.put(shootistProvider);
            .init();
            providerTable.put(shootmeProvider);
            shootistProvider.addSipListener();
            shootmeProvider.addSipListener();
            getRiProtocolObjects().start();
            if (getTiProtocolObjects() != getRiProtocolObjects())
                getTiProtocolObjects().start();
            
            this..sendInviteRequest();
            Thread.currentThread().sleep();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            fail("unexpected exception ");
        }
        if (!this..checkState() || !this..checkState()) {
            fail("Test Failed - Didnt receive Dialog Timeout Event");
            return;
        }
        doTearDown(false);
        doSetUp();
    }
    
    // check that the caller application doesn't get called on timeout but called on dialog terminated event when it is not implementing the new listener
        
        try {
        	this. = new ProtocolObjects("shootist""gov.nist""udp"false,falsetrue);
            SipProvider shootistProvider = .createSipProvider();
            this. = new ProtocolObjects("shootme""gov.nist""udp"false,falsetrue);
             = new Shootme();
            SipProvider shootmeProvider = .createSipProvider();
           
            providerTable.put(shootistProvider);
            .init();
            providerTable.put(shootmeProvider);
            shootistProvider.addSipListener();
            shootmeProvider.addSipListener();
            getRiProtocolObjects().start();
            if (getTiProtocolObjects() != getRiProtocolObjects())
                getTiProtocolObjects().start();
            
            Thread.currentThread().sleep();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            fail("unexpected exception ");
        }
        if (!this..checkState() || !this..checkState()) {
            fail("Test Failed - Didnt receive Dialog Timeout Event");
            return;
        }
        doTearDown(false);
        doSetUp();
    }
    
    // check that the apps don't get called on tiemout event if autodialog is true but get called on dialog terminated event
    public void testDialogTimeoutAutoDialog() {
        
        try {
        	this. = new ProtocolObjects("shootist""gov.nist""udp"true,falsetrue);
             = new Shootist();
            SipProvider shootistProvider = .createSipProvider();
            this. = new ProtocolObjects("shootme""gov.nist""udp"true,falsetrue);
             = new Shootme();
            SipProvider shootmeProvider = .createSipProvider();
           
            .init();
            providerTable.put(shootistProvider);
            .init();
            providerTable.put(shootmeProvider);
            shootistProvider.addSipListener();
            shootmeProvider.addSipListener();
            getRiProtocolObjects().start();
            if (getTiProtocolObjects() != getRiProtocolObjects())
                getTiProtocolObjects().start();
            
            this..sendInviteRequest();
            Thread.currentThread().sleep();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            fail("unexpected exception ");
        }
        if (!this..checkState() || !this..checkState()) {
            fail("Test Failed - received Dialog Timeout Event");
            return;
        }
        doTearDown(false);
        doSetUp();
    }
    
    // test checking that when the B2BUA flag is set to true, the app doesn't get called on dialog timeout but get called for dialog terminated 
    public void testDialogTimeoutB2BUABothCalled() {
        
        try {
        	this. = new ProtocolObjects("shootist""gov.nist""udp"false,truetrue);
             = new Shootist();
            SipProvider shootistProvider = .createSipProvider();
            this. = new ProtocolObjects("shootme""gov.nist""udp"false,falsetrue);
            .setStateIsOk(true);
            SipProvider shootmeProvider = .createSipProvider();
           
            .init();
            providerTable.put(shootistProvider);
            .init();
            providerTable.put(shootmeProvider);
            shootistProvider.addSipListener();
            shootmeProvider.addSipListener();
            getRiProtocolObjects().start();
            if (getTiProtocolObjects() != getRiProtocolObjects())
                getTiProtocolObjects().start();
            
            this..sendInviteRequest();
            Thread.currentThread().sleep();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            fail("unexpected exception ");
        }
        if (!this..checkState()) {
        	fail("Test Failed - received Dialog Timeout Event");
        }
        		
        if(!this..checkState()) {
            fail("Test Failed - didn't received Dialog Terminated Event");
            return;
        }
        doTearDown(false);
        doSetUp();
    }
    public void tearDown() {
        doTearDown(true);
    }
    private void doTearDown(boolean definetly) {
        try {
            Thread.sleep(3000);
            // this.shootist.checkState();
            // this.shootme.checkState();
            .destroy();
            .destroy();
            Thread.sleep(1000);
            this..clear();
            if (definetly)
                logTestCompleted();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
New to GrepCode? Check out our FAQ X