1   /*
2    * $Id: SimpleJbpmTestCase.java 10789 2008-02-12 20:04:43Z dfeist $
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.transport.bpm.jbpm;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.transport.bpm.BPMS;
16  import org.mule.transport.bpm.ProcessConnector;
17  import org.mule.transport.bpm.jbpm.Jbpm;
18  import org.mule.util.NumberUtils;
19  
20  /**
21   * Tests the connector against jBPM with a simple process.
22   */
23  public class SimpleJbpmTestCase extends AbstractJbpmTestCase
24  {
25  
26      protected String getConfigResources()
27      {
28          return "jbpm-functional-test.xml";
29      }
30  
31      public void testSimpleProcess() throws Exception {
32          // Deploy the process definition.
33          ((Jbpm) bpms).deployProcess("simple-process.xml");
34  
35          MuleMessage 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          MuleMessage 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 }