1   /*
2    * $Id: MessagingJbpmSpringTestCase.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.config.ConfigurationBuilder;
14  import org.mule.extras.client.MuleClient;
15  import org.mule.extras.spring.config.SpringConfigurationBuilder;
16  import org.mule.providers.bpm.BPMS;
17  import org.mule.providers.bpm.tests.AbstractBpmTestCase;
18  import org.mule.umo.UMOMessage;
19  import org.mule.util.NumberUtils;
20  
21  /**
22   * Tests the connector against jBPM with a process which generates a Mule message and 
23   * processes its response.
24   * jBPM is instantiated by Spring using the Spring jBPM module.
25   */
26  public class MessagingJbpmSpringTestCase extends AbstractBpmTestCase {
27  
28      protected ConfigurationBuilder getBuilder() throws Exception {
29          return new SpringConfigurationBuilder();
30      }
31  
32      protected String getConfigResources() {
33          return "mule-jbpm-spring-config.xml";
34      }
35  
36      public void testSendMessageProcess() throws Exception {
37          // Deploy the process definition.
38          ((Jbpm) bpms).deployProcess("message-process.xml");
39  
40          UMOMessage response;
41          Object process;
42          BPMS bpms = connector.getBpms();
43          MuleClient client = new MuleClient();
44          try {
45              // Create a new process.
46              response = client.send("bpm://message", "data", null);
47              process = response.getPayload();
48  
49              long processId = NumberUtils.toLong(bpms.getId(process));
50              // The process should be started and in a wait state.
51              assertFalse(processId == -1);
52              assertEquals("sendMessage", bpms.getState(process));
53  
54              // Advance the process one step.
55              response = client.send("bpm://message/" + processId, "data", null);
56              process = response.getPayload();
57  
58              // The process should have ended.
59              assertTrue(bpms.hasEnded(process));
60          } finally {
61              client.dispose();
62          }
63      }
64  }