[jboss-svn-commits] JBL Code SVN: r10976 - in labs/jbossesb/trunk/product/services/jbpm/src/test/java: org/jboss/soa/esb/services/jbpm and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Apr 14 15:02:12 EDT 2007


Author: estebanschifman
Date: 2007-04-14 15:02:12 -0400 (Sat, 14 Apr 2007)
New Revision: 10976

Added:
   labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/
   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/processdefinition.xml
Log:
Unit tests for jbpm.CommandInterpreter

Added: 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	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/CommandInterpreterUnitTest.java	2007-04-14 19:02:12 UTC (rev 10976)
@@ -0,0 +1,150 @@
+/*
+ * 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.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.services.jbpm.util.CommandVehicle;
+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 CommandInterpreterUnitTest
+{
+
+	private static Class 		thisClass = CommandInterpreterUnitTest.class;
+	static Logger 				_logger = Logger.getLogger(thisClass);
+	static CommandInterpreter	_interpreter;
+	
+    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
+    	{
+    		_interpreter	= new CommandInterpreter(new ConfigTree("empty"));
+    	}
+    	catch (Exception e)
+    	{
+    		_logger.fatal("Unable to instantiate jbpm command interpreter",e);
+    		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);
+    }
+
+//    @Test
+    public void testDeployProcessDefinition()
+    {
+    	_logger.info("testDeployProcessDefinition() invoked");
+        try
+        {
+        	CommandVehicle vhc = new CommandVehicle(CommandVehicle.Operation.deployProcessDefinition);
+        	vhc.setProcessDefinitionXml(stringFromFile("processdefinition.xml"));
+        	CommandVehicle response = new CommandVehicle
+        		(_interpreter.process(vhc.toCommandMessage()));
+    		if (null!=response)
+    		{
+    			_logger.info("Invoked : "+vhc.getOperator().toString());
+    			_logger.info("Return code = "+response.getReturnCode());
+    			_logger.info("Error messg = "+response.getErrorMessage());
+    			Exception e = response.getException();
+    			if (null==e)
+    			{
+    				_logger.info("PrcDef name = "+response.getProcessDefinitionName());
+    				_logger.info("PrcDef vers = "+response.getProcessVersion());
+    			}
+    			else
+    				_logger.error("Problems in jbpm.CommandInterpreter",e);
+    		}
+    		else
+    			_logger.info("Response was not received");
+    		_logger.info("_______________________________________________________________________");
+        	
+        	assertTrue(CommandVehicle.RETCODE_OK.equals(response.getReturnCode()));
+        }
+        catch (Exception _ex)
+        {
+            _ex.printStackTrace();
+            assertTrue(false);
+        }
+
+    }
+	protected String stringFromFile(String pFileName) throws Exception
+	{
+		String userDir = System.getProperty("user.dir");
+		String baseDir = (userDir.endsWith("jbpm_simple1")) 
+		? userDir
+		: userDir + "/product/services/jbpm/src/test/java";
+	    InputStream in = new FileInputStream(new File(baseDir,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);
+		return out.toString();
+	}
+	
+
+}
\ 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/CommandInterpreterUnitTest.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/trunk/product/services/jbpm/src/test/java/processdefinition.xml
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/test/java/processdefinition.xml	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/test/java/processdefinition.xml	2007-04-14 19:02:12 UTC (rev 10976)
@@ -0,0 +1,17 @@
+<?xml 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>
\ No newline at end of file


Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/test/java/processdefinition.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml




More information about the jboss-svn-commits mailing list