View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.jbpm;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.module.bpm.BPMS;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  
13  import org.jbpm.api.ProcessInstance;
14  import org.junit.Test;
15  
16  import static org.junit.Assert.assertEquals;
17  import static org.junit.Assert.assertNotNull;
18  import static org.junit.Assert.assertTrue;
19  
20  public class ForkedProcessComponentTestCase extends FunctionalTestCase
21  {
22  
23      @Override
24      protected String getConfigResources()
25      {
26          return "jbpm-component-functional-test.xml";
27      }
28  
29      @Test
30      public void testForkedProcess() throws Exception 
31      {
32          BPMS bpms = muleContext.getRegistry().lookupObject(BPMS.class);
33          assertNotNull(bpms);
34  
35          // Create a new process.
36          MuleMessage response = muleContext.getClient().send("vm://fork", "data", null);                      
37          ProcessInstance process = (ProcessInstance) response.getPayload();
38          
39          // The process should be waiting for asynchronous responses from both services
40          String state = (String) bpms.getState(process);
41          assertTrue(state.contains("waitForResponseA"));
42          assertTrue(state.contains("waitForResponseB"));
43  
44          Thread.sleep(2000);
45  
46          // ServiceA is initially stopped, so we're still waiting for a response from ServiceA
47          process = (ProcessInstance) bpms.lookupProcess(process.getId());
48          assertEquals("waitForResponseA", bpms.getState(process));
49  
50          // Start ServiceA
51          muleContext.getRegistry().lookupService("ServiceA").resume();
52          Thread.sleep(2000);
53                      
54          // The process should have ended.
55          process = (ProcessInstance) bpms.lookupProcess(process.getId());
56          assertTrue("Process should have ended, but is in state " + bpms.getState(process), 
57                  bpms.hasEnded(process));
58      }
59  
60  }