View Javadoc

1   /*
2    * $Id: SpringJbpmComponentTestCase.java 22470 2011-07-20 09:28:00Z justin.calleja $
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 static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertFalse;
15  import static org.junit.Assert.assertNotNull;
16  import static org.junit.Assert.assertTrue;
17  
18  import java.util.Arrays;
19  import java.util.Collection;
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  import org.junit.Test;
24  import org.junit.runners.Parameterized.Parameters;
25  import org.mule.api.MuleMessage;
26  import org.mule.api.client.MuleClient;
27  import org.mule.module.bpm.BPMS;
28  import org.mule.module.bpm.Process;
29  import org.mule.tck.AbstractServiceAndFlowTestCase;
30  
31  /**
32   * Tests jBPM component with a simple process. The ProcessEngine is built by Spring
33   * and injected into the Mule wrapper.
34   */
35  public class SpringJbpmComponentTestCase extends AbstractServiceAndFlowTestCase
36  {
37  
38      public SpringJbpmComponentTestCase(ConfigVariant variant, String configResources)
39      {
40          super(variant, configResources);
41      }
42  
43      @Parameters
44      public static Collection<Object[]> parameters()
45      {
46          return Arrays.asList(new Object[][]{{ConfigVariant.SERVICE, "spring-jbpm-component-service.xml"},
47              {ConfigVariant.FLOW, "spring-jbpm-component-flow.xml"}});
48      }
49  
50      @Test
51      public void testSimpleProcess() throws Exception
52      {
53          MuleClient client = muleContext.getClient();
54          BPMS bpms = muleContext.getRegistry().lookupObject(BPMS.class);
55          assertNotNull(bpms);
56  
57          // Create a new process.
58          MuleMessage response = client.send("vm://simple", "data", null);
59          Object process = response.getPayload();
60  
61          String processId = (String) bpms.getId(process);
62          // The process should be started and in a wait state.
63          assertFalse(processId == null);
64          assertEquals("dummyState", bpms.getState(process));
65  
66          // Advance the process one step.
67          Map<String, Object> props = new HashMap<String, Object>();
68          props.put(Process.PROPERTY_PROCESS_ID, processId);
69          response = client.send("vm://simple", null, props);
70          process = response.getPayload();
71  
72          // The process should have ended.
73          assertTrue(bpms.hasEnded(process));
74      }
75  
76  }