Package net.fp.rp.spring

Source Code of net.fp.rp.spring.SpringStarterTest

/**
*
*/
package net.fp.rp.spring;

import java.util.List;

import junit.framework.TestCase;
import net.fp.rp.common.exception.RpException;
import net.fp.rp.jbpm.TestActionHandler;

import org.apache.log4j.Logger;
import org.jbpm.graph.exe.ExecutionContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

/**
* Junit test to fire off a simple workflow via Spring
* @author paul.browne
* Copyright @link www.firstpartners.net/red
*/
public class SpringStarterTest extends TestCase {

  /**
   * Where to find the Spring Context that we use for testing
   */
  public static final String TEST_APP_CONTEXT="core/test/net/fp/rp/spring/SpringStarterTest-AppContext.xml";
 
  /**
   * The Name of the Spring Bean under test
   */
  public static final String TEST_BEAN="StartWorkFlowBean";
 
   /** Logger for this class and subclasses */
    protected final Logger log = Logger.getLogger(getClass());
 
    //The application context used by this test
    ApplicationContext context = null;
   
  public void setUp() throws Exception{
   
   
    context = new FileSystemXmlApplicationContext(TEST_APP_CONTEXT);
   
  }
 
  public void testWorkflow() throws Throwable{
   
        //Start the Workflow
        SpringStarter myBean  = (SpringStarter) context.getBean(TEST_BEAN);
        myBean.startWorkflow();
   
        //Use our Special Test Handler to get information on how the workflow went
        List executionList = TestActionHandler.getPreviousExecutions();
       
        assertNotNull("Execution List should not be null",executionList);
        assertTrue("Execution List should not be empty",!executionList.isEmpty());
        assertEquals("Execution List should have three execution contexts. Actual is:"+executionList.size(),3,executionList.size());
       
       
  }
 
  public void testMappingCopy()  throws Throwable{
   
     //Start the Workflow
        SpringStarter myBean  = (SpringStarter) context.getBean(TEST_BEAN);
        myBean.startWorkflow();
   
        //Use our Special Test Handler to get information on how the workflow went
        List<ExecutionContext> executionList = TestActionHandler.getPreviousExecutions();
      
        assertEquals(executionList.get(0).getContextInstance().getVariable("Test Key 1"),"Test Value 1");
        assertEquals(executionList.get(0).getContextInstance().getVariable("Test Key 2"),"Test Value 2");
       
  }
 
  public void testWorkflowAwareOfSpring() throws Throwable{
   
     //Start the Workflow
        SpringStarter myBean  = (SpringStarter) context.getBean(TEST_BEAN);
        myBean.startWorkflow();
   
        
        //The following is only true because we make it so in the .jpdl.xml file
        assertEquals(TestActionHandler.appContext,TEST_APP_CONTEXT);
  }
 
  public void testNoStrategy() {
   
    //Get the bean
    SpringStarter myBean  = (SpringStarter) context.getBean(TEST_BEAN);
   
    //Set the strategy object to null
    myBean.setStarterStrategy(null);
   
    //now ensure that it blows up
    try{
      myBean.startWorkflow();
      fail("Expected RpException not thrown when no strategy object is in place");
    } catch (RpException rp){
      //do nothing , this is the behaviour that we expected
    }
   
   
   
  }
}
TOP

Related Classes of net.fp.rp.spring.SpringStarterTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.