View Javadoc

1   /*
2    * $Id: SimpleJbpmTestCase.java 19710 2010-09-23 16:29:07Z tcarlson $
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.transport.jbpm;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.bpm.BPMS;
15  import org.mule.module.bpm.Process;
16  import org.mule.module.client.MuleClient;
17  import org.mule.tck.FunctionalTestCase;
18  import org.mule.transport.bpm.ProcessConnector;
19  
20  /**
21   * Tests the connector against jBPM with a simple process.
22   * 
23   * @deprecated It is recommended to configure BPM as a component rather than a transport for 3.x
24   */
25  public class SimpleJbpmTestCase extends FunctionalTestCase
26  {
27  
28      protected String getConfigResources()
29      {
30          return "jbpm-functional-test.xml";
31      }
32  
33      public void testSimpleProcess() throws Exception 
34      {
35          ProcessConnector connector = (ProcessConnector) muleContext.getRegistry().lookupConnector("bpmConnector");
36          BPMS bpms = connector.getBpms();
37          assertNotNull(bpms);
38  
39          MuleClient client = new MuleClient(muleContext);
40          try
41          {
42              // Create a new process.
43              MuleMessage response = client.send("bpm://simple", "data", null);
44              Object process = response.getPayload();
45  
46              String processId = (String)bpms.getId(process);
47              // The process should be started and in a wait state.
48              assertFalse(processId == null);
49              assertEquals("dummyState", bpms.getState(process));
50  
51              // Advance the process one step.
52              response = client.send("bpm://simple/" + processId, null, null);
53              process = response.getPayload();
54  
55              // The process should have ended.
56              assertTrue(bpms.hasEnded(process));
57          }
58          finally
59          {
60              client.dispose();
61          }
62      }
63  
64      public void testSimpleProcessWithParameters() throws Exception
65      {
66          ProcessConnector connector = (ProcessConnector) muleContext.getRegistry().lookupConnector("bpmConnector");
67          BPMS bpms = connector.getBpms();
68  
69          MuleClient client = new MuleClient(muleContext);
70          try
71          {
72              // Create a new process.
73              MuleMessage response = client.send("bpm://?" +
74                                     Process.PROPERTY_ACTION + "=" + Process.ACTION_START +
75                                     "&" + Process.PROPERTY_PROCESS_TYPE + "=simple", "data", null);
76              Object process = response.getPayload();
77  
78              // The process should be started and in a wait state.
79              Object processId = bpms.getId(process);
80              assertNotNull(processId);
81              assertEquals("dummyState", bpms.getState(process));
82  
83              // Advance the process one step.
84              response = client.send("bpm://?" +
85                                     Process.PROPERTY_ACTION + "=" + Process.ACTION_ADVANCE +
86                                     "&" + Process.PROPERTY_PROCESS_TYPE + "=simple&" +
87                                     Process.PROPERTY_PROCESS_ID + "=" + processId, "data", null);
88              process = response.getPayload();
89  
90              // The process should have ended.
91              assertTrue(bpms.hasEnded(process));
92          }
93          finally
94          {
95              client.dispose();
96          }
97      }
98  }