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