1   /*
2    * $Id: SimpleJbpmTestCase.java 8707 2007-09-29 12:43:09Z romikk $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.providers.bpm.jbpm;
12  
13  import org.mule.extras.client.MuleClient;
14  import org.mule.providers.bpm.BPMS;
15  import org.mule.providers.bpm.ProcessConnector;
16  import org.mule.umo.UMOMessage;
17  import org.mule.util.NumberUtils;
18  
19  /**
20   * Tests the connector against jBPM with a simple process.
21   */
22  public class SimpleJbpmTestCase extends AbstractJbpmTestCase
23  {
24  
25      protected String getConfigResources()
26      {
27          return "mule-jbpm-config.xml";
28      }
29  
30      public void testSimpleProcess() throws Exception
31      {
32          // Deploy the process definition.
33          ((Jbpm) bpms).deployProcess("simple-process.xml");
34  
35          UMOMessage response;
36          Object process;
37          BPMS bpms = connector.getBpms();
38          MuleClient client = new MuleClient();
39          try
40          {
41              // Create a new process.
42              response = client.send("bpm://simple", "data", null);
43              process = response.getPayload();
44  
45              long processId = NumberUtils.toLong(bpms.getId(process));
46              // The process should be started and in a wait state.
47              assertFalse(processId == -1);
48              assertEquals("dummyState", bpms.getState(process));
49  
50              // Advance the process one step.
51              response = client.send("bpm://simple/" + processId, null, null);
52              process = response.getPayload();
53  
54              // The process should have ended.
55              assertTrue(bpms.hasEnded(process));
56          }
57          finally
58          {
59              client.dispose();
60          }
61      }
62  
63      public void testSimpleProcessWithParameters() throws Exception
64      {
65          // Deploy the process definition.
66          ((Jbpm) bpms).deployProcess("simple-process.xml");
67  
68          UMOMessage response;
69          Object process;
70          BPMS bpms = connector.getBpms();
71          MuleClient client = new MuleClient();
72          try
73          {
74              // Create a new process.
75              response = client.send("bpm://?" +
76                                     ProcessConnector.PROPERTY_ACTION + "=" + ProcessConnector.ACTION_START +
77                                     "&" + ProcessConnector.PROPERTY_PROCESS_TYPE + "=simple", "data", null);
78              process = response.getPayload();
79  
80              long processId =
81                      response.getLongProperty(ProcessConnector.PROPERTY_PROCESS_ID, -1);
82              // The process should be started and in a wait state.
83              assertFalse(processId == -1);
84              assertEquals("dummyState", bpms.getState(process));
85  
86              // Advance the process one step.
87              response = client.send("bpm://?" +
88                                     ProcessConnector.PROPERTY_ACTION + "=" + ProcessConnector.ACTION_ADVANCE +
89                                     "&" + ProcessConnector.PROPERTY_PROCESS_TYPE + "=simple&" +
90                                     ProcessConnector.PROPERTY_PROCESS_ID + "=" + processId, "data", null);
91              process = response.getPayload();
92  
93              // The process should have ended.
94              assertTrue(bpms.hasEnded(process));
95          }
96          finally
97          {
98              client.dispose();
99          }
100     }
101 }