View Javadoc

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