1   /**
2    * 
3    */
4   package eu.diversit.jbpm.spring;
5   
6   import junit.framework.Assert;
7   
8   import org.jbpm.api.ProcessInstance;
9   import org.jbpm.examples.java.Hand;
10  import org.junit.Test;
11  import org.junit.runner.RunWith;
12  import org.springframework.beans.factory.annotation.Autowired;
13  import org.springframework.test.annotation.DirtiesContext;
14  import org.springframework.test.context.ContextConfiguration;
15  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
16  import org.springframework.transaction.annotation.Transactional;
17  
18  /**
19   * @author joostdenboer
20   *
21   */
22  @DirtiesContext
23  @RunWith(SpringJUnit4ClassRunner.class)
24  @ContextConfiguration(locations={"/applicationContext.xml", "/hsqldbEmbeddedDataSourceContext.xml", "/testApplicationContext.xml"})
25  @Transactional
26  public class JbpmSpringBeanTest {
27  
28  	@Autowired
29  	JbpmProcessBean testBean;
30  	
31  	@Test
32  	public void testStartProcessUsingKey() {
33  		// set key to use
34  		testBean.setProcessKey("JavaKey");
35  		
36  		Assert.assertNotNull("No JbpmProcessBean in context", testBean);
37  		Assert.assertNotNull("Process not deployed", testBean.getDeploymentId());
38  		
39  		ProcessInstance pi = testBean.startProcessInstance();
40  		
41  		Assert.assertNotNull("No ProcessDefinition", pi);
42  		System.out.println("Process state is: "+pi.getState());
43  
44  		String answer = (String) testBean.getVariable(pi.getId(),"answer");
45  	    Assert.assertEquals("I'm fine, thank you.", answer);
46  
47  	    Hand hand = (Hand) testBean.getVariable(pi.getId(), "hand");
48  	    Assert.assertTrue(hand.isShaken());
49  	    Assert.assertEquals(1, hand.getTimesShaken());
50  	    System.out.println("Times shaken = "+hand.getTimesShaken());
51  	}
52  
53  	@Test
54  	public void testStartProcessWithoutUsingKey() {
55  		
56  		Assert.assertNotNull("No JbpmProcessBean in context", testBean);
57  		Assert.assertNotNull("Process not deployed", testBean.getDeploymentId());
58  		
59  		ProcessInstance pi = testBean.startProcessInstance();
60  		
61  		Assert.assertNotNull("No ProcessDefinition", pi);
62  		System.out.println("Process state is: "+pi.getState());
63  	
64  		String answer = (String) testBean.getVariable(pi.getId(),"answer");
65  	    Assert.assertEquals("I'm fine, thank you.", answer);
66  	
67  	    Hand hand = (Hand) testBean.getVariable(pi.getId(), "hand");
68  	    Assert.assertTrue(hand.isShaken());
69  	    Assert.assertEquals(1, hand.getTimesShaken());
70  	    System.out.println("Times shaken = "+hand.getTimesShaken());
71  	}
72  }