[jboss-svn-commits] JBL Code SVN: r17324 - in labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test: resources and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Dec 19 13:27:50 EST 2007


Author: kurt.stam at jboss.com
Date: 2007-12-19 13:27:50 -0500 (Wed, 19 Dec 2007)
New Revision: 17324

Added:
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/ExceptionFlowTest.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/TimerTest.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testExceptionHandling.xml
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testTimer.jpg
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testTimer.xml
Modified:
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/log4j.xml
Log:
JBESB-1301 adding unittests

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/ExceptionFlowTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/ExceptionFlowTest.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/ExceptionFlowTest.java	2007-12-19 18:27:50 UTC (rev 17324)
@@ -0,0 +1,147 @@
+/*
+ * 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.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URI;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+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.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.Before;
+import org.junit.Test;
+/**
+ * Tests the capabilities of jBPM which we are using to handle exceptions.
+ * 
+ * @author kstam
+ *
+ */
+public class ExceptionFlowTest 
+{
+    private static String PROCESS_DEF_XML = "testExceptionHandling.xml";
+	private static Logger logger = Logger.getLogger(ExceptionFlowTest.class);
+    private static long processInstanceId;
+    
+    private static EPR epr1;
+    private static MockCourier courier1;
+    private static String MOCK_CATEGORY="MockCategory";
+    private static String MOCK_SERVICE ="MockService";
+
+    @Before
+    public void setup() throws Exception
+    {
+        MockCourierFactory.install();
+        MockRegistry.install();
+        epr1 = new EPR(new URI("test1"));
+        courier1 = new MockCourier(true);
+        MockRegistry.register(MOCK_CATEGORY, MOCK_SERVICE, epr1, courier1);
+        
+        logger.info("Setting up jBPM");
+        JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
+        JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+        jbpmContext.getJbpmConfiguration().getJobExecutor().start();
+      
+        //Extract a process definition from the processdefinition.xml file.
+        ProcessDefinition processDefinition 
+            = ProcessDefinition.parseXmlResource(PROCESS_DEF_XML);
+        assertNotNull(processDefinition);
+        //Create an instance of the process definition.
+        jbpmContext.deployProcessDefinition(processDefinition);
+        //processInstance = new ProcessInstance(processDefinition);
+        ProcessInstance processInstance = jbpmContext.newProcessInstance("testExceptionHandling");
+        assertTrue(
+                "Instance is in start state", 
+                "start".equals(processInstance.getRootToken().getNode().getName()));
+        processInstanceId = processInstance.getId();
+        jbpmContext.close();
+    }
+
+    /**
+     * Tests timeout of the first node (service1). The time-out-transition will
+     * be taken and we should en up in the ExceptionHandling end-state.
+     * 
+     * @throws Exception
+     */
+    @Test
+    public void timeOut() throws Exception
+    { 
+        JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
+        JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+        ProcessInstance processInstance = jbpmContext.loadProcessInstance(processInstanceId);
+        
+        Token token = processInstance.getRootToken();
+        assertEquals("start",token.getNode().getName());
+        //Move the process to service1
+        processInstance.signal();
+        jbpmContext.close();
+        //Our timer fires after 1000 millies, so let's wait for that
+        int seconds=0;
+        while(true) {
+            jbpmContext = jbpmConfiguration.createJbpmContext();
+            processInstance = jbpmContext.loadProcessInstance(processInstanceId);
+            token = processInstance.getRootToken();
+            logger.info(seconds++ + " Node=" + token.getNode().getName());
+            if ("ExceptionHandling".equals(token.getNode().getName())) break; //we're done waiting
+            if (seconds > 20) break; // the timer must not have fired so we are bailing (and failing)
+            jbpmContext.close();
+            try { Thread.sleep(1000); } catch (InterruptedException e) {e.printStackTrace();}
+        }
+        assertEquals("ExceptionHandling",token.getNode().getName());
+    }
+    
+    @Test
+    public void takeExceptionTransition() {
+        JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
+        JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+        ProcessInstance processInstance = jbpmContext.loadProcessInstance(processInstanceId);
+        
+        Token token = processInstance.getRootToken();
+        assertEquals("start",token.getNode().getName());
+        //Move the process to service1
+        processInstance.signal();
+        assertEquals("Service1",token.getNode().getName());
+//      Move the process to service2, no timeout on service1
+        processInstance.signal();
+        assertEquals("Service2",token.getNode().getName());
+        //Move the service2 ExceptionHandling
+        processInstance.signal("exception");
+        assertEquals("ExceptionHandling",token.getNode().getName());
+    }
+    
+    public static junit.framework.Test suite(){
+        return new JUnit4TestAdapter(ExceptionFlowTest.class);
+    }
+
+}


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/ExceptionFlowTest.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/TimerTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/TimerTest.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/TimerTest.java	2007-12-19 18:27:50 UTC (rev 17324)
@@ -0,0 +1,115 @@
+/*
+ * 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.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+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.BeforeClass;
+import org.junit.Test;
+/**
+ * Tests the capabilities of jBPM timer, which we are using.
+ * 
+ * @author kstam
+ *
+ */
+public class TimerTest 
+{
+    private static String PROCESS_DEF_XML = "testTimer.xml";
+	private static Logger logger = Logger.getLogger(TimerTest.class);
+    private static long processInstanceId;
+    //private static ProcessInstance processInstance = null;
+    //private static JbpmContext jbpmContext = null;
+    //private static GraphSession graphSession = null;
+
+    @BeforeClass
+    public static void setup() throws Exception
+    {
+        logger.info("Setting up jBPM");
+        JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
+        
+        jbpmConfiguration.getJobExecutor().start();
+        JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+        //Extract a process definition from the processdefinition.xml file.
+        ProcessDefinition processDefinition = ProcessDefinition.parseXmlResource(PROCESS_DEF_XML);
+        assertNotNull(processDefinition);
+        //Create an instance of the process definition.
+        jbpmContext.deployProcessDefinition(processDefinition);
+        ProcessInstance processInstance = jbpmContext.newProcessInstance("testTimer");
+        processInstanceId = processInstance.getId();
+        assertTrue(
+                "Instance is in start state", 
+                "start".equals(processInstance.getRootToken().getNode().getName()));
+        processInstance.getContextInstance().createVariable("processingTime", "3000");
+        jbpmContext.close(); 
+    }
+
+    /**
+     * Tests timeout functionality of jBPM
+     * 
+     * @throws Exception
+     */
+    @Test
+    public void timeOut() throws Exception
+    { 
+        JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
+        JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+        ProcessInstance processInstance = jbpmContext.loadProcessInstance(processInstanceId);
+        
+        Token token = processInstance.getRootToken(); 
+        processInstance.signal();
+        assertEquals("wait1",token.getNode().getName());
+        jbpmContext.close();
+        
+        int seconds=0;
+        while (true) {
+            try {
+                Thread.sleep(1000);
+            } catch (InterruptedException e) {}
+            jbpmContext = jbpmConfiguration.createJbpmContext();
+            processInstance = jbpmContext.loadProcessInstance(processInstanceId);
+            token = processInstance.getRootToken();
+            String currentNode = token.getNode().getName();
+            System.out.println(seconds++ + " " + currentNode);
+            jbpmContext.close();
+            if (currentNode.equals("end")) break;
+            if (seconds > 20) break; 
+        }
+        
+        //Check that we are now in the end node.
+        assertEquals("end",token.getNode().getName());
+    }
+    
+    public static junit.framework.Test suite(){
+        return new JUnit4TestAdapter(TimerTest.class);
+    }
+
+}


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/TimerTest.java
___________________________________________________________________
Name: svn:eol-style
   + native


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources
___________________________________________________________________
Name: svn:ignore
   - .gpd.JBpmObjectMapperTestProcessDefinition.xml
.gpd.testMappingDefinition.xml

   + .gpd.JBpmObjectMapperTestProcessDefinition.xml
.gpd.testMappingDefinition.xml
.gpd.testExceptionHandling.xml
.gpd.testTimer.xml


Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/log4j.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/log4j.xml	2007-12-19 17:39:21 UTC (rev 17323)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/log4j.xml	2007-12-19 18:27:50 UTC (rev 17324)
@@ -35,10 +35,10 @@
    <!-- ================ -->
 
    <category name="org.jbpm">
-      <priority value="INFO"/>
+      <priority value="DEBUG"/>
    </category>
    <category name="org.hibernate">
-      <priority value="ERROR"/>
+      <priority value="INFO"/>
    </category>
    <category name="org.jboss">
       <priority value="WARN"/>

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testExceptionHandling.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testExceptionHandling.xml	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testExceptionHandling.xml	2007-12-19 18:27:50 UTC (rev 17324)
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process-definition 
+  xmlns="urn:jbpm.org:jpdl-3.2"
+  name="testExceptionHandling">
+   <start-state name="start">
+      <transition name="" to="Service1"></transition>
+   </start-state>
+   <node name="Service1">
+	  <action class="org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler">
+	      	<esbCategoryName>MockCategory</esbCategoryName>
+          	<esbServiceName>MockService</esbServiceName>
+       </action>
+       <timer name='timeout' duedate='1 seconds' transition='time-out-transition'/>
+       <transition name="" to="Service2"></transition>
+       <transition name="time-out-transition" to="ExceptionHandling"></transition>
+   </node>
+   <node name="Service2">
+      <action class="org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler">
+	      	<esbCategoryName>MockCategory</esbCategoryName>
+          	<esbServiceName>MockService</esbServiceName>
+       </action>
+      <transition name="" to="Service3"></transition>
+      <transition name="exception" to="ExceptionHandling"></transition>
+   </node>
+   <end-state name="ExceptionHandling"></end-state>
+   <node name="Service3">
+      <action class="org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler">
+	      	<esbCategoryName>MockCategory</esbCategoryName>
+          	<esbServiceName>MockService</esbServiceName>
+       </action>
+      <transition name="" to="end"></transition>
+      <transition name="exception" to="ExceptionHandling"></transition>
+   </node>
+   <end-state name="end"></end-state>
+</process-definition>
\ No newline at end of file


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testExceptionHandling.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testTimer.jpg
===================================================================
(Binary files differ)


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testTimer.jpg
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testTimer.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testTimer.xml	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testTimer.xml	2007-12-19 18:27:50 UTC (rev 17324)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process-definition 
+  xmlns="urn:jbpm.org:jpdl-3.2"
+  name="testTimer">
+   <start-state name="start">
+      <transition name="toWait" to="wait1"></transition>
+   </start-state>
+   <state name="wait1">
+               <timer duedate="2 seconds" transition="continue" />
+               <transition name="continue" to="mynode" />
+       </state>
+       <node name="mynode">
+               <transition name="toWait2" to="wait2" />
+       </node>
+       <state name="wait2">
+               <timer duedate="2 seconds" transition="continue" />
+               <transition name="continue" to="end" />
+       </state>
+   <end-state name="end"></end-state>
+</process-definition>
\ No newline at end of file


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testTimer.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml




More information about the jboss-svn-commits mailing list