[jboss-svn-commits] JBL Code SVN: r11186 - in labs/jbossesb/trunk/product/services/jbpm/src: main/java/org/jboss/soa/esb/services/jbpm/actions and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Apr 21 10:01:42 EDT 2007


Author: estebanschifman
Date: 2007-04-21 10:01:42 -0400 (Sat, 21 Apr 2007)
New Revision: 11186

Added:
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/MessagePreprocessorFactory.java
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultPreprocessorFactoryImpl.java
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DeployProcessDef.java
   labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/JbpmTestUtil.java
   labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/SingleCommandProcessorUnitTest.java
   labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/testDeployProcessDef.xml
   labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/testNewProcessInstance.xml
Removed:
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/SingleCommandProcessor.java
Modified:
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/Constants.java
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/CommandInterpreter.java
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/util/Helper.java
   labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/CommandInterpreterUnitTest.java
Log:
Factory based implementation of jbpm.SingleCommandProcessor

Modified: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/Constants.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/Constants.java	2007-04-21 13:02:00 UTC (rev 11185)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/Constants.java	2007-04-21 14:01:42 UTC (rev 11186)
@@ -28,6 +28,11 @@
 import org.jboss.soa.esb.services.jbpm.actions.CommandInterpreter;
 import org.jboss.soa.esb.util.ClassUtil;
 
+/**
+ * 
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a> 
+ *
+ */
 public class Constants {
 	
 	private static Logger _logger = Logger.getLogger(Constants.class);
@@ -40,6 +45,7 @@
 	public static final String PROCESS_DEFINITION_NAME		="jbpmProcessDefName";
 	public static final String PROCESS_DEFINITION_VERSION	="jbpmProcessDefVersion";
 	public static final String PROCESS_INSTANCE_ID			="jbpmProcessInstId";
+	public static final String PROCESS_HAS_ENDED			="jbpmProcessEnded";
 	public static final String TASK_INSTANCE_ID				="jbpmTaskInstId";
 	public static final String TOKEN_ID						="jbpmTokenId";
 	public static final String CREATE_START_TASK			="jbpmCreateStartTask";

Modified: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/CommandInterpreter.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/CommandInterpreter.java	2007-04-21 13:02:00 UTC (rev 11185)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/CommandInterpreter.java	2007-04-21 14:01:42 UTC (rev 11186)
@@ -66,10 +66,6 @@
  * 
  * jBPM command interpreter.
  * 
- * <p/>This class is tightly coupled with JbpmCommmandVehicle.
- * <br/>It should be able to interpret all commands in the 'Operation' enum in JbpmCommandVehicle.
- * <br/>If new operations are added there, the process() method in this class should be changed accordingly. 
- * 
  * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a> 
  *
  */
@@ -177,6 +173,7 @@
 		}
 		catch (Exception e)
 		{
+			e.printStackTrace();
 			throw new ActionProcessingException(e);
 		}
 		
@@ -185,7 +182,7 @@
 		
 	public Message doTheJob(Command command)
 	{
-		Message response = Helper.responseTemplate();
+		Message response = Helper.commandMessageTemplate();
 		Body	body	= response.getBody();
 
 		try
@@ -429,6 +426,7 @@
 		{
 			Helper.setLongValue(response, Constants.TOKEN_ID			,token.getId());			
 			Helper.setLongValue(response, Constants.PROCESS_INSTANCE_ID, token.getProcessInstance().getId());
+			Helper.setBooleanValue(response, Constants.PROCESS_HAS_ENDED, token.hasEnded());
 		}
 		return response;
 	} // _______________________________

Added: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/MessagePreprocessorFactory.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/MessagePreprocessorFactory.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/MessagePreprocessorFactory.java	2007-04-21 14:01:42 UTC (rev 11186)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ */
+package org.jboss.soa.esb.services.jbpm.actions;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.services.jbpm.actions.impl.DefaultPreprocessorFactoryImpl;
+
+/**
+ * Factory to obtain appropriate MessagePreprocessor for jBPM SingleCommandProcessors
+ * 
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a> 
+ *
+ */
+public abstract class MessagePreprocessorFactory
+{
+
+	public abstract SingleCommandProcessor.MessagePreprocessor 
+		getPreProcessor(ConfigTree config) throws ConfigurationException;
+	
+	
+	protected static final Object s_oSynch = new Integer(0);
+
+	private   static MessagePreprocessorFactory _factory;
+	public static MessagePreprocessorFactory getInstance()
+	{
+		if (null==_factory)
+			synchronized(s_oSynch)
+			{ 
+				if (null==_factory)
+					_factory=new DefaultPreprocessorFactoryImpl();
+			};
+		return _factory;
+	} //________________________________	
+}


Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/MessagePreprocessorFactory.java
___________________________________________________________________
Name: svn:eol-style
   + native

Deleted: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/SingleCommandProcessor.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/SingleCommandProcessor.java	2007-04-21 13:02:00 UTC (rev 11185)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/SingleCommandProcessor.java	2007-04-21 14:01:42 UTC (rev 11186)
@@ -1,148 +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 org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.actions.ActionProcessingException;
-import org.jboss.soa.esb.addressing.MalformedEPRException;
-import org.jboss.soa.esb.couriers.CourierException;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.services.jbpm.Constants;
-import org.jboss.soa.esb.services.jbpm.util.Helper;
-
-public class SingleCommandProcessor extends CommandInterpreter 
-{
-	public static final String COMMAND_ATTRIBUTE_TAG	= "command";
-	
-	public SingleCommandProcessor(ConfigTree config) throws ConfigurationException
-	{
-		super(config);
-	} // ________________________________
-	
-	public Message process (Message message)
-		throws MalformedEPRException, CourierException, ActionProcessingException
-
-	{
-		if (null==_thisProcessor)
-			throw new ActionProcessingException("Problems with configuration - this should never happen");
-
-		return super.process(_thisProcessor.preProcess(message));
-	} //________________________________
-
-	protected void checkMyParms() throws ConfigurationException
-	{
-		super.checkMyParms();
-
-		String sAux = _config.getRequiredAttribute(COMMAND_ATTRIBUTE_TAG);
-		try { _oper = Constants.OpCode.valueOf(sAux); }
-		catch (IllegalArgumentException e)
-		{
-			throw new ConfigurationException("Attribute '"+COMMAND_ATTRIBUTE_TAG+"' has an invalid value"
-						+"- see CommandVehicle.Operation enum for possible values");
-		}
-
-	} // _______________________________
-	
-	protected void implementDeployProcessDef() throws ConfigurationException
-	{
-		ConfigTree[] childs = _config.getChildren(Constants.PROCESS_DEFINITION_NAME_TAG);
-		if (null==childs || childs.length<1)
-			throw new ConfigurationException("Missing or invalid <"+Constants.PROCESS_DEFINITION_NAME_TAG+"> element");
-		if (childs.length>1)
-			throw new ConfigurationException("Only one <"+Constants.PROCESS_DEFINITION_NAME_TAG+"> element can be specified");
-		final String xmlString = childs[0].toString();
-		try
-		{
-			_thisProcessor = new CommandSpecificProcessor()
-			{
-				public Message preProcess(Message message)
-				{
-					Helper.setObjectValue(message, Constants.COMMAND_CODE,Constants.OpCode.DeployProcessDefinition);
-					Helper.setObjectValue(message, Constants.PROCESS_DEFINITION_XML, xmlString);
-					return message;
-				}
-			};
-		}
-		catch (Exception e)
-		{
-			throw new ConfigurationException(e);
-		}
-	} // _______________________________
-    
-	protected void implementGetProcessVars() throws ConfigurationException
-	{
-	} // _______________________________
-    
-	protected void implementGetTokenVars() throws ConfigurationException
-	{
-	} // _______________________________
-    
-	protected void implementHasInstanceEnded() throws ConfigurationException
-	{
-		// this is just a placeholder - No extra attributes nor elements needed by this op
-		// process instance id must come in each incoming message
-	} // _______________________________
-    
-	protected void implementNewProcessInstance() throws ConfigurationException
-	{
-	} // _______________________________
-    
-	protected void implementSetProcessVars() throws ConfigurationException
-	{
-	} // _______________________________
-    
-	protected void implementSetTokenVars() throws ConfigurationException
-	{
-	} // _______________________________
-    
-	protected void implementSignalProcess() throws ConfigurationException
-	{
-	} // _______________________________
-    
-	protected void implementSignalToken() throws ConfigurationException
-	{
-	} // _______________________________
-	
-	
-	/**
-	 * Map source variable name to target variable name - Default is same name.
-	 * <br/>Depending on the operation code, this will translate jBPM context names to
-	 * esb Message body object names, or vice-versa
-	 * @param sourceName String - The variable name to translate
-	 * @return String - The target variable name, or arg0 if it was not mapped
-	 */
-	protected String getTargetVarName(String sourceName) 
-	{ 
-		return sourceName; 
-	}
-	
-	protected Constants.OpCode 				_oper;
-	protected CommandSpecificProcessor		_thisProcessor;
-	
-	// Use this command pattern to specialize behaviour for each individual command
-	protected abstract class CommandSpecificProcessor
-	{
-		abstract Message preProcess(Message message) throws ActionProcessingException;
-	}
-}

Added: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultPreprocessorFactoryImpl.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultPreprocessorFactoryImpl.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultPreprocessorFactoryImpl.java	2007-04-21 14:01:42 UTC (rev 11186)
@@ -0,0 +1,77 @@
+/*
+ * 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.impl;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.services.jbpm.Constants;
+import org.jboss.soa.esb.services.jbpm.actions.MessagePreprocessorFactory;
+import org.jboss.soa.esb.services.jbpm.actions.SingleCommandProcessor;
+
+/**
+ * Default implementation of a message preprocessor factory
+ * 
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a> 
+ *
+ */
+public class DefaultPreprocessorFactoryImpl extends MessagePreprocessorFactory 
+{
+	
+	@Override
+	public SingleCommandProcessor.MessagePreprocessor getPreProcessor(ConfigTree config) 
+		throws ConfigurationException 
+	{
+		Constants.OpCode opCode = null;
+		String sAux = config.getRequiredAttribute(SingleCommandProcessor.COMMAND_ATTRIBUTE_TAG);
+		try { opCode = Constants.OpCode.valueOf(sAux); }
+		catch (IllegalArgumentException e)
+		{
+			throw new ConfigurationException("Attribute '"+SingleCommandProcessor.COMMAND_ATTRIBUTE_TAG+"' has an invalid value"
+						+"- see CommandVehicle.Operation enum for possible values");
+		}
+		
+		if 	(Constants.OpCode.DeployProcessDefinition		.equals(opCode))
+			return new DeployProcessDef(config);
+		if	(Constants.OpCode.GetProcessInstanceCommand		.equals(opCode))
+			return null;
+		if	(Constants.OpCode.GetTaskInstanceCommand		.equals(opCode))
+			return null;
+		if	(Constants.OpCode.GetTaskListCommand			.equals(opCode))
+			return null;
+		if	(Constants.OpCode.NewProcessInstanceCommand		.equals(opCode))
+			return null;
+		if	(Constants.OpCode.SignalCommand					.equals(opCode))
+			return null;
+		if	(Constants.OpCode.StartProcessInstanceCommand	.equals(opCode))
+			return null;
+		if	(Constants.OpCode.StartWorkOnTaskCommand		.equals(opCode))
+			return null;
+		if	(Constants.OpCode.TaskInstanceEndCommand		.equals(opCode))
+			return null;
+		if	(Constants.OpCode.VariablesCommand				.equals(opCode))
+			return null;
+		
+		throw new ConfigurationException(opCode.toString()+" not implemented");
+	} // _______________________________
+
+}


Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultPreprocessorFactoryImpl.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DeployProcessDef.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DeployProcessDef.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DeployProcessDef.java	2007-04-21 14:01:42 UTC (rev 11186)
@@ -0,0 +1,83 @@
+/*
+ * 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.impl;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.jbpm.Constants;
+import org.jboss.soa.esb.services.jbpm.Constants.OpCode;
+import org.jboss.soa.esb.services.jbpm.actions.SingleCommandProcessor;
+import org.jboss.soa.esb.util.Util;
+import org.jbpm.graph.def.ProcessDefinition;
+
+/**
+ *
+ * Implementation of a message preprocessor that obtains the process definition 
+ * from the action configuration XML
+ * 
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a> 
+ */
+public class DeployProcessDef implements SingleCommandProcessor .MessagePreprocessor
+{
+	public OpCode getOpCode() { return Constants.OpCode.DeployProcessDefinition; }
+
+	public DeployProcessDef(ConfigTree config) throws ConfigurationException
+	{
+		ConfigTree[] childs = config.getChildren(Constants.PROCESS_DEFINITION_XML_TAG);
+		if (null==childs || childs.length<1)
+			throw new ConfigurationException("Missing or invalid <"+Constants.PROCESS_DEFINITION_XML_TAG+"> element");
+		if (childs.length>1)
+			throw new ConfigurationException("Only one <"+Constants.PROCESS_DEFINITION_XML_TAG+"> element can be specified");
+		String version 	= childs[0].getAttribute("version");
+		String encoding = childs[0].getAttribute("encoding");
+		if (Util.isNullString(version) || Util.isNullString(encoding))
+			throw new ConfigurationException("Wrong 'version' or 'encoding' attribute in <"+Constants.PROCESS_DEFINITION_XML_TAG+">");
+		StringBuilder sb = new StringBuilder("<?xml version='").append(version)
+			.append("' encoding='").append(encoding).append("' ?>\n")
+		;
+		ConfigTree[] def = childs[0].getChildren("process-definition");
+		if (null==def || def.length<1)
+			throw new ConfigurationException("Missing or invalid <process-definition> element");
+		if (def.length>1)
+			throw new ConfigurationException("Only one <process-definition> element can be specified");
+		final String xmlString = sb.append(def[0].toString()).toString();
+		try
+		{
+			_processDef = ProcessDefinition.parseXmlString(xmlString);
+		}
+		catch (Exception e)
+		{
+			throw new ConfigurationException(e);
+		}
+	} // ________________________________
+	
+	public void preFormat(Message message) 
+	{
+		message.getBody().add(Constants.COMMAND_CODE,getOpCode().toString());
+		message.getBody().add(Constants.PROCESS_DEFINITION, _processDef);
+	} // ________________________________
+    
+	ProcessDefinition _processDef;
+
+}


Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DeployProcessDef.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/util/Helper.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/util/Helper.java	2007-04-21 13:02:00 UTC (rev 11185)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/util/Helper.java	2007-04-21 14:01:42 UTC (rev 11186)
@@ -19,7 +19,7 @@
 		throw new Exception("Missing or invalid <"+str+"> object in Message body");
 	} //________________________________
 
-	public static Message responseTemplate() 			
+	public static Message commandMessageTemplate() 			
 	{
 		Message template = MessageFactory.getInstance().getMessage();
 		URI	 uri	= null;

Modified: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/CommandInterpreterUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/CommandInterpreterUnitTest.java	2007-04-21 13:02:00 UTC (rev 11185)
+++ labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/CommandInterpreterUnitTest.java	2007-04-21 14:01:42 UTC (rev 11186)
@@ -24,12 +24,7 @@
 
 import static org.junit.Assert.assertTrue;
 
-import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URISyntaxException;
 
 import junit.framework.JUnit4TestAdapter;
 
@@ -80,7 +75,7 @@
     	_logger.info("@BeforeClass invoked");
     	try 
     	{
-    		copyHibernateCfgToRootCP();
+    		_hibernateConfFile = JbpmTestUtil.copyHibernateCfgToRootCP();
     		JbpmConfiguration.getInstance().createSchema();
     	}
     	catch (Exception e)
@@ -115,7 +110,6 @@
     public void testFullProcessLifecycle()
     {
     	long 			instanceId=0		, tokenId=0;
-    	 Exception excJbpm;
     	 Constants.OpCode opCode = null;
     	 Message	request, response;
 
@@ -123,89 +117,51 @@
         try
         {
         	opCode	= Constants.OpCode.DeployProcessDefinition;
-        	request = Helper.responseTemplate();
+        	request = Helper.commandMessageTemplate();
         	Helper.setStringValue(request, Constants.COMMAND_CODE, opCode);
-        	Helper.setStringValue(request, Constants.PROCESS_DEFINITION_XML, stringFromFile("process_01.xml"));
+        	Helper.setStringValue(request, Constants.PROCESS_DEFINITION_XML
+        			, JbpmTestUtil.stringFromFile("process_01.xml"));
 
-        	response = invokeJbpm(request); 
-
-        	_logger.info("Invoked : "+opCode.toString());
-        	_logger.info("Return code = "+Helper.getStringValue(response,Constants.RETURN_CODE));
-        	excJbpm = (Exception)Helper.getObjectValue(response,Constants.EXCEPTION);
-        	if (null==excJbpm)
-        	{
-        		_logger.info("PrcDef name = "+Helper.getObjectValue(response,Constants.PROCESS_DEFINITION_NAME));
-        		_logger.info("PrcDef vers = "+Helper.getObjectValue(response,Constants.PROCESS_DEFINITION_VERSION));
-    		}
-        	else
-        		_logger.error("Problems in jbpm.CommandInterpreter",excJbpm);
-			_logger.info("_______________________________________________________________________");
+        	response = invokeJbpm(request);
+    		_logger.info(JbpmTestUtil.dumpResponse(response, opCode));
+    		assertTrue(Constants.RETCODE_OK.equals(Helper.getStringValue(response, Constants.RETURN_CODE)));
         	
-        	assertTrue(Constants.RETCODE_OK.equals(Helper.getObjectValue(response, Constants.RETURN_CODE)));
-        	
         	opCode	= Constants.OpCode.NewProcessInstanceCommand;
-        	request = Helper.responseTemplate();
+        	request = Helper.commandMessageTemplate();
         	Helper.setStringValue(request, Constants.COMMAND_CODE, opCode);
         	Helper.setStringValue(request, Constants.PROCESS_DEFINITION_NAME, TEST_PROCESS_NAME);
-	    	
-        	response = invokeJbpm(request); 
+        	response = invokeJbpm(request);
+    		_logger.info(JbpmTestUtil.dumpResponse(response, opCode));
+    		assertTrue(Constants.RETCODE_OK.equals(Helper.getStringValue(response, Constants.RETURN_CODE)));	    	
 
-        	_logger.info("Invoked : "+opCode.toString());
-        	_logger.info("Return code = "+Helper.getStringValue(response,Constants.RETURN_CODE));
-        	excJbpm = (Exception)Helper.getObjectValue(response,Constants.EXCEPTION);
-        	if (null==excJbpm)
-        	{
-        		instanceId	= Helper.getLongValue(response,Constants.PROCESS_INSTANCE_ID);
-        		tokenId		= Helper.getLongValue(response,Constants.TOKEN_ID);
-        		_logger.info("Process Id = "+instanceId);
-        		_logger.info("Token   Id = "+tokenId);
-    		}
-        	else
-        		_logger.error("Problems in jbpm.CommandInterpreter",excJbpm);
-			_logger.info("_______________________________________________________________________");
-
-        	assertTrue(Constants.RETCODE_OK.equals(Helper.getObjectValue(response, Constants.RETURN_CODE)));
-
+ 	     	instanceId	= Helper.getLongValue(response,Constants.PROCESS_INSTANCE_ID);
+ 	     	tokenId		= Helper.getLongValue(response,Constants.TOKEN_ID);
         	boolean signalToken = true;
 			for (boolean continueLooping = true; continueLooping;)
 			{
 				opCode	= Constants.OpCode.SignalCommand;
 				// for this test, alternatively signal:  token - process - token ...
 				
-	        	request = Helper.responseTemplate();
+	        	request = Helper.commandMessageTemplate();
 	        	Helper.setStringValue(request, Constants.COMMAND_CODE, opCode);
 	 	     	if (signalToken)
 	 	     		Helper.setLongValue(request, Constants.TOKEN_ID, tokenId);
 	 	     	else
 	 	     		Helper.setLongValue(request, Constants.PROCESS_INSTANCE_ID, instanceId);
+	 	     	response = invokeJbpm(request);
 				signalToken = ! signalToken;
 
-	 	     	response = invokeJbpm(request);
-
 	 	     	if (null!=response)
-				{
-	 	        	_logger.info("Invoked : "+opCode.toString());
-	 	        	_logger.info("Return code = "+Helper.getStringValue(response,Constants.RETURN_CODE));
-	 	        	excJbpm = (Exception)Helper.getObjectValue(response,Constants.EXCEPTION);
-					if (null==excJbpm)
-					{
-		        		instanceId	= Helper.getLongValue(response,Constants.PROCESS_INSTANCE_ID);
-		        		tokenId		= Helper.getLongValue(response,Constants.TOKEN_ID);
-						Token token = (Token)Helper.getObjectValue(response, Constants.JBPM_RETURN_OBJECT);
-						boolean hasEnded = token.hasEnded();
-						_logger.info("Has ended   = "+ hasEnded);
-						_logger.info("Current State = "+token.getNode().getName());
-						
-						continueLooping	= ! hasEnded;
-					}
-					else
-						_logger.error("Problems in jbpm.CommandInterpreter",excJbpm);
-				}
+		    		_logger.info(JbpmTestUtil.dumpResponse(response, opCode));
 				else
-					_logger.info("Response was not received");
-				_logger.info("_______________________________________________________________________");
-				
+					_logger.info("Response was not received");			
 	        	assertTrue(Constants.RETCODE_OK.equals(Helper.getObjectValue(response, Constants.RETURN_CODE)));
+	        	
+	        	Token token = (Token)Helper.getObjectValue(response, Constants.JBPM_RETURN_OBJECT);
+	        	if (token.hasEnded())
+	        		break;
+	 	     	instanceId	= Helper.getLongValue(response,Constants.PROCESS_INSTANCE_ID);
+	 	     	tokenId		= Helper.getLongValue(response,Constants.TOKEN_ID);
 			}
 
         }
@@ -217,42 +173,6 @@
 
     } //________________________________
 
-	protected static String stringFromFile(String pFileName) throws IOException
-	{
-	    InputStream in = thisClass.getResourceAsStream(pFileName);
-		ByteArrayOutputStream out = new ByteArrayOutputStream();
-		byte[]ba = new byte[1000];
-		int iQ = -1;
-		while (-1<(iQ=in.read(ba)))
-			if (iQ>0)	out.write(ba,0,iQ);
-		in.close();
-		return out.toString();
-	}
-	
-	protected static void copyFile(String resource, File target) throws IOException
-	{
-	    InputStream in = thisClass.getResourceAsStream(resource);
-		FileOutputStream out = new FileOutputStream(target);
-		byte[]ba = new byte[1000];
-		int iQ = -1;
-		while (-1<(iQ=in.read(ba)))
-			if (iQ>0)	out.write(ba,0,iQ);
-		out.close();
-		in.close();
-	}
-	
-	protected static void copyHibernateCfgToRootCP()
-		throws URISyntaxException, IOException
-	{
-		String configName = "hibernate.cfg.xml";
-		File localHibernateXml = new File(thisClass.getResource(configName).toURI());
-		String path = localHibernateXml.toString();
-		int i = path.indexOf("org/jboss/soa/esb/services/jbpm/actions");
-		File classRoot = new File(path.substring(0,i-1));
-		_hibernateConfFile = new File(classRoot,configName);
-		copyFile(configName, _hibernateConfFile);
-	}
-	
    protected Message invokeJbpm(Message request) throws Exception
    {
   	 if (null==_interp)

Added: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/JbpmTestUtil.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/JbpmTestUtil.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/JbpmTestUtil.java	2007-04-21 14:01:42 UTC (rev 11186)
@@ -0,0 +1,89 @@
+package org.jboss.soa.esb.services.jbpm.actions;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.net.URISyntaxException;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.jbpm.Constants;
+
+public class JbpmTestUtil 
+{
+	private static final Class thisClass = JbpmTestUtil.class;
+
+	public static String stringFromFile(String pFileName) throws IOException
+	{
+	    InputStream in = thisClass.getResourceAsStream(pFileName);
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		byte[]ba = new byte[1000];
+		int iQ = -1;
+		while (-1<(iQ=in.read(ba)))
+			if (iQ>0)	out.write(ba,0,iQ);
+		in.close();
+		return out.toString();
+	}
+	
+	public static void copyFile(String resource, File target) throws IOException
+	{
+	    InputStream in = thisClass.getResourceAsStream(resource);
+		FileOutputStream out = new FileOutputStream(target);
+		byte[]ba = new byte[1000];
+		int iQ = -1;
+		while (-1<(iQ=in.read(ba)))
+			if (iQ>0)	out.write(ba,0,iQ);
+		out.close();
+		in.close();
+	}
+	
+	public static File copyHibernateCfgToRootCP()
+		throws URISyntaxException, IOException
+	{
+		String configName = "hibernate.cfg.xml";
+		File localHibernateXml = new File(thisClass.getResource(configName).toURI());
+		String path = localHibernateXml.toString();
+		int i = path.indexOf("org/jboss/soa/esb/services/jbpm/actions");
+		File classRoot = new File(path.substring(0,i-1));
+		File target = new File(classRoot,configName);
+		copyFile(configName, target);
+		return target;
+	}
+	
+	public static String dumpResponse(Message message, Constants.OpCode opCode)
+	{
+		StringBuilder sb = new StringBuilder("\nInvoked: ").append(opCode.toString()).append("\n");
+		if (null==message)
+			return sb.append(" - No response received").toString();
+		sb.append(getObject(message,Constants.RETURN_CODE));
+		sb.append(getObject(message,Constants.ERROR_MESSAGE));
+		sb.append(getObject(message,Constants.EXCEPTION));
+		sb.append(getObject(message,Constants.ACTOR_ID));
+		sb.append(getObject(message,Constants.ACTOR_LIST));
+		sb.append(getObject(message,Constants.CURRENT_NODE_NAME));
+		sb.append(getObject(message,Constants.JBPM_RETURN_OBJECT));
+		sb.append(getObject(message,Constants.PROCESS_DEFINITION_NAME));
+		sb.append(getObject(message,Constants.PROCESS_DEFINITION_VERSION));
+		sb.append(getObject(message,Constants.PROCESS_INSTANCE_ID));
+		sb.append(getObject(message,Constants.TASK_INSTANCE_ID));
+		sb.append(getObject(message,Constants.TOKEN_ID));
+		sb.append(getObject(message,Constants.PROCESS_HAS_ENDED));
+		return sb.append("_______________________________________________________________________")
+			.toString();		
+	}
+	
+	public static String getObject(Message message, String key)
+	{
+		Object obj = message.getBody().get(key);
+		if (null==obj)
+			return "";
+		if (!(obj instanceof Exception))
+		 return key+" = "+obj.toString()+"\n";
+		ByteArrayOutputStream ba = new ByteArrayOutputStream();
+		((Exception)obj).printStackTrace(new PrintStream(ba));
+		return key+" = "+obj.toString()+"\n"+ba.toString();
+	}
+	
+}


Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/JbpmTestUtil.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/SingleCommandProcessorUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/SingleCommandProcessorUnitTest.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/SingleCommandProcessorUnitTest.java	2007-04-21 14:01:42 UTC (rev 11186)
@@ -0,0 +1,149 @@
+/*
+ * 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 junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.jbpm.Constants;
+import org.jboss.soa.esb.services.jbpm.util.Helper;
+import org.jbpm.JbpmConfiguration;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test the jBPM command interpreter class
+ *
+ * @author <a href="mailto:schifest at heuristica.com.ar">Esteban</a>
+ */
+
+
+public class SingleCommandProcessorUnitTest
+{
+
+	private static Class 		thisClass = SingleCommandProcessorUnitTest.class;
+	static Logger 				_logger = Logger.getLogger(thisClass);
+	
+	private static File		_hibernateConfFile;
+	
+    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 
+    	{
+    		_hibernateConfFile = JbpmTestUtil.copyHibernateCfgToRootCP();
+    		JbpmConfiguration.getInstance().createSchema();
+    	}
+    	catch (Exception e)
+    	{
+    		e.printStackTrace();
+    		assertTrue(false);
+    	}
+    }
+
+
+    @AfterClass
+    public static void runAfterAllTests() throws Exception
+    {
+    	_logger.info("@AfterClass invoked");
+		// Remove the hibernate.cfg.xml file we copied to the classpath root
+    	if (null!=_hibernateConfFile)
+    	{
+    		JbpmConfiguration.getInstance().dropSchema();
+    		_hibernateConfFile.delete();
+    	}
+    }
+
+    @Test
+    public void mockTest()
+    {
+    	// place holder so test will run even with no other @Test
+    	_logger.info("Mock test invoked");
+    	assertTrue(true);
+    }
+    
+    @Test
+    public void testSequence()
+    {
+    	testDeployProcessDef();
+    	testNewProcessInstance();
+    }
+    
+    public void testDeployProcessDef()
+    {
+    	try
+    	{
+    		String tree = JbpmTestUtil.stringFromFile("testDeployProcessDef.xml");
+    		SingleCommandProcessor command = new SingleCommandProcessor(ConfigTree.fromXml(tree));
+    		Message response = command.process(Helper.commandMessageTemplate());
+    		_logger.info(JbpmTestUtil.dumpResponse(response, command.getOpCode()));
+    		String ret = Helper.getStringValue(response, Constants.RETURN_CODE);
+    		assertTrue(Constants.RETCODE_OK.equals(ret));
+    	}
+    	catch (Exception e)
+    	{
+    		_logger.error(e);
+    		assertTrue(false);
+    	}
+    } //________________________________
+ 
+	public void testNewProcessInstance()
+	{
+		try
+		{
+			String tree = JbpmTestUtil.stringFromFile("testDeployProcessDef.xml");
+			SingleCommandProcessor command = new SingleCommandProcessor(ConfigTree.fromXml(tree));
+			Message response = command.process(Helper.commandMessageTemplate());
+			_logger.info(JbpmTestUtil.dumpResponse(response, command.getOpCode()));
+			String ret = Helper.getStringValue(response, Constants.RETURN_CODE);
+			assertTrue(Constants.RETCODE_OK.equals(ret));
+		}
+		catch (Exception e)
+		{
+			_logger.error(e);
+			assertTrue(false);
+		}
+	} //________________________________
+
+}
\ No newline at end of file


Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/SingleCommandProcessorUnitTest.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/testDeployProcessDef.xml
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/testDeployProcessDef.xml	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/testDeployProcessDef.xml	2007-04-21 14:01:42 UTC (rev 11186)
@@ -0,0 +1,21 @@
+<action	name="one" class="org.jboss.soa.esb.services.jbpm.actions.SingleCommandProcessor"
+		command="DeployProcessDefinition">
+	<ProcessDefinitionXml version="1.0" encoding="UTF-8">
+		<process-definition 
+		  xmlns="urn:jbpm.org:jpdl-3.1"
+		  name="simple"
+		 >
+		   <start-state name="start">
+		      <transition name="to_state" to="first">
+		         
+		      </transition>
+		   </start-state>
+		   <state name="first">
+		      <transition name="to_end" to="end">
+		         
+		      </transition>
+		   </state>
+		   <end-state name="end"></end-state>
+			</process-definition>
+	</ProcessDefinitionXml>
+</action>


Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/testDeployProcessDef.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native

Added: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/testNewProcessInstance.xml
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/testNewProcessInstance.xml	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/testNewProcessInstance.xml	2007-04-21 14:01:42 UTC (rev 11186)
@@ -0,0 +1,4 @@
+<action	name="two" class="org.jboss.soa.esb.services.jbpm.actions.SingleCommandProcessor"
+		command="NewProcessInstanceCommand">
+		<ProcessDefinition name="simple" />
+</action>


Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/testNewProcessInstance.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native




More information about the jboss-svn-commits mailing list