[jboss-svn-commits] JBL Code SVN: r25054 - in labs/jbossesb/trunk/product: services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm and 6 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Feb 2 10:23:31 EST 2009
Author: beve
Date: 2009-02-02 10:23:30 -0500 (Mon, 02 Feb 2009)
New Revision: 25054
Added:
labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/cmd/
labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackCommandUnitTest.java
labs/jbossesb/trunk/product/services/jbpm/src/test/resources/callbackCommandUnitTest.xml
Modified:
labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/jboss-esb-unfiltered.xml
labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/Mapping.java
labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandler.java
labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackCommand.java
labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandExecutor.java
labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandlerUnitTest.java
labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/JBpmObjectMapperCallbackUnitTest.java
Log:
Work for https://jira.jboss.org/jira/browse/JBESB-2317 "Reduce verbosity of jBPM callback EPRs"
Modified: labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/jboss-esb-unfiltered.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/jboss-esb-unfiltered.xml 2009-02-02 14:56:06 UTC (rev 25053)
+++ labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/jboss-esb-unfiltered.xml 2009-02-02 15:23:30 UTC (rev 25054)
@@ -51,7 +51,7 @@
is-gateway="true" />
<fs-listener name="ESB-Listener" busidref="startEsbChannel"/>
</listeners>
- <actions>
+ <actions mep="OneWay">
<action name="spy1"
class="org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.esb_actions.MessageSpy"/>
<action name="testStore" class="org.jboss.soa.esb.actions.TestMessageStore"/>
Modified: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/Mapping.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/Mapping.java 2009-02-02 14:56:06 UTC (rev 25053)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/Mapping.java 2009-02-02 15:23:30 UTC (rev 25054)
@@ -54,6 +54,31 @@
.append(", defaultValue=").append(defaultValue).append(" ]");
return builder.toString();
}
+
+ public boolean equals(final Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (!(obj instanceof Mapping))
+ return false;
+
+ Mapping mapping = (Mapping) obj;
+ return (bpm == mapping.bpm || bpm != null && bpm.equals(mapping.bpm)) &&
+ (esb == mapping.esb || esb != null && esb.equals(mapping.esb)) &&
+ (defaultValue == mapping.defaultValue || defaultValue != null && defaultValue.equals(mapping.defaultValue)) &&
+ (isProcessScope == mapping.isProcessScope || isProcessScope != null && isProcessScope.equals(mapping.isProcessScope));
+ }
+
+ public int hashCode()
+ {
+ int hash = 7;
+ hash = 31 * hash + (null == bpm ? 0 : bpm.hashCode());
+ hash = 31 * hash + (null == esb ? 0 : esb.hashCode());
+ hash = 31 * hash + (null == defaultValue ? 0 : defaultValue.hashCode());
+ hash = 31 * hash + (null == isProcessScope ? 0 : isProcessScope.hashCode());
+ return hash;
+ }
+
/**
*
* @param mappingElement
Modified: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandler.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandler.java 2009-02-02 14:56:06 UTC (rev 25053)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandler.java 2009-02-02 15:23:30 UTC (rev 25054)
@@ -193,9 +193,6 @@
{
EPR replyTo = new LogicalEPR(ServiceInvoker.INTERNAL_SERVICE_CATEGORY, JBpmCallback.JBPM_CALL_BACK_SERVICE_NAME);
PortReference portReference = replyTo.getAddr();
- if (esbToJBpmXml!=null) {
- portReference.addExtension(Constants.ESB_TO_BPM_VARS_TAG, esbToJBpmXml);
- }
if (globalProcessScope!=null) {
portReference.addExtension(Constants.PROCESS_SCOPE_ATTR, globalProcessScope.toString());
}
Modified: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackCommand.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackCommand.java 2009-02-02 14:56:06 UTC (rev 25053)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackCommand.java 2009-02-02 15:23:30 UTC (rev 25054)
@@ -21,17 +21,27 @@
*/
package org.jboss.soa.esb.services.jbpm.cmd;
+import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
+import org.dom4j.tree.DefaultElement;
+import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.PortReference;
+import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.services.jbpm.Constants;
+import org.jboss.soa.esb.services.jbpm.JBpmObjectMapper;
import org.jboss.soa.esb.services.jbpm.Mapping;
+import org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler;
import org.jbpm.JbpmContext;
import org.jbpm.command.Command;
import org.jbpm.context.exe.ContextInstance;
+import org.jbpm.graph.def.Action;
+import org.jbpm.graph.def.Node;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;
+import org.jbpm.instantiation.Delegation;
/**
* @author kstam
@@ -39,6 +49,8 @@
*/
public class CallbackCommand implements Command {
+ private static final HashMap<Mapping, Object> EMPTY_VARIABLES_MAP = new HashMap<Mapping, Object>();
+
private static Logger logger = Logger.getLogger(CallbackCommand.class);
/**
*
@@ -54,6 +66,11 @@
*/
private Map<Mapping, Object> variables ;
+ /**
+ * The ESB Message object.
+ */
+ private Message message;
+
private EPR callbackEpr;
public CallbackCommand() {
@@ -75,26 +92,37 @@
this.variables = variables ;
}
+ public void setMessage(final Message message)
+ {
+ this.message = message;
+ }
+
+
public Object execute(JbpmContext jbpmContext)
{
final boolean isDebugEnabled = logger.isDebugEnabled() ;
try {
- long nodeId = Long.parseLong(callbackEpr.getAddr().getExtensionValue(Constants.NODE_ID));
- long tokenId = Long.parseLong(callbackEpr.getAddr().getExtensionValue(Constants.TOKEN_ID));
- long processInstanceId = Long.parseLong(callbackEpr.getAddr().getExtensionValue(Constants.PROCESS_INSTANCE_ID));
+ PortReference portRef = callbackEpr.getAddr();
+ long nodeId = Long.parseLong(portRef.getExtensionValue(Constants.NODE_ID));
+ long tokenId = Long.parseLong(portRef.getExtensionValue(Constants.TOKEN_ID));
+ long processInstanceId = Long.parseLong(portRef.getExtensionValue(Constants.PROCESS_INSTANCE_ID));
+
String counterName = Constants.PROCESS_NODE_VERSION_COUNTER + nodeId + '_' + tokenId;
- long processNodeVersion = Long.parseLong(callbackEpr.getAddr().getExtensionValue(counterName));
- if (isDebugEnabled) logger.debug("Expected nodeId=" + nodeId +
- ", tokenId=" + tokenId + ", processNodeVersion=" + processNodeVersion);
+
+ long processNodeVersion = Long.parseLong(portRef.getExtensionValue(counterName));
+
+ if (isDebugEnabled) logger.debug("Expected nodeId=" + nodeId + ", tokenId=" + tokenId + ", processNodeVersion=" + processNodeVersion);
//get update on current state of things.
final Token token = jbpmContext.getToken(tokenId) ;
if (token == null) {
throw new CallbackException("Token id " + tokenId + " from process instance " + processInstanceId + " is no longer active") ;
}
+
final ProcessInstance instance = token.getProcessInstance() ;
if (instance == null) {
throw new CallbackException("Process instance " + processInstanceId + " is no longer active") ;
}
+
if (instance.getId() != processInstanceId) {
throw new CallbackException("Token id " + tokenId + " from process instance " + processInstanceId + " now attached to process instance " + instance.getId()) ;
}
@@ -111,22 +139,86 @@
}
final ContextInstance contextInstance = instance.getContextInstance() ;
- final long currentProcessNodeVersion = Long.parseLong(String.valueOf(
- contextInstance.getVariableLocally(counterName, token)));
+ final long currentProcessNodeVersion = Long.parseLong(String.valueOf(contextInstance.getVariableLocally(counterName, token)));
if (isDebugEnabled) logger.debug("ProcessNodeVersion=" + currentProcessNodeVersion);
if (processNodeVersion!=currentProcessNodeVersion) {
- throw new CallbackException("The current processNodeVersion (id=" + currentProcessNodeVersion +
- ") is not the expected version (version=" + processNodeVersion + ").");
+ throw new CallbackException("The current processNodeVersion (id=" + currentProcessNodeVersion + ") is not the expected version (version=" + processNodeVersion + ").");
}
- final String globalProcessScopeVal = callbackEpr.getAddr().getExtensionValue(Constants.PROCESS_SCOPE_ATTR) ;
+ final String globalProcessScopeVal = portRef.getExtensionValue(Constants.PROCESS_SCOPE_ATTR) ;
// Default to global scope as that matches the previous functionality
// N.B. This is different from retrieving variables!!
final boolean globalProcessScope = (globalProcessScopeVal == null ? true : Boolean.parseBoolean(globalProcessScopeVal));
- AsyncProcessSignal.createSignalJob(jbpmContext, token, transitionName, jbpmContext.getActorId(), globalProcessScope, variables) ;
+
+ Map<Mapping, Object> variablesMap = getVariablesMapFromMessage(token.getNode(), message);
+ // Try to be backward compatible in case the variable mappings were stored in the epr and set on this CallbackCommand instance.
+ if (variables != null)
+ {
+ variablesMap.putAll(variables);
+ }
+
+ AsyncProcessSignal.createSignalJob(jbpmContext, token, transitionName, jbpmContext.getActorId(), globalProcessScope, variablesMap) ;
} catch (CallbackException jbpmCe) {
+ //TODO: Why is this only a warning?
logger.warn(jbpmCe.getMessage());
}
return null;
}
+
+ /**
+ * This method uses the information located in the jBPM nodes action definition to find out
+ * which variables have been defined there.
+ * <p/>
+ * The variables that are specified in the element 'esbToBpmVars' will be extracted from the
+ * ESB Message object and put into the retured map.
+ *
+ * For example:
+ * <pre>{@code
+ * <node name="node1">
+ * <action name="first action" class="org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler">
+ * <esbCategoryName>MockCategory</esbCategoryName>
+ * <esbServiceName>MockService</esbServiceName>
+ * <esbToBpmVars>
+ * <mapping esb="BODY_CONTENT" bpm="theBody" process-scope="false"/>
+ * </esbToBpmVars>
+ * </action>
+ * </node>
+ * }</pre>
+ *
+ * @param node The jBPM node.
+ * @param esbMessage The ESB Message object
+ * @return Map A Map with the 'esbToBpmVars' mapping as the key and the object/value of
+ * that mapping which was extracted from the ESB Message object.
+ * @throws CallbackException
+ */
+ HashMap<Mapping, Object> getVariablesMapFromMessage(final Node node, final Message esbMessage) throws CallbackException
+ {
+ final Action jbpmAction = node.getAction();
+ if (jbpmAction != null && esbMessage != null)
+ {
+ final Delegation actionDelegation = jbpmAction.getActionDelegation();
+ if (actionDelegation != null)
+ {
+ final Object delegate = actionDelegation.getInstance();
+ if (delegate instanceof EsbActionHandler)
+ {
+ final EsbActionHandler handler = (EsbActionHandler)delegate;
+ final DefaultElement esbToBpmVars = handler.esbToBpmVars;
+ if (esbToBpmVars != null)
+ {
+ try
+ {
+ return new JBpmObjectMapper().mapFromEsbMessageToJBpmMapping(esbMessage, esbToBpmVars.asXML());
+ }
+ catch (final ConfigurationException e)
+ {
+ throw new CallbackException(e.getMessage(), e);
+ }
+ }
+ }
+ }
+ }
+ return EMPTY_VARIABLES_MAP;
+ }
+
}
Modified: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandExecutor.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandExecutor.java 2009-02-02 14:56:06 UTC (rev 25053)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandExecutor.java 2009-02-02 15:23:30 UTC (rev 25054)
@@ -125,27 +125,19 @@
{
CallbackCommand command = new CallbackCommand();
EPR toEpr = message.getHeader().getCall().getTo();
- try {
- command.setCallbackEpr(toEpr);
- //Map the variables
- String esbToBpmXml = toEpr.getAddr().getExtensionValue(Constants.ESB_TO_BPM_VARS_TAG);
- JBpmObjectMapper mapper = new JBpmObjectMapper();
- //Obtaining the VariableMap that is going to be set callback command
- Map<Mapping,Object> variableMap = mapper.mapFromEsbMessageToJBpmMapping(message, esbToBpmXml);
- if (null!=variableMap) command.setVariables(variableMap);
- String transition = (toEpr.getAddr().getExtensionValue(Constants.TRANSITION_NAME));
- //The transition can be overriden if needed, by setting the following variable.
- String overriddenTransition = MessageHelper.getStringValue(message, Constants.TRANSITION_NAME);
- if (overriddenTransition!=null) {
- if (transition!=null) logger.debug("Overriding the transition to " + overriddenTransition);
- transition = overriddenTransition;
- }
- if (null!=transition) command.setTransitionName(transition);
- logger.debug("Signaling Process with Transition=" + transition + ", VariableMap=" + variableMap);
- executeJbpmCommand(command);
- } catch (ConfigurationException ce) {
- throw new JbpmException(ce.getMessage(), ce);
+ command.setCallbackEpr(toEpr);
+ command.setMessage(message);
+
+ String transition = (toEpr.getAddr().getExtensionValue(Constants.TRANSITION_NAME));
+ //The transition can be overriden if needed, by setting the following variable.
+ String overriddenTransition = MessageHelper.getStringValue(message, Constants.TRANSITION_NAME);
+ if (overriddenTransition!=null) {
+ if (transition!=null) logger.debug("Overriding the transition to " + overriddenTransition);
+ transition = overriddenTransition;
}
+ if (null!=transition) command.setTransitionName(transition);
+ logger.debug("Signaling Process with Transition=" + transition);
+ executeJbpmCommand(command);
}
};
Modified: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandlerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandlerUnitTest.java 2009-02-02 14:56:06 UTC (rev 25053)
+++ labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandlerUnitTest.java 2009-02-02 15:23:30 UTC (rev 25054)
@@ -39,7 +39,6 @@
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
public class EsbActionHandlerUnitTest
@@ -60,7 +59,6 @@
}
@Test
- @Ignore
public void testSimpleProcess() throws Exception
{
// Extract a process definition from the processdefinition.xml file.
Modified: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/JBpmObjectMapperCallbackUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/JBpmObjectMapperCallbackUnitTest.java 2009-02-02 14:56:06 UTC (rev 25053)
+++ labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/JBpmObjectMapperCallbackUnitTest.java 2009-02-02 15:23:30 UTC (rev 25054)
@@ -109,7 +109,7 @@
String esbToBpmXml = epr.getAddr().getExtensionValue(Constants.ESB_TO_BPM_VARS_TAG);
//Obtaining the VariableMap that is going to be set callback command
- Map<String,Object> variableMap = mapper.mapFromEsbMessageToJBpmMap(message, esbToBpmXml);
+ Map<String,Object> variableMap = mapper.mapFromEsbMessageToJBpmMap(message, esbToBpmVars.asXML());
logger.info(variableMap);
//Let's make sure that what we put in is going to make it roundtrip.
assertEquals(helloWorldTokenScope, variableMap.get("x1"));
Added: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackCommandUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackCommandUnitTest.java (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackCommandUnitTest.java 2009-02-02 15:23:30 UTC (rev 25054)
@@ -0,0 +1,170 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2009, Red Hat Middleware
+ * LLC, and individual contributors by the @authors tag. See the copyright.txt
+ * in the distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.services.jbpm.cmd;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.net.URI;
+import java.util.Map;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.jboss.internal.soa.esb.couriers.MockCourier;
+import org.jboss.internal.soa.esb.couriers.MockCourierFactory;
+import org.jboss.internal.soa.esb.services.registry.MockRegistry;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.PortReference;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.services.jbpm.Constants;
+import org.jboss.soa.esb.services.jbpm.Mapping;
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmContext;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.graph.exe.Token;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Unit test for {@link CallbackCommand}.
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ *
+ */
+public class CallbackCommandUnitTest
+{
+ @Test
+ public void getVariablesMap() throws CallbackException
+ {
+ final String payload = "sample payload";
+
+ final ProcessDefinition processDef = ProcessDefinition.parseXmlResource("callbackCommandUnitTest.xml");
+ final ProcessInstance instance = new ProcessInstance(processDef);
+
+ Token token = instance.getRootToken();
+ Message message = MessageFactory.getInstance().getMessage();
+ message.getBody().add(payload);
+
+ instance.signal();
+ assertEquals("node1", token.getNode().getName());
+
+ final CallbackCommand callback = new CallbackCommand();
+ Map<Mapping, Object> variablesMap = callback.getVariablesMapFromMessage(token.getNode(), message);
+
+ Mapping expectedMappning = expectedMapping(Constants.BODY_CONTENT_VARIABLE_NAME, "theBody", false, null);
+ assertEquals(payload, variablesMap.get(expectedMappning));
+ }
+
+ @Test
+ public void execute()
+ {
+ final String jbpmBodyContentKey = "theBody";
+ final String esbBodyContent = "sample payload";
+
+ final String esbXmlContentKey = "xml";
+ final String jbpmXmlContentKey = "xmlContent";
+ final String esbXmlContent = "<somexml/>";
+
+ final JbpmContext jbpmContext = JbpmConfiguration.getInstance().createJbpmContext();
+ jbpmContext.deployProcessDefinition(ProcessDefinition.parseXmlResource("callbackCommandUnitTest.xml"));
+ final ProcessDefinition processDefinition = jbpmContext.getGraphSession().findLatestProcessDefinition("callback");
+ final ProcessInstance instance = new ProcessInstance(processDefinition);
+
+ Token token = instance.getRootToken();
+ instance.signal();
+ assertEquals("node1", token.getNode().getName());
+ assertEquals(2L, token.getNode().getId());
+
+ assertNotNull(jbpmContext.getToken(instance.getProcessDefinition().getVersion()));
+
+ final CallbackCommand callback = new CallbackCommand();
+ callback.setCallbackEpr(createEpr(token));
+
+ Message message = MessageFactory.getInstance().getMessage();
+ message.getBody().add(esbBodyContent);
+ message.getBody().add(esbXmlContentKey, esbXmlContent);
+ callback.setMessage(message);
+
+ callback.execute(jbpmContext);
+
+ assertEquals(esbBodyContent, token.getProcessInstance().getContextInstance().getVariable(jbpmBodyContentKey));
+ assertEquals(esbXmlContent, token.getProcessInstance().getContextInstance().getVariable(jbpmXmlContentKey));
+ }
+
+ private Mapping expectedMapping(final String esb, final String bpm, final boolean processScope, final String defaultVal)
+ {
+ Mapping expectedMappning = new Mapping();
+ expectedMappning.setBpm("theBody");
+ expectedMappning.setEsb("BODY_CONTENT");
+ expectedMappning.setIsProcessScope(false);
+ expectedMappning.setDefaultValue(null);
+ return expectedMappning;
+ }
+
+ private EPR createEpr(final Token token)
+ {
+ ProcessInstance instance = token.getProcessInstance();
+
+ final EPR epr = new EPR();
+ final PortReference portRef = epr.getAddr();
+ final long nodeId = token.getNode().getId();
+ final long tokenId = token.getId();
+ final long processVersion = instance.getProcessDefinition().getVersion();
+
+ portRef.addExtension(Constants.NODE_ID, String.valueOf(nodeId));
+ portRef.addExtension(Constants.TOKEN_ID, String.valueOf(tokenId));
+ portRef.addExtension(Constants.PROCESS_INSTANCE_ID, String.valueOf(instance.getId()));
+
+ // Set the counter
+ String counterName = Constants.PROCESS_NODE_VERSION_COUNTER + nodeId + '_' + tokenId;
+ portRef.addExtension(counterName, String.valueOf(processVersion));
+
+ // The counterName variable is expected to be found in the process context.
+ instance.getContextInstance().setVariableLocally(counterName, processVersion);
+ return epr;
+ }
+
+ @BeforeClass
+ public static void setup() throws Exception
+ {
+ MockCourierFactory.install();
+ MockRegistry.install();
+ EPR epr1 = new EPR(new URI("test1"));
+ MockCourier courier1 = new MockCourier(true);
+ MockRegistry.register("MockCategory", "MockService", epr1, courier1);
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ MockCourierFactory.uninstall();
+ MockRegistry.uninstall();
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(CallbackCommandUnitTest.class);
+ }
+
+}
Added: labs/jbossesb/trunk/product/services/jbpm/src/test/resources/callbackCommandUnitTest.xml
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/test/resources/callbackCommandUnitTest.xml (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/test/resources/callbackCommandUnitTest.xml 2009-02-02 15:23:30 UTC (rev 25054)
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process-definition xmlns="urn:jbpm.org:jpdl-3.2" name="callback">
+
+ <start-state name="start">
+ <transition name="ok" to="node1"></transition>
+ </start-state>
+
+ <node name="node1">
+ <action name="first action" class="org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler">
+ <esbCategoryName>MockCategory</esbCategoryName>
+ <esbServiceName>MockService</esbServiceName>
+ <esbToBpmVars>
+ <mapping esb="BODY_CONTENT" bpm="theBody" process-scope="false"/>
+ <mapping esb="xml" bpm="xmlContent" process-scope="false"/>
+ </esbToBpmVars>
+ </action>
+ <transition to="child1"></transition>
+ </node>
+
+ <fork name="fork">
+ <transition to="child1"/>
+ <transition to="child2"/>
+ </fork>
+
+ <node name="child1">
+ <action name="child1SendToESB" class="org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler">
+ <esbCategoryName>MockCategory</esbCategoryName>
+ <esbServiceName>MockService</esbServiceName>
+ <bpmToEsbVars>
+ <mapping bpm="theBody" esb="BODY_CONTENT" process-scope="false"/>
+ </bpmToEsbVars>
+ <esbToBpmVars>
+ <mapping esb="BODY_CONTENT" bpm="theBody" process-scope="false"/>
+ </esbToBpmVars>
+ </action>
+ <transition to="end"/>
+ </node>
+
+ <node name="child2">
+ <action name="child2SendToESB" class="org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler">
+ <esbCategoryName>MockCategory</esbCategoryName>
+ <esbServiceName>MockService</esbServiceName>
+ <bpmToEsbVars>
+ <mapping bpm="theBody" esb="BODY_CONTENT" process-scope="false"/>
+ </bpmToEsbVars>
+ <esbToBpmVars>
+ <mapping esb="BODY_CONTENT" bpm="theBody" process-scope="false"/>
+ </esbToBpmVars>
+ </action>
+ <transition to="end"/>
+ </node>
+
+ <end-state name="end"/>
+</process-definition>
+
\ No newline at end of file
More information about the jboss-svn-commits
mailing list