[jboss-svn-commits] JBL Code SVN: r11731 - in labs/jbossesb/trunk/product: services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon May 7 22:57:39 EDT 2007
Author: estebanschifman
Date: 2007-05-07 22:57:38 -0400 (Mon, 07 May 2007)
New Revision: 11731
Added:
labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/processDefinition2/gpd.xml
labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/processDefinition2/processimage.jpg
labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbAction2.java
labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/
labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbAction2UnitTest.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/resources/testMappingDefinition.xml
Removed:
labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/EsbActionHandlerUnitTest.java
Modified:
labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/processDefinition2/processdefinition.xml
Log:
New EsbAction2 jBPM ActionHandler with better xml configuration
Added: labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/processDefinition2/gpd.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/processDefinition2/gpd.xml (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/processDefinition2/gpd.xml 2007-05-08 02:57:38 UTC (rev 11731)
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process-diagram name="processDefinition2" width="688" height="577">
+ <node name="start" x="0" y="0" width="140" height="40">
+ <transition name="">
+ <label x="5" y="-10"/>
+ </transition>
+ </node>
+ <node name="node1" x="0" y="0" width="140" height="40">
+ <transition name="">
+ <label x="5" y="-10"/>
+ </transition>
+ </node>
+ <node name="node2" x="0" y="0" width="140" height="40">
+ <transition name="">
+ <label x="5" y="-10"/>
+ </transition>
+ </node>
+ <node name="node3" x="0" y="0" width="140" height="40">
+ <transition name="">
+ <label x="5" y="-10"/>
+ </transition>
+ </node>
+ <node name="end1" x="0" y="0" width="140" height="40"/>
+ <node name="Send Results" x="0" y="0" width="140" height="40">
+ <transition name="">
+ <label x="5" y="-10"/>
+ </transition>
+ </node>
+</process-diagram>
Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/processDefinition2/gpd.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:eol-style
+ native
Modified: labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/processDefinition2/processdefinition.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/processDefinition2/processdefinition.xml 2007-05-08 01:34:16 UTC (rev 11730)
+++ labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/processDefinition2/processdefinition.xml 2007-05-08 02:57:38 UTC (rev 11731)
@@ -16,10 +16,10 @@
<esbServiceName>Service1</esbServiceName>
<millisToWaitForResponse>5000</millisToWaitForResponse>
<jbpmToEsbVars>
- <variable jbpm-name="theBody" esb-name="BODY_CONTENT" />
+ <mapping jbpm-name="theBody" esb-name="BODY_CONTENT" />
</jbpmToEsbVars>
<returnVars>
- <variable jbpm-name="theBody" esb-name="BODY_CONTENT" />
+ <mapping jbpm-name="theBody" esb-name="BODY_CONTENT" />
</returnVars>
</action>
</event>
@@ -32,10 +32,10 @@
<esbServiceName>Service2</esbServiceName>
<millisToWaitForResponse>5000</millisToWaitForResponse>
<jbpmToEsbVars>
- <variable jbpm-name="theBody" esb-name="BODY_CONTENT" />
+ <mapping jbpm-name="theBody" esb-name="BODY_CONTENT" />
</jbpmToEsbVars>
<returnVars>
- <variable jbpm-name="theBody" esb-name="BODY_CONTENT" />
+ <mapping jbpm-name="theBody" esb-name="BODY_CONTENT" />
</returnVars>
</action>
</event>
@@ -48,10 +48,10 @@
<esbServiceName>Service3</esbServiceName>
<millisToWaitForResponse>5000</millisToWaitForResponse>
<jbpmToEsbVars>
- <variable jbpm-name="theBody" esb-name="BODY_CONTENT" />
+ <mapping jbpm-name="theBody" esb-name="BODY_CONTENT" />
</jbpmToEsbVars>
<returnVars>
- <variable jbpm-name="theBody" esb-name="BODY_CONTENT" />
+ <mapping jbpm-name="theBody" esb-name="BODY_CONTENT" />
</returnVars>
</action>
</event>
@@ -66,10 +66,10 @@
<esbServiceName>ResultsService</esbServiceName>
<millisToWaitForResponse>5000</millisToWaitForResponse>
<jbpmToEsbVars>
- <variable jbpm-name="theBody" esb-name="BODY_CONTENT" />
+ <mapping jbpm-name="theBody" esb-name="BODY_CONTENT" />
</jbpmToEsbVars>
<returnVars>
- <variable jbpm-name="theBody" esb-name="BODY_CONTENT" />
+ <mapping jbpm-name="theBody" esb-name="BODY_CONTENT" />
</returnVars>
</action>
</event>
Added: labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/processDefinition2/processimage.jpg
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/processDefinition2/processimage.jpg
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbAction2.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbAction2.java (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbAction2.java 2007-05-08 02:57:38 UTC (rev 11731)
@@ -0,0 +1,261 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * 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.actionhandlers;
+
+import java.net.URI;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.log4j.Logger;
+import org.dom4j.Element;
+import org.dom4j.tree.DefaultElement;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.listeners.message.Invoker;
+import org.jboss.soa.esb.message.Body;
+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.util.Helper;
+import org.jbpm.context.exe.ContextInstance;
+import org.jbpm.graph.def.ActionHandler;
+import org.jbpm.graph.def.Node;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ExecutionContext;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.graph.exe.Token;
+
+/**
+ *
+ * Send messages to ESB services from jBPM applications, and optionally wait for response.
+ * <li/>esbCategoryName - for ESB registry lookup
+ * <li/>esbServiceName - for ESB registry lookup
+ * <li>millisToWaitForResponse - if a value > 0 is supplied, a response will be expected from the ESB service
+ * and maximum wait time will be set accordingly. If response is not received, a CourierTimeoutException will
+ * be thrown
+ * </li>
+ *
+ * @author <a href="mailto:schifest at heuristica.com.ar">Esteban</a>
+ *
+ */
+
+public class EsbAction2 implements ActionHandler
+{
+ public static final String OUTGOING_VARS_TAG = "jbpmToEsbVars";
+ public static final String RETURN_VARS_TAG = "returnVars";
+ public static final String MAPPING_TAG = "mapping";
+ public static final String JBPM_NAME_ATTR = "jbpm-name";
+ public static final String ESB_NAME_ATTR = "esb-name";
+ public static final String PROCESS_SCOPE_ATTR = "process-scope";
+
+ private static final long serialVersionUID = 1L;
+
+ public String esbCategoryName;
+ public String esbServiceName;
+ public Integer millisToWaitForResponse;
+ public Boolean globalProcessScope;
+ public DefaultElement jbpmToEsbVars;
+ public DefaultElement returnVars;
+
+ protected Logger _logger = Logger.getLogger(getClass());
+
+ protected Map<String, String>_outVarMapping;
+ protected Map<String, String>_retVarMapping;
+ protected transient Token _token;
+
+ public void execute(ExecutionContext executionContext) throws Exception
+ {
+ _token = executionContext.getToken();
+
+ Message request = getMessageTemplate();
+ varsToRequest(request);
+ if (null==millisToWaitForResponse || millisToWaitForResponse < 1)
+ {
+ Invoker.invoke(request,esbCategoryName, esbServiceName);
+ return;
+ }
+
+ Message response = null;
+ if ("MOCK_CATEGORY".equals(esbCategoryName)
+ && "MOCK_SERVICE".equals(esbServiceName))
+ response = request;
+ else
+ Invoker.invokeAndAwaitResponse (request,esbCategoryName, esbServiceName, millisToWaitForResponse);
+ if (null!=response)
+ varsFromResponse(response);
+ } //________________________________
+
+ protected void varsToRequest(Message request)
+ throws Exception
+ {
+ ContextInstance ctxInstance = _token.getProcessInstance().getContextInstance();
+ Body body = request.getBody();
+ boolean gblPrcScope = (null==globalProcessScope)
+ ? false : globalProcessScope;
+ if (null==jbpmToEsbVars)
+ {
+ Map map = (gblPrcScope)? ctxInstance.getVariables()
+ : ctxInstance.getVariables(_token);
+ if (null!=map)
+ for (Iterator iter=map.entrySet().iterator(); iter.hasNext();)
+ {
+ Map.Entry curr = (Map.Entry)iter.next();
+ body.add(curr.getKey().toString(), curr.getValue());
+ }
+ return;
+ }
+ List list = jbpmToEsbVars.elements(MAPPING_TAG);
+ // do nothing if empty list
+ if (list.size()<1 )
+ return;
+
+ for (Object iter: list)
+ {
+ Element curr = (Element)iter;
+ String jbpmKey = curr.attributeValue(JBPM_NAME_ATTR);
+ String esbKey = curr.attributeValue(ESB_NAME_ATTR);
+ String processScope = curr.attributeValue(PROCESS_SCOPE_ATTR);
+ boolean isPrcScope = (null==processScope) ? gblPrcScope
+ : Boolean.parseBoolean(processScope);
+ Object obj = (isPrcScope)
+ ? ctxInstance.getVariable(jbpmKey)
+ : ctxInstance.getVariable(jbpmKey, _token);
+ if (null!=obj)
+ {
+ if(Constants.BODY_CONTENT_VARIABLE_NAME.equals(esbKey))
+ {
+ if (obj instanceof byte[])
+ body.setContents((byte[])obj);
+ else
+ body.setContents(obj.toString().getBytes());
+ }
+ else
+ body.add(esbKey, obj);
+ }
+ }
+ } //________________________________
+
+ protected void varsFromResponse(Message response) throws Exception
+ {
+ ContextInstance ctxInstance = _token.getProcessInstance().getContextInstance();
+ Body body = response.getBody();
+ boolean gblPrcScope = (null==globalProcessScope)
+ ? false : globalProcessScope;
+ if (null==returnVars)
+ {
+ Map map = (gblPrcScope)? ctxInstance.getVariables()
+ : ctxInstance.getVariables(_token);
+ if (null!=map)
+ for (Iterator iter=map.keySet().iterator(); iter.hasNext();)
+ {
+ String key = iter.next().toString();
+ Object obj = body.get(key);
+ if (null!=obj)
+ {
+ if (gblPrcScope)
+ ctxInstance.setVariable(key, obj);
+ else
+ ctxInstance.setVariable(key, obj, _token);
+ }
+ }
+ return;
+ }
+ List list = returnVars.elements(MAPPING_TAG);
+ // do nothing if empty list
+ if (list.size()<1 )
+ return;
+
+ for (Object iter: list)
+ {
+ Element curr = (Element)iter;
+ String jbpmVar = curr.attributeValue(JBPM_NAME_ATTR);
+ String esbVar = curr.attributeValue(ESB_NAME_ATTR);
+ String processScope = curr.attributeValue(PROCESS_SCOPE_ATTR);
+ boolean isPrcScope = (null==processScope) ? gblPrcScope
+ : Boolean.parseBoolean(processScope);
+ Object obj = (Constants.BODY_CONTENT_VARIABLE_NAME.equals(esbVar))
+ ?body.getContents()
+ :body.get(esbVar);
+ Object oldVal = (isPrcScope) ? ctxInstance.getVariable(jbpmVar)
+ : ctxInstance.getVariable(jbpmVar,_token);
+ if (null==oldVal)
+ {
+ if (null!=obj)
+ {
+ if (isPrcScope)
+ ctxInstance.createVariable(jbpmVar, obj);
+ else
+ ctxInstance.createVariable(jbpmVar, obj, _token);
+ }
+ }
+ else
+ {
+ if (null==obj)
+ {
+ if (isPrcScope)
+ ctxInstance.deleteVariable(jbpmVar);
+ else
+ ctxInstance.deleteVariable(jbpmVar, _token);
+ }
+ else
+ {
+ if (isPrcScope)
+ ctxInstance.setVariable(jbpmVar,obj);
+ else
+ ctxInstance.setVariable(jbpmVar,obj,_token);
+ }
+ }
+ }
+ } //________________________________
+
+ protected Message getMessageTemplate() throws Exception
+ {
+ if (null==esbCategoryName)
+ throw new ConfigurationException("Service category (esbCategoryName element) must not be null");
+ if (null==esbServiceName)
+ throw new ConfigurationException("Service name (esbServiceName element) must not be null");
+
+ Message template = MessageFactory.getInstance().getMessage();
+ Call call = template.getHeader().getCall();
+ call.setMessageID(new URI(UUID.randomUUID().toString()));
+
+ Helper.setLongValue (template,Constants.TOKEN_ID,_token.getId());
+ Node node = _token.getNode();
+ if (null!=node)
+ Helper.setStringValue(template, Constants.CURRENT_NODE_NAME, node.getName());
+
+ ProcessInstance instance = _token.getProcessInstance();
+ Helper.setLongValue(template,Constants.PROCESS_INSTANCE_ID,instance.getId());
+
+ ProcessDefinition process = instance.getProcessDefinition();
+ Helper.setObjectValue(template ,Constants.PROCESS_DEFINITION_NAME, process.getName());
+ Helper.setIntValue (template ,Constants.PROCESS_DEFINITION_VERSION, process.getVersion());
+ Helper.setLongValue (template ,Constants.PROCESS_DEFINITION_ID, process.getId());
+
+
+ return template;
+ } //________________________________
+
+}
Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbAction2.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbAction2UnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbAction2UnitTest.java (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbAction2UnitTest.java 2007-05-08 02:57:38 UTC (rev 11731)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * 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.actionhandlers;
+
+import java.io.File;
+
+import junit.framework.JUnit4TestAdapter;
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
+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;
+
+public class EsbAction2UnitTest extends TestCase
+{
+
+ private static Class thisClass = EsbAction2UnitTest.class;
+ static Logger _logger = Logger.getLogger(thisClass);
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(thisClass);
+ }
+
+ static File WORKDIR;
+ static
+ {
+ String os = System.getProperty("os.name","").toLowerCase();
+ String dflt = (os.indexOf("win")>=0) ? "/temp": "/tmp";
+ WORKDIR = new File(System.getProperty("java.io.tmpdir",dflt));
+ }
+
+ @BeforeClass
+ public static void runBeforeAllTests()
+ {
+ _logger.info("@BeforeClass invoked");
+ try
+ {
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+
+ @AfterClass
+ public static void runAfterAllTests() throws Exception
+ {
+ _logger.info("@AfterClass invoked");
+ }
+
+ @Test
+ public void testSimpleProcess() throws Exception
+ {
+ // Extract a process definition from the processdefinition.xml file.
+ ProcessDefinition processDefinition
+ = ProcessDefinition.parseXmlResource("testMappingDefinition.xml");
+ assertTrue("Definition should not be null", null!=processDefinition);
+
+ // Create an instance of the process definition.
+ ProcessInstance instance = new ProcessInstance(processDefinition);
+ assertTrue(
+ "Instance is in start state",
+ instance.getRootToken().getNode().getName().equals("start"));
+
+ String varVal = "HELLO world";
+ String second = "Second Hello";
+ String body = "This text in Message body";
+
+ Token token = instance.getRootToken();
+ instance.getContextInstance().createVariable("v1", varVal, token);
+ instance.getContextInstance().createVariable("g2", second);
+ instance.getContextInstance().createVariable("body", body.getBytes(),token);
+ instance.signal();
+
+ assertTrue(
+ "Instance is in first state",
+ instance.getRootToken().getNode().getName().equals("first"));
+
+ _logger.info("Instance Var x1= "+varVal);
+ assertTrue(varVal.equals(instance.getContextInstance().getVariable("x1")));
+ _logger.info("Token Var x2= "+second);
+ assertTrue(second.equals(instance.getContextInstance().getVariable("x2",instance.getRootToken())));
+ _logger.info("Token Var x3= "+body);
+ assertTrue(body.equals(new String((byte[])instance.getContextInstance().getVariable("x3",instance.getRootToken()))));
+
+ instance.signal();
+ assertTrue(
+ "Instance is in end state",
+ instance.getRootToken().getNode().getName().equals("end"));
+ assertTrue("Instance has ended", instance.hasEnded());
+ }
+
+}
Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbAction2UnitTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandlerUnitTest.java (from rev 11713, labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/EsbActionHandlerUnitTest.java)
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandlerUnitTest.java (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandlerUnitTest.java 2007-05-08 02:57:38 UTC (rev 11731)
@@ -0,0 +1,266 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * 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.actionhandlers;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.jbpm.Constants;
+import org.jboss.soa.esb.services.jbpm.actions.BpmProcessor;
+import org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler;
+import org.jboss.soa.esb.services.jbpm.actions.JbpmTestUtil;
+import org.jboss.soa.esb.services.jbpm.util.Helper;
+import org.jbpm.context.exe.ContextInstance;
+import org.jbpm.graph.exe.ExecutionContext;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.graph.exe.Token;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+/**
+ * Test the EsbActionHandler class
+ *
+ * @author <a href="mailto:schifest at heuristica.com.ar">Esteban</a>
+ */
+
+
+public class EsbActionHandlerUnitTest
+{
+
+ private static Class thisClass = EsbActionHandlerUnitTest.class;
+ static Logger _logger = Logger.getLogger(thisClass);
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(thisClass);
+ }
+
+ static File WORKDIR;
+ static
+ {
+ String os = System.getProperty("os.name","").toLowerCase();
+ String dflt = (os.indexOf("win")>=0) ? "/temp": "/tmp";
+ WORKDIR = new File(System.getProperty("java.io.tmpdir",dflt));
+ }
+
+ @BeforeClass
+ public static void runBeforeAllTests()
+ {
+ _logger.info("@BeforeClass invoked");
+ try
+ {
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+
+ @AfterClass
+ public static void runAfterAllTests() throws Exception
+ {
+ _logger.info("@AfterClass invoked");
+ }
+
+ @Test
+ public void mockTest()
+ {
+ // place holder so test will run even with no other @Test
+ _logger.info("Mock test invoked");
+ assertTrue(true);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testEsbActionHandler()
+ {
+ Message msg=null;
+ MyEsbActionHandler handler = null;
+
+ for(Boolean processVars: new boolean[]{false,true})
+ try
+ {
+ // use the same config as the BpmProcessorUnitTest
+ String xml = JbpmTestUtil.stringFromFile("testSingleCommands.xml");
+ ConfigTree[] actions = ConfigTree.fromXml(xml).getChildren("action");
+
+ // create a process def
+ BpmProcessor command = new BpmProcessor(actions[0]);
+ command.process(Helper.commandMessageTemplate());
+
+ // create a process instance
+ command = new BpmProcessor(actions[1]);
+ msg = command.process(Helper.commandMessageTemplate());
+ ProcessInstance inst = (ProcessInstance)msg.getBody()
+ .get(Constants.JBPM_RETURN_OBJECT);
+
+ Token token = inst.getRootToken();
+ ContextInstance ctx = inst.getContextInstance();
+
+ handler = getHandler(token, "No variables - No mappings - no response",processVars);
+ handler.execute(null);
+
+ handler = getHandler(token,"V3 and V2 - No mappings - no response",processVars);
+ handler.jbpmToEsb_variables="jbV3,jbV2";
+ handler.execute(null);
+
+ handler = getHandler(token,"V3 and V2 mapped - no response",processVars);
+ handler.jbpmToEsb_variables="jbV3,jbV2";
+ handler.jbpmToEsb_esbNames="esbV3,esbV2";
+ handler.execute(null);
+
+ handler = getHandler(token, "No variables - No mappings - Response expected",processVars);
+ handler.millisToWaitForResponse=1;
+ handler.execute(null);
+ assertTrue((s_varMap.get("jbV1")+"_P").equals(ctx.getVariable("jbV1",token)));
+ assertTrue((s_varMap.get("jbV2")+"_P").equals(ctx.getVariable("jbV2",token)));
+ assertTrue((s_varMap.get("jbV3")+"_P").equals(ctx.getVariable("jbV3",token)));
+
+ handler = getHandler(token,"All variables mapped both ways - Response expected",processVars);
+ handler.jbpmToEsb_variables="jbV3,jbV2,jbV1";
+ handler.jbpmToEsb_esbNames="esbV3,esbV2,esbV1";
+ handler.millisToWaitForResponse=1;
+
+ handler.return_esbNames="esbV1,esbV2,esbV3";
+ handler.return_variables="jbV1,jbV2,jbV3";
+
+ handler.execute(null);
+ assertTrue((s_varMap.get("jbV1")+"_P").equals(ctx.getVariable("jbV1",token)));
+ assertTrue((s_varMap.get("jbV2")+"_P").equals(ctx.getVariable("jbV2",token)));
+ assertTrue((s_varMap.get("jbV3")+"_P").equals(ctx.getVariable("jbV3",token)));
+
+ handler = getHandler(token,"V1 mapped both ways (trick j1 to e3 and back) - Response expected",processVars);
+ handler.jbpmToEsb_variables="jbV1";
+ handler.jbpmToEsb_esbNames="esbV3";
+ handler.return_esbNames="esbV3";
+ handler.return_variables="jbV1";
+ handler.millisToWaitForResponse=1;
+ handler.execute(null);
+ assertTrue((s_varMap.get("jbV1")+"_P").equals(ctx.getVariable("jbV1",token)));
+ assertTrue(s_varMap.get("jbV2").equals(ctx.getVariable("jbV2",token)));
+ assertTrue(s_varMap.get("jbV3").equals(ctx.getVariable("jbV3",token)));
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+ } //________________________________
+
+ private static MyEsbActionHandler getHandler(Token token, String title, boolean processVars)
+ {
+ Iterator iter=null;
+
+ ContextInstance ctxInstance = token.getProcessInstance().getContextInstance();
+
+ iter = ctxInstance.getVariables(token).keySet().iterator();
+ while (iter.hasNext())
+ ctxInstance.deleteVariable((String)iter.next(),token);
+
+ iter = ctxInstance.getVariables().keySet().iterator();
+ while (iter.hasNext())
+ ctxInstance.deleteVariable((String)iter.next());
+
+ ctxInstance.addVariables(s_varMap,token);
+
+ MyEsbActionHandler handler = new MyEsbActionHandler(title,processVars);
+ handler.setToken(token);
+
+ return handler;
+ } //________________________________
+
+ private static final String[] s_vars =
+ {"jbV1","jbV2","jbV3","esbV1","esbV2","esbV3"};
+ private static final Map<String,Object> s_varMap = new HashMap<String, Object>();
+ static
+ {
+ s_varMap.put("jbV1","1");
+ s_varMap.put("jbV2","22");
+ s_varMap.put("jbV3","333");
+ };
+ private static void dumpMessage(String title, Message msg) throws Exception
+ {
+ StringBuilder sb = new StringBuilder("\n---").append(title).append("---");
+ Body body = msg.getBody();
+ for (String curr:s_vars)
+ sb.append(" ").append(curr).append("=").append(body.get(curr));
+ System.out.println(sb);
+ }
+
+ private static class MyEsbActionHandler extends EsbActionHandler
+ {
+ public static final long serialVersionUID = 1L;
+ public void setToken(Token token) {_token = token; }
+
+ public MyEsbActionHandler(String title, boolean processLevelVars)
+ {
+ String level = (processLevelVars)?"PROCESS VARS ":"TOKEN VARS";
+ System.out.println(level+" "+title);
+ esbCategoryName = "mockCategory";
+ esbServiceName = "mockServiceName";
+ processVariables = processLevelVars;
+ }
+
+
+ // this is a mock execute method to avoid need of ESB running for
+ // the unit test
+ @Override
+ public void execute(ExecutionContext ctx) throws Exception
+ {
+ // Does the same as the real one, but does not go to ESB
+ Message request = getMessageTemplate();
+ varsToRequest(request);
+ dumpMessage("Request ",request);
+
+ if (null!=millisToWaitForResponse && millisToWaitForResponse > 0)
+ {
+ Body body = request.getBody();
+ for(String curr:s_vars)
+ {
+ String val = (String)body.get(curr);
+ if (null!=val)
+ body.add(curr, val+"_P");
+ }
+
+ dumpMessage("Response ",request);
+ varsFromResponse(request);
+ }
+ System.out.println("______________________________________");
+ }
+ };
+}
\ No newline at end of file
Deleted: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/EsbActionHandlerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/EsbActionHandlerUnitTest.java 2007-05-08 01:34:16 UTC (rev 11730)
+++ labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/EsbActionHandlerUnitTest.java 2007-05-08 02:57:38 UTC (rev 11731)
@@ -1,264 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and individual contributors as indicated
- * 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.actions;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import junit.framework.JUnit4TestAdapter;
-
-import org.apache.log4j.Logger;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.message.Body;
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.services.jbpm.Constants;
-import org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler;
-import org.jboss.soa.esb.services.jbpm.util.Helper;
-import org.jbpm.context.exe.ContextInstance;
-import org.jbpm.graph.exe.ExecutionContext;
-import org.jbpm.graph.exe.ProcessInstance;
-import org.jbpm.graph.exe.Token;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-
-/**
- * Test the EsbActionHandler class
- *
- * @author <a href="mailto:schifest at heuristica.com.ar">Esteban</a>
- */
-
-
-public class EsbActionHandlerUnitTest
-{
-
- private static Class<EsbActionHandlerUnitTest> thisClass = EsbActionHandlerUnitTest.class;
- static Logger _logger = Logger.getLogger(thisClass);
-
- public static junit.framework.Test suite()
- {
- return new JUnit4TestAdapter(thisClass);
- }
-
- static File WORKDIR;
- static
- {
- String os = System.getProperty("os.name","").toLowerCase();
- String dflt = (os.indexOf("win")>=0) ? "/temp": "/tmp";
- WORKDIR = new File(System.getProperty("java.io.tmpdir",dflt));
- }
-
- @BeforeClass
- public static void runBeforeAllTests()
- {
- _logger.info("@BeforeClass invoked");
- try
- {
- }
- catch (Exception e)
- {
- e.printStackTrace();
- assertTrue(false);
- }
- }
-
-
- @AfterClass
- public static void runAfterAllTests() throws Exception
- {
- _logger.info("@AfterClass invoked");
- }
-
- @Test
- public void mockTest()
- {
- // place holder so test will run even with no other @Test
- _logger.info("Mock test invoked");
- assertTrue(true);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testEsbActionHandler()
- {
- Message msg=null;
- MyEsbActionHandler handler = null;
-
- for(Boolean processVars: new boolean[]{false,true})
- try
- {
- // use the same config as the BpmProcessorUnitTest
- String xml = JbpmTestUtil.stringFromFile("testSingleCommands.xml");
- ConfigTree[] actions = ConfigTree.fromXml(xml).getChildren("action");
-
- // create a process def
- BpmProcessor command = new BpmProcessor(actions[0]);
- command.process(Helper.commandMessageTemplate());
-
- // create a process instance
- command = new BpmProcessor(actions[1]);
- msg = command.process(Helper.commandMessageTemplate());
- ProcessInstance inst = (ProcessInstance)msg.getBody()
- .get(Constants.JBPM_RETURN_OBJECT);
-
- Token token = inst.getRootToken();
- ContextInstance ctx = inst.getContextInstance();
-
- handler = getHandler(token, "No variables - No mappings - no response",processVars);
- handler.execute(null);
-
- handler = getHandler(token,"V3 and V2 - No mappings - no response",processVars);
- handler.jbpmToEsb_variables="jbV3,jbV2";
- handler.execute(null);
-
- handler = getHandler(token,"V3 and V2 mapped - no response",processVars);
- handler.jbpmToEsb_variables="jbV3,jbV2";
- handler.jbpmToEsb_esbNames="esbV3,esbV2";
- handler.execute(null);
-
- handler = getHandler(token, "No variables - No mappings - Response expected",processVars);
- handler.millisToWaitForResponse=1;
- handler.execute(null);
- assertTrue((s_varMap.get("jbV1")+"_P").equals(ctx.getVariable("jbV1",token)));
- assertTrue((s_varMap.get("jbV2")+"_P").equals(ctx.getVariable("jbV2",token)));
- assertTrue((s_varMap.get("jbV3")+"_P").equals(ctx.getVariable("jbV3",token)));
-
- handler = getHandler(token,"All variables mapped both ways - Response expected",processVars);
- handler.jbpmToEsb_variables="jbV3,jbV2,jbV1";
- handler.jbpmToEsb_esbNames="esbV3,esbV2,esbV1";
- handler.millisToWaitForResponse=1;
-
- handler.return_esbNames="esbV1,esbV2,esbV3";
- handler.return_variables="jbV1,jbV2,jbV3";
-
- handler.execute(null);
- assertTrue((s_varMap.get("jbV1")+"_P").equals(ctx.getVariable("jbV1",token)));
- assertTrue((s_varMap.get("jbV2")+"_P").equals(ctx.getVariable("jbV2",token)));
- assertTrue((s_varMap.get("jbV3")+"_P").equals(ctx.getVariable("jbV3",token)));
-
- handler = getHandler(token,"V1 mapped both ways (trick j1 to e3 and back) - Response expected",processVars);
- handler.jbpmToEsb_variables="jbV1";
- handler.jbpmToEsb_esbNames="esbV3";
- handler.return_esbNames="esbV3";
- handler.return_variables="jbV1";
- handler.millisToWaitForResponse=1;
- handler.execute(null);
- assertTrue((s_varMap.get("jbV1")+"_P").equals(ctx.getVariable("jbV1",token)));
- assertTrue(s_varMap.get("jbV2").equals(ctx.getVariable("jbV2",token)));
- assertTrue(s_varMap.get("jbV3").equals(ctx.getVariable("jbV3",token)));
-
- }
- catch (Exception e)
- {
- e.printStackTrace();
- assertTrue(false);
- }
- } //________________________________
-
- private static MyEsbActionHandler getHandler(Token token, String title, boolean processVars)
- {
- Iterator iter=null;
-
- ContextInstance ctxInstance = token.getProcessInstance().getContextInstance();
-
- iter = ctxInstance.getVariables(token).keySet().iterator();
- while (iter.hasNext())
- ctxInstance.deleteVariable((String)iter.next(),token);
-
- iter = ctxInstance.getVariables().keySet().iterator();
- while (iter.hasNext())
- ctxInstance.deleteVariable((String)iter.next());
-
- ctxInstance.addVariables(s_varMap,token);
-
- MyEsbActionHandler handler = new MyEsbActionHandler(title,processVars);
- handler.setToken(token);
-
- return handler;
- } //________________________________
-
- private static final String[] s_vars =
- {"jbV1","jbV2","jbV3","esbV1","esbV2","esbV3"};
- private static final Map<String,Object> s_varMap = new HashMap<String, Object>();
- static
- {
- s_varMap.put("jbV1","1");
- s_varMap.put("jbV2","22");
- s_varMap.put("jbV3","333");
- };
- private static void dumpMessage(String title, Message msg) throws Exception
- {
- StringBuilder sb = new StringBuilder("\n---").append(title).append("---");
- Body body = msg.getBody();
- for (String curr:s_vars)
- sb.append(" ").append(curr).append("=").append(body.get(curr));
- System.out.println(sb);
- }
-
- private static class MyEsbActionHandler extends EsbActionHandler
- {
- public static final long serialVersionUID = 1L;
- public void setToken(Token token) {_token = token; }
-
- public MyEsbActionHandler(String title, boolean processLevelVars)
- {
- String level = (processLevelVars)?"PROCESS VARS ":"TOKEN VARS";
- System.out.println(level+" "+title);
- esbCategoryName = "mockCategory";
- esbServiceName = "mockServiceName";
- processVariables = processLevelVars;
- }
-
-
- // this is a mock execute method to avoid need of ESB running for
- // the unit test
- @Override
- public void execute(ExecutionContext ctx) throws Exception
- {
- // Does the same as the real one, but does not go to ESB
- Message request = getMessageTemplate();
- varsToRequest(request);
- dumpMessage("Request ",request);
-
- if (null!=millisToWaitForResponse && millisToWaitForResponse > 0)
- {
- Body body = request.getBody();
- for(String curr:s_vars)
- {
- String val = (String)body.get(curr);
- if (null!=val)
- body.add(curr, val+"_P");
- }
-
- dumpMessage("Response ",request);
- varsFromResponse(request);
- }
- System.out.println("______________________________________");
- }
- };
-}
\ No newline at end of file
Added: labs/jbossesb/trunk/product/services/jbpm/src/test/resources/testMappingDefinition.xml
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/test/resources/testMappingDefinition.xml (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/test/resources/testMappingDefinition.xml 2007-05-08 02:57:38 UTC (rev 11731)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process-definition
+ xmlns="urn:jbpm.org:jpdl-3.1"
+ name="testMappingDefinition">
+ <start-state name="start">
+ <transition name="to_state" to="first">
+ <action class="org.jboss.soa.esb.services.jbpm.actionhandlers.EsbAction2">
+ <esbCategoryName>MOCK_CATEGORY</esbCategoryName>
+ <esbServiceName>MOCK_SERVICE</esbServiceName>
+ <millisToWaitForResponse>1</millisToWaitForResponse>
+ <jbpmToEsbVars>
+ <mapping jbpm-name="v1" esb-name="esbObj1" />
+ <mapping jbpm-name="g2" esb-name="esbObj2" process-scope="true" />
+ <mapping jbpm-name="body" esb-name="BODY_CONTENT" />
+ </jbpmToEsbVars>
+ <returnVars>
+ <mapping jbpm-name="x1" esb-name="esbObj1" process-scope="true" />
+ <mapping jbpm-name="x2" esb-name="esbObj2" />
+ <mapping jbpm-name="x3" esb-name="BODY_CONTENT" />
+ </returnVars>
+ </action>
+ </transition>
+ </start-state>
+ <state name="first">
+ <transition name="to_end" to="end" />
+ </state>
+ <end-state name="end"></end-state>
+</process-definition>
\ No newline at end of file
Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/test/resources/testMappingDefinition.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list