[jbpm-commits] JBoss JBPM SVN: r3025 - in jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm: enterprise and 4 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Nov 21 06:26:43 EST 2008
Author: thomas.diesler at jboss.com
Date: 2008-11-21 06:26:42 -0500 (Fri, 21 Nov 2008)
New Revision: 3025
Added:
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/config/
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/config/AppServerConfigurationsTest.java
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/config/ContainerProvidedJarsTest.java
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/ejbtimer/
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/ejbtimer/EjbSchedulerTest.java
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/jms/
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/jms/JmsMessageTest.java
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/jta/
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java
Removed:
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/AppServerConfigurationsTest.java
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/ContainerProvidedJarsTest.java
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/msg/
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/persistence/
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/scheduler/
Log:
Move enterprise tests to their own package
Deleted: jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/AppServerConfigurationsTest.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/AppServerConfigurationsTest.java 2008-11-21 11:04:59 UTC (rev 3024)
+++ jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/AppServerConfigurationsTest.java 2008-11-21 11:26:42 UTC (rev 3025)
@@ -1,65 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, 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.jbpm.enterprise;
-
-import junit.framework.Test;
-
-import org.apache.cactus.ServletTestCase;
-import org.jbpm.JbpmConfiguration;
-import org.jbpm.api.test.IntegrationTestSetup;
-import org.jbpm.msg.jms.JmsMessageServiceFactory;
-import org.jbpm.persistence.jta.JtaDbPersistenceServiceFactory;
-import org.jbpm.scheduler.ejbtimer.EntitySchedulerServiceFactory;
-import org.jbpm.svc.Services;
-
-public class AppServerConfigurationsTest extends ServletTestCase
-{
- JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
-
- public static Test suite() throws Exception
- {
- return new IntegrationTestSetup(AppServerConfigurationsTest.class, "enterprise-test.war");
- }
-
- public void testUnavailabilityOfTheJobExecutor()
- {
- assertNull(jbpmConfiguration.getJobExecutor());
- }
-
- public void testJtaDbPersistenceFactoryConfiguration()
- {
- assertSame(JtaDbPersistenceServiceFactory.class, jbpmConfiguration.getServiceFactory(Services.SERVICENAME_PERSISTENCE).getClass());
- JtaDbPersistenceServiceFactory persistenceServiceFactory = (JtaDbPersistenceServiceFactory)jbpmConfiguration.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
- assertFalse(persistenceServiceFactory.isTransactionEnabled());
- assertTrue(persistenceServiceFactory.isCurrentSessionEnabled());
- }
-
- public void testJmsMessageServiceFactoryConfiguration()
- {
- assertSame(JmsMessageServiceFactory.class, jbpmConfiguration.getServiceFactory(Services.SERVICENAME_MESSAGE).getClass());
- }
-
- public void testEjbSchedulerServiceFactoryConfiguration()
- {
- assertSame(EntitySchedulerServiceFactory.class, jbpmConfiguration.getServiceFactory(Services.SERVICENAME_SCHEDULER).getClass());
- }
-}
Deleted: jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/ContainerProvidedJarsTest.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/ContainerProvidedJarsTest.java 2008-11-21 11:04:59 UTC (rev 3024)
+++ jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/ContainerProvidedJarsTest.java 2008-11-21 11:26:42 UTC (rev 3025)
@@ -1,119 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, 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.jbpm.enterprise;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.management.ObjectName;
-
-import junit.framework.TestCase;
-
-import org.jbpm.api.model.builder.ObjectNameFactory;
-import org.jbpm.api.test.IntegrationTestHelper;
-
-/**
- * Test that there are jars deployed which should in fact be provided by the container
- *
- * @author thomas.diesler at jboss.com
- * @since 23-Sep-2008
- */
-public class ContainerProvidedJarsTest extends TestCase
-{
- IntegrationTestHelper delegate = new IntegrationTestHelper();
-
- public void testDependencies() throws Exception
- {
- String targetContainer = null;
- if (delegate.isTargetJBoss422())
- {
- targetContainer = "jboss422";
- }
- else if (delegate.isTargetJBoss423())
- {
- targetContainer = "jboss423";
- }
- else if (delegate.isTargetJBoss500())
- {
- targetContainer = "jboss500";
- }
- assertNotNull("System property 'target.container' not null", targetContainer);
- assertTrue("Supported target.container: " + targetContainer, "jboss422,jboss423,jboss500".indexOf(targetContainer) >= 0);
-
- File jbossJars = delegate.getResourceFile(targetContainer + "-dependencies.txt");
- assertTrue("JBoss jar fixture exists: " + jbossJars, jbossJars.exists());
-
- // Read the JBoss ServerHomeDir
- ObjectName oname = ObjectNameFactory.create("jboss.system:type=ServerConfig");
- File serverHomeDir = (File)delegate.getServer().getAttribute(oname, "ServerHomeDir");
- if (serverHomeDir == null)
- throw new IllegalStateException("Cannot obtain jboss home dir");
-
- File jbpmDir = new File(serverHomeDir + "/deploy/jbpm");
- assertTrue("jBPM dir exists: " + jbpmDir, jbpmDir.exists());
-
- // Store the deployed jars in a string builder
- String deployedJars = getDeployedJars(jbpmDir).toString();
-
- // Iterate over the known server provided jars
- List<String> matchingJars = new ArrayList<String>();
- BufferedReader br = new BufferedReader(new FileReader(jbossJars));
- String line = br.readLine();
- while (line != null)
- {
- if (line.length() == 0 || line.startsWith("#"))
- {
- line = br.readLine();
- continue;
- }
-
- if (deployedJars.indexOf(line) > 0)
- {
- matchingJars.add(line);
- }
- line = br.readLine();
- }
-
- assertEquals("Invalid deployed jars: " + matchingJars, 0, matchingJars.size());
- }
-
- private List<String> getDeployedJars(File subdir)
- {
- List<String> deployedJars = new ArrayList<String>();
- for (File file : subdir.listFiles())
- {
- if (file.isDirectory())
- {
- deployedJars.addAll(getDeployedJars(file));
- continue;
- }
-
- String fileName = file.getName();
- if (fileName.endsWith(".jar"))
- deployedJars.add(fileName);
- }
- return deployedJars;
- }
-}
Added: jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/config/AppServerConfigurationsTest.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/config/AppServerConfigurationsTest.java (rev 0)
+++ jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/config/AppServerConfigurationsTest.java 2008-11-21 11:26:42 UTC (rev 3025)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbpm.enterprise.config;
+
+import junit.framework.Test;
+
+import org.apache.cactus.ServletTestCase;
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.api.test.IntegrationTestSetup;
+import org.jbpm.msg.jms.JmsMessageServiceFactory;
+import org.jbpm.persistence.jta.JtaDbPersistenceServiceFactory;
+import org.jbpm.scheduler.ejbtimer.EntitySchedulerServiceFactory;
+import org.jbpm.svc.Services;
+
+public class AppServerConfigurationsTest extends ServletTestCase
+{
+ JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
+
+ public static Test suite() throws Exception
+ {
+ return new IntegrationTestSetup(AppServerConfigurationsTest.class, "enterprise-test.war");
+ }
+
+ public void testUnavailabilityOfTheJobExecutor()
+ {
+ assertNull(jbpmConfiguration.getJobExecutor());
+ }
+
+ public void testJtaDbPersistenceFactoryConfiguration()
+ {
+ assertSame(JtaDbPersistenceServiceFactory.class, jbpmConfiguration.getServiceFactory(Services.SERVICENAME_PERSISTENCE).getClass());
+ JtaDbPersistenceServiceFactory persistenceServiceFactory = (JtaDbPersistenceServiceFactory)jbpmConfiguration.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
+ assertFalse(persistenceServiceFactory.isTransactionEnabled());
+ assertTrue(persistenceServiceFactory.isCurrentSessionEnabled());
+ }
+
+ public void testJmsMessageServiceFactoryConfiguration()
+ {
+ assertSame(JmsMessageServiceFactory.class, jbpmConfiguration.getServiceFactory(Services.SERVICENAME_MESSAGE).getClass());
+ }
+
+ public void testEjbSchedulerServiceFactoryConfiguration()
+ {
+ assertSame(EntitySchedulerServiceFactory.class, jbpmConfiguration.getServiceFactory(Services.SERVICENAME_SCHEDULER).getClass());
+ }
+}
Property changes on: jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/config/AppServerConfigurationsTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/config/ContainerProvidedJarsTest.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/config/ContainerProvidedJarsTest.java (rev 0)
+++ jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/config/ContainerProvidedJarsTest.java 2008-11-21 11:26:42 UTC (rev 3025)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbpm.enterprise.config;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.management.ObjectName;
+
+import junit.framework.TestCase;
+
+import org.jbpm.api.model.builder.ObjectNameFactory;
+import org.jbpm.api.test.IntegrationTestHelper;
+
+/**
+ * Test that there are jars deployed which should in fact be provided by the container
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 23-Sep-2008
+ */
+public class ContainerProvidedJarsTest extends TestCase
+{
+ IntegrationTestHelper delegate = new IntegrationTestHelper();
+
+ public void testDependencies() throws Exception
+ {
+ String targetContainer = null;
+ if (delegate.isTargetJBoss422())
+ {
+ targetContainer = "jboss422";
+ }
+ else if (delegate.isTargetJBoss423())
+ {
+ targetContainer = "jboss423";
+ }
+ else if (delegate.isTargetJBoss500())
+ {
+ targetContainer = "jboss500";
+ }
+ assertNotNull("System property 'target.container' not null", targetContainer);
+ assertTrue("Supported target.container: " + targetContainer, "jboss422,jboss423,jboss500".indexOf(targetContainer) >= 0);
+
+ File jbossJars = delegate.getResourceFile(targetContainer + "-dependencies.txt");
+ assertTrue("JBoss jar fixture exists: " + jbossJars, jbossJars.exists());
+
+ // Read the JBoss ServerHomeDir
+ ObjectName oname = ObjectNameFactory.create("jboss.system:type=ServerConfig");
+ File serverHomeDir = (File)delegate.getServer().getAttribute(oname, "ServerHomeDir");
+ if (serverHomeDir == null)
+ throw new IllegalStateException("Cannot obtain jboss home dir");
+
+ File jbpmDir = new File(serverHomeDir + "/deploy/jbpm");
+ assertTrue("jBPM dir exists: " + jbpmDir, jbpmDir.exists());
+
+ // Store the deployed jars in a string builder
+ String deployedJars = getDeployedJars(jbpmDir).toString();
+
+ // Iterate over the known server provided jars
+ List<String> matchingJars = new ArrayList<String>();
+ BufferedReader br = new BufferedReader(new FileReader(jbossJars));
+ String line = br.readLine();
+ while (line != null)
+ {
+ if (line.length() == 0 || line.startsWith("#"))
+ {
+ line = br.readLine();
+ continue;
+ }
+
+ if (deployedJars.indexOf(line) > 0)
+ {
+ matchingJars.add(line);
+ }
+ line = br.readLine();
+ }
+
+ assertEquals("Invalid deployed jars: " + matchingJars, 0, matchingJars.size());
+ }
+
+ private List<String> getDeployedJars(File subdir)
+ {
+ List<String> deployedJars = new ArrayList<String>();
+ for (File file : subdir.listFiles())
+ {
+ if (file.isDirectory())
+ {
+ deployedJars.addAll(getDeployedJars(file));
+ continue;
+ }
+
+ String fileName = file.getName();
+ if (fileName.endsWith(".jar"))
+ deployedJars.add(fileName);
+ }
+ return deployedJars;
+ }
+}
Property changes on: jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/config/ContainerProvidedJarsTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/ejbtimer/EjbSchedulerTest.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/ejbtimer/EjbSchedulerTest.java (rev 0)
+++ jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/ejbtimer/EjbSchedulerTest.java 2008-11-21 11:26:42 UTC (rev 3025)
@@ -0,0 +1,321 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbpm.enterprise.ejbtimer;
+
+import java.rmi.RemoteException;
+import java.util.Collections;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.Test;
+
+import org.apache.cactus.ServletTestCase;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jbpm.EventCallback;
+import org.jbpm.JbpmContext;
+import org.jbpm.api.test.IntegrationTestSetup;
+import org.jbpm.command.Command;
+import org.jbpm.command.DeployProcessCommand;
+import org.jbpm.command.StartProcessInstanceCommand;
+import org.jbpm.ejb.LocalCommandService;
+import org.jbpm.ejb.LocalCommandServiceHome;
+import org.jbpm.graph.def.Event;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.graph.exe.Token;
+import org.jbpm.scheduler.ejbtimer.EntitySchedulerService;
+
+/**
+ * Exercises for the {@linkplain EntitySchedulerService EJB scheduler service}.
+ *
+ * @author Alejandro Guizar
+ */
+public class EjbSchedulerTest extends ServletTestCase {
+
+ private LocalCommandService commandService;
+
+ private static LocalCommandServiceHome commandServiceHome;
+
+ private static final Log log = LogFactory.getLog(EjbSchedulerTest.class);
+
+ public static Test suite() throws Exception {
+ return new IntegrationTestSetup(EjbSchedulerTest.class, "enterprise-test.war");
+ }
+
+ protected void setUp() throws Exception {
+ if (commandServiceHome == null) {
+ Context initialContext = new InitialContext();
+ try {
+ commandServiceHome = (LocalCommandServiceHome) initialContext.lookup("java:comp/env/ejb/CommandServiceBean");
+ }
+ finally {
+ initialContext.close();
+ }
+ }
+ commandService = commandServiceHome.create();
+ log.info("### " + getName() + " started ###");
+ }
+
+ protected void tearDown() throws Exception {
+ log.info("### " + getName() + " done ###");
+ commandService = null;
+ }
+
+ public void testScheduleFuture() throws Exception {
+ deployProcess("<process-definition name='future'>"
+ + " <event type='process-end'>"
+ + " <action expression='#{eventCallback.processEnd}'/>"
+ + " </event>"
+ + " <start-state name='start'>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <state name='a'>"
+ + " <timer duedate='1 second' transition='timeout' />"
+ + " <transition name='timeout' to='end' />"
+ + " </state>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
+ long processId = launchProcess("future").getId();
+ EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
+ assertTrue(isProcessFinished(processId));
+ }
+
+ public void testSchedulePast() throws Exception {
+ deployProcess("<process-definition name='past'>"
+ + " <event type='process-end'>"
+ + " <action expression='#{eventCallback.processEnd}'/>"
+ + " </event>"
+ + " <start-state name='start'>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <state name='a'>"
+ + " <timer duedate='-1 second' transition='timeout' />"
+ + " <transition name='timeout' to='end' />"
+ + " </state>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
+ long processId = launchProcess("past").getId();
+ EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
+ assertTrue(isProcessFinished(processId));
+ }
+
+ public void testScheduleRepeat() throws Exception {
+ deployProcess("<process-definition name='repeat'>"
+ + " <event type='timer'>"
+ + " <action expression='#{eventCallback.timer}'/>"
+ + " </event>"
+ + " <start-state name='start'>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <state name='a'>"
+ + " <timer duedate='1 second' repeat='1 second' />"
+ + " <transition to='end' />"
+ + " </state>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
+ long processId = launchProcess("repeat").getId();
+ for (int i = 0; i < 3; i++) {
+ EventCallback.waitForEvent(Event.EVENTTYPE_TIMER);
+ assertEquals("a", getProcessState(processId));
+ }
+ signalProcess(processId);
+ assertTrue(isProcessFinished(processId));
+ }
+
+ public void testCancel() throws Exception {
+ deployProcess("<process-definition name='cancel'>"
+ + " <event type='timer'>"
+ + " <action expression='#{eventCallback.timer}'/>"
+ + " </event>"
+ + " <start-state name='start'>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <state name='a'>"
+ + " <timer duedate='1 second' repeat='1 second' />"
+ + " <transition to='end' />"
+ + " </state>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
+ ProcessInstance process = launchProcess("cancel");
+ long processId = process.getId();
+ // first expiration
+ EventCallback.waitForEvent(Event.EVENTTYPE_TIMER);
+ assertEquals("a", getProcessState(processId));
+ // repeated expiration
+ EventCallback.waitForEvent(Event.EVENTTYPE_TIMER);
+ assertEquals("a", getProcessState(processId));
+ // no more expirations
+ cancelTimer("a", process.getRootToken().getId());
+ EventCallback.waitForEvent(Event.EVENTTYPE_TIMER, 2000);
+ signalProcess(processId);
+ assertTrue(isProcessFinished(processId));
+ }
+
+ public void testScheduleSequence() throws Exception {
+ deployProcess("<process-definition name='sequence'>"
+ + " <event type='process-end'>"
+ + " <action expression='#{eventCallback.processEnd}'/>"
+ + " </event>"
+ + " <event type='timer'>"
+ + " <action expression='#{eventCallback.timer}'/>"
+ + " </event>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <state name='a'>"
+ + " <timer duedate='500 milliseconds' transition='timeout' />"
+ + " <transition name='timeout' to='b' />"
+ + " </state>"
+ + " <state name='b'>"
+ + " <timer duedate='500 milliseconds' transition='timeout' />"
+ + " <transition name='timeout' to='c' />"
+ + " </state>"
+ + " <state name='c'>"
+ + " <timer duedate='500 milliseconds' transition='timeout' />"
+ + " <transition name='timeout' to='d' />"
+ + " </state>"
+ + " <state name='d'>"
+ + " <timer duedate='500 milliseconds' transition='timeout' />"
+ + " <transition name='timeout' to='e' />"
+ + " </state>"
+ + " <state name='e'>"
+ + " <timer duedate='500 milliseconds' transition='timeout' />"
+ + " <transition name='timeout' to='end' />"
+ + " </state>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
+ long processId = launchProcess("sequence").getId();
+ char state = 'b';
+ for (int i = 0; i < 4; i++) {
+ EventCallback.waitForEvent(Event.EVENTTYPE_TIMER);
+ assertEquals(Character.toString(state++), getProcessState(processId));
+ }
+ EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
+ assertTrue(isProcessFinished(processId));
+ }
+
+ public void testScheduleFork() throws Exception {
+ deployProcess("<process-definition name='fork'>"
+ + " <event type='process-end'>"
+ + " <action expression='#{eventCallback.processEnd}'/>"
+ + " </event>"
+ + " <start-state>"
+ + " <transition to='f' />"
+ + " </start-state>"
+ + " <fork name='f'>"
+ + " <transition name='a' to='a' />"
+ + " <transition name='b' to='b' />"
+ + " <transition name='c' to='c' />"
+ + " <transition name='d' to='d' />"
+ + " <transition name='e' to='e' />"
+ + " </fork>"
+ + " <state name='a'>"
+ + " <timer duedate='0.25 seconds' transition='timeout' />"
+ + " <transition name='timeout' to='j' />"
+ + " </state>"
+ + " <state name='b'>"
+ + " <timer duedate='0.5 seconds' transition='timeout' />"
+ + " <transition name='timeout' to='j' />"
+ + " </state>"
+ + " <state name='c'>"
+ + " <timer duedate='0.75 seconds' transition='timeout' />"
+ + " <transition name='timeout' to='j' />"
+ + " </state>"
+ + " <state name='d'>"
+ + " <timer duedate='1 second' transition='timeout' />"
+ + " <transition name='timeout' to='j' />"
+ + " </state>"
+ + " <state name='e'>"
+ + " <timer duedate='1.25 second' transition='timeout' />"
+ + " <transition name='timeout' to='j' />"
+ + " </state>"
+ + " <join name='j' async='exclusive'>"
+ + " <transition to='end' />"
+ + " </join>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
+ long processId = launchProcess("fork").getId();
+ EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
+ assertTrue(isProcessFinished(processId));
+ }
+
+ private ProcessDefinition deployProcess(String xml) throws RemoteException {
+ return (ProcessDefinition) commandService.execute(new DeployProcessCommand(xml));
+ }
+
+ private ProcessInstance launchProcess(String processName) throws RemoteException {
+ StartProcessInstanceCommand command = new StartProcessInstanceCommand();
+ command.setProcessName(processName);
+ command.setVariables(Collections.singletonMap("eventCallback", new EventCallback()));
+ return (ProcessInstance) commandService.execute(command);
+ }
+
+ private void signalProcess(final long processId) throws RemoteException {
+ commandService.execute(new Command() {
+
+ private static final long serialVersionUID = 1L;
+
+ public Object execute(JbpmContext jbpmContext) throws Exception {
+ jbpmContext.loadProcessInstanceForUpdate(processId).signal();
+ return null;
+ }
+ });
+ }
+
+ private String getProcessState(final long processId) throws RemoteException {
+ return (String) commandService.execute(new Command() {
+
+ private static final long serialVersionUID = 1L;
+
+ public Object execute(JbpmContext jbpmContext) throws Exception {
+ return jbpmContext.loadProcessInstance(processId).getRootToken().getNode().getName();
+ }
+ });
+ }
+
+ private boolean isProcessFinished(final long processId) throws RemoteException {
+ Boolean isFinished = (Boolean) commandService.execute(new Command() {
+
+ private static final long serialVersionUID = 1L;
+
+ public Object execute(JbpmContext jbpmContext) throws Exception {
+ return jbpmContext.loadProcessInstance(processId).hasEnded();
+ }
+ });
+ return isFinished.booleanValue();
+ }
+
+ private void cancelTimer(final String timerName, final long tokenId) throws RemoteException {
+ commandService.execute(new Command() {
+
+ private static final long serialVersionUID = 1L;
+
+ public Object execute(JbpmContext jbpmContext) throws Exception {
+ Token token = jbpmContext.loadToken(tokenId);
+ jbpmContext.getServices().getSchedulerService().deleteTimersByName(timerName, token);
+ return null;
+ }
+ });
+ }
+}
Property changes on: jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/ejbtimer/EjbSchedulerTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/jms/JmsMessageTest.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/jms/JmsMessageTest.java (rev 0)
+++ jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/jms/JmsMessageTest.java 2008-11-21 11:26:42 UTC (rev 3025)
@@ -0,0 +1,283 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbpm.enterprise.jms;
+
+import java.util.Collections;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.Test;
+
+import org.apache.cactus.ServletTestCase;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jbpm.EventCallback;
+import org.jbpm.JbpmContext;
+import org.jbpm.api.test.IntegrationTestSetup;
+import org.jbpm.command.Command;
+import org.jbpm.command.DeployProcessCommand;
+import org.jbpm.command.StartProcessInstanceCommand;
+import org.jbpm.ejb.LocalCommandService;
+import org.jbpm.ejb.LocalCommandServiceHome;
+import org.jbpm.graph.def.Event;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.msg.jms.JmsMessageService;
+
+/**
+ * Exercises for the {@linkplain JmsMessageService JMS message service}.
+ * @author Alejandro Guizar
+ */
+public class JmsMessageTest extends ServletTestCase {
+
+ private LocalCommandService commandService;
+
+ private static LocalCommandServiceHome commandServiceHome;
+
+ static final int processExecutionCount = 5;
+ static final int maxWaitTime = 10 * 1000;
+
+ public static Test suite() throws Exception {
+ return new IntegrationTestSetup(JmsMessageTest.class, "enterprise-test.war");
+ }
+
+ protected void setUp() throws Exception
+ {
+ if (commandServiceHome == null) {
+ Context initialContext = new InitialContext();
+ try {
+ commandServiceHome = (LocalCommandServiceHome) initialContext.lookup("java:comp/env/ejb/CommandServiceBean");
+ }
+ finally {
+ initialContext.close();
+ }
+ }
+ commandService = commandServiceHome.create();
+ log.info("### " + getName() + " started ###");
+ }
+
+ protected void tearDown() throws Exception
+ {
+ log.info("### " + getName() + " done ###");
+ commandService = null;
+ EventCallback.clear();
+ }
+
+ public void testAsyncNode()
+ {
+ deployProcess("<process-definition name='node'>"
+ + " <event type='process-end'>"
+ + " <action expression='#{eventCallback.processEnd}'/>"
+ + " </event>"
+ + " <start-state name='start'>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <node name='a' async='true'>"
+ + " <transition to='end' />"
+ + " </node>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
+ long processId = launchProcess("node").getId();
+ EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
+ assertTrue("Process has ended", hasProcessEnded(processId));
+ }
+
+ public void testAsyncAction()
+ {
+ deployProcess("<process-definition name='action'>"
+ + " <start-state name='start'>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <node name='a'>"
+ + " <event type='node-enter'>"
+ + " <action async='true' expression='#{eventCallback.nodeEnter}' />"
+ + " </event>"
+ + " <event type='node-leave'>"
+ + " <action async='true' expression='#{eventCallback.nodeLeave}' />"
+ + " </event>"
+ + " <transition to='end'>"
+ + " <action async='true' expression='#{eventCallback.transition}' />"
+ + " </transition>"
+ + " </node>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
+ long processId = launchProcess("action").getId();
+ EventCallback.waitForEvent(Event.EVENTTYPE_NODE_ENTER);
+ EventCallback.waitForEvent(Event.EVENTTYPE_NODE_LEAVE);
+ EventCallback.waitForEvent(Event.EVENTTYPE_TRANSITION);
+ assertTrue("Process has ended", hasProcessEnded(processId));
+ }
+
+ public void testAsyncSequence()
+ {
+ deployProcess("<process-definition name='sequence'>"
+ + " <event type='process-end'>"
+ + " <action expression='#{eventCallback.processEnd}'/>"
+ + " </event>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <node name='a' async='true'>"
+ + " <transition to='b' />"
+ + " </node>"
+ + " <node name='b' async='true'>"
+ + " <transition to='c' />"
+ + " </node>"
+ + " <node name='c' async='true'>"
+ + " <transition to='d' />"
+ + " </node>"
+ + " <node name='d' async='true'>"
+ + " <transition to='e' />"
+ + " </node>"
+ + " <node name='e' async='true'>"
+ + " <transition to='end' />"
+ + " </node>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
+ long processId = launchProcess("sequence").getId();
+ EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
+ assertTrue("Process has ended", hasProcessEnded(processId));
+ }
+
+ public void testAsyncFork() throws Exception
+ {
+ deployProcess("<process-definition name='fork'>"
+ + " <event type='process-end'>"
+ + " <action expression='#{eventCallback.processEnd}'/>"
+ + " </event>"
+ + " <start-state>"
+ + " <transition to='f' />"
+ + " </start-state>"
+ + " <fork name='f'>"
+ + " <transition name='a' to='a' />"
+ + " <transition name='b' to='b' />"
+ + " <transition name='c' to='c' />"
+ + " <transition name='d' to='d' />"
+ + " <transition name='e' to='e' />"
+ + " </fork>"
+ + " <node name='a'>"
+ + " <transition to='j' />"
+ + " </node>"
+ + " <node name='b' async='true'>"
+ + " <transition to='j' />"
+ + " </node>"
+ + " <node name='c' async='true'>"
+ + " <transition to='j' />"
+ + " </node>"
+ + " <node name='d' async='true'>"
+ + " <transition to='j' />"
+ + " </node>"
+ + " <node name='e' async='true'>"
+ + " <transition to='j' />"
+ + " </node>"
+ + " <join name='j' async='exclusive'>"
+ + " <transition to='end' />"
+ + " </join>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
+ long processId = launchProcess("fork").getId();
+ EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
+ Thread.sleep(1000);
+ assertTrue("Process has ended", hasProcessEnded(processId));
+ }
+
+ public void testAsyncExecutions()
+ {
+ deployProcess("<process-definition name='execution'>"
+ + " <event type='process-end'>"
+ + " <action expression='#{eventCallback.processEnd}' />"
+ + " </event>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <node name='a' async='true'>"
+ + " <transition to='b' />"
+ + " </node>"
+ + " <node name='b'>"
+ + " <event type='node-enter'>"
+ + " <action async='exclusive' expression='#{eventCallback.nodeEnter}' />"
+ + " </event>"
+ + " <transition to='c' />"
+ + " </node>"
+ + " <node name='c' async='exclusive'>"
+ + " <transition to='d' />"
+ + " </node>"
+ + " <node name='d'>"
+ + " <event type='node-leave'>"
+ + " <action async='exclusive' expression='#{eventCallback.nodeLeave}' />"
+ + " </event>"
+ + " <transition to='e' />"
+ + " </node>"
+ + " <node name='e' async='exclusive'>"
+ + " <transition to='end' />"
+ + " </node>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
+ long[] processIds = new long[processExecutionCount];
+ for (int i = 0; i < processExecutionCount; i++) {
+ processIds[i] = launchProcess("execution").getId();
+ EventCallback.waitForEvent(Event.EVENTTYPE_NODE_ENTER);
+ }
+ for (int i = 0; i < processExecutionCount; i++) {
+ EventCallback.waitForEvent(Event.EVENTTYPE_NODE_LEAVE);
+ }
+ for (int i = 0; i < processExecutionCount; i++) {
+ waitForProcessEnd(processIds[i]);
+ assertTrue(hasProcessEnded(processIds[i]));
+ }
+ }
+
+ private ProcessDefinition deployProcess(String xml) {
+ return (ProcessDefinition) commandService.execute(new DeployProcessCommand(xml));
+ }
+
+ private ProcessInstance launchProcess(String processName) {
+ StartProcessInstanceCommand command = new StartProcessInstanceCommand();
+ command.setProcessName(processName);
+ command.setVariables(Collections.singletonMap("eventCallback", new EventCallback()));
+ return (ProcessInstance) commandService.execute(command);
+ }
+
+ private boolean hasProcessEnded(final long processId) {
+ Boolean isFinished = (Boolean) commandService.execute(new Command() {
+ private static final long serialVersionUID = 1L;
+ public Object execute(JbpmContext jbpmContext) throws Exception {
+ return jbpmContext.loadProcessInstance(processId).hasEnded();
+ }
+ });
+ return isFinished.booleanValue();
+ }
+
+ private void waitForProcessEnd(long processId) {
+ long startTime = System.currentTimeMillis();
+ do {
+ EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END, 1000);
+ if (System.currentTimeMillis() - startTime > maxWaitTime) {
+ log.warn("process " + processId + " took too long");
+ break;
+ }
+ } while (!hasProcessEnded(processId));
+ }
+
+ private static Log log = LogFactory.getLog(JmsMessageTest.class);
+}
Property changes on: jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/jms/JmsMessageTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/jta (from rev 3019, jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/persistence/jta)
Deleted: jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/persistence/jta/JtaDbPersistenceTest.java 2008-11-21 10:10:35 UTC (rev 3019)
+++ jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java 2008-11-21 11:26:42 UTC (rev 3025)
@@ -1,252 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, 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.jbpm.persistence.jta;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.transaction.UserTransaction;
-
-import junit.framework.Test;
-
-import org.apache.cactus.ServletTestCase;
-import org.jbpm.JbpmConfiguration;
-import org.jbpm.JbpmContext;
-import org.jbpm.api.test.IntegrationTestSetup;
-import org.jbpm.graph.def.ProcessDefinition;
-import org.jbpm.graph.exe.ProcessInstance;
-
-public class JtaDbPersistenceTest extends ServletTestCase
-{
-
- private JbpmConfiguration jbpmConfiguration;
- private UserTransaction tx;
- private boolean rollback;
-
- private static long definitionId;
-
- public static Test suite() throws Exception
- {
- return new IntegrationTestSetup(JtaDbPersistenceTest.class, "enterprise-test.war");
- }
-
- protected void setUp() throws Exception
- {
- jbpmConfiguration = JbpmConfiguration.getInstance();
- }
-
- public void testUserTx() throws Exception
- {
- tx = getUserTransaction();
- testServiceTx();
- }
-
- public void testUserTxRollback() throws Exception
- {
- tx = getUserTransaction();
- testServiceTxRollback();
- }
-
- public void testServiceTx() throws Exception
- {
- long definitionId = deployProcess();
- long instanceId = launchProcess(definitionId);
- signal(instanceId);
- assertTrue(hasEnded(instanceId));
- }
-
- public void testServiceTxRollback() throws Exception
- {
- rollback = true;
- long definitionId = deployProcess();
- long instanceId = launchProcess(definitionId);
- signal(instanceId);
- assertFalse(hasEnded(instanceId));
- }
-
- private long deployProcess() throws Exception
- {
- if (definitionId == 0)
- {
- try
- {
- if (tx != null)
- tx.begin();
- JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- try
- {
- assertEquals(tx == null, isTxCreatedByService(jbpmContext));
- ProcessDefinition definition = ProcessDefinition.parseXmlString("<process-definition name='tx'>" + " <start-state name='start'>"
- + " <transition to='midway' />" + " </start-state>" + " <state name='midway'>" + " <transition to='end' />" + " </state>"
- + " <end-state name='end' />" + "</process-definition>");
- jbpmContext.deployProcessDefinition(definition);
- definitionId = definition.getId();
- }
- catch (RuntimeException e)
- {
- if (tx == null)
- jbpmContext.setRollbackOnly();
- throw e;
- }
- finally
- {
- jbpmContext.close();
- }
- if (tx != null)
- tx.commit();
- }
- catch (Exception e)
- {
- if (tx != null)
- tx.rollback();
- throw e;
- }
- }
- return definitionId;
- }
-
- private long launchProcess(long definitionId) throws Exception
- {
- try
- {
- if (tx != null)
- tx.begin();
- JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- ProcessInstance instance;
- try
- {
- assertEquals(tx == null, isTxCreatedByService(jbpmContext));
- ProcessDefinition definition = jbpmContext.getGraphSession().loadProcessDefinition(definitionId);
- instance = new ProcessInstance(definition);
- instance.signal();
- jbpmContext.save(instance);
- }
- catch (RuntimeException e)
- {
- if (tx == null)
- jbpmContext.setRollbackOnly();
- throw e;
- }
- finally
- {
- jbpmContext.close();
- }
- if (tx != null)
- tx.commit();
- return instance.getId();
- }
- catch (Exception e)
- {
- if (tx != null)
- tx.rollback();
- throw e;
- }
- }
-
- private void signal(long instanceId) throws Exception
- {
- try
- {
- if (tx != null)
- tx.begin();
- JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- try
- {
- assertEquals(tx == null, isTxCreatedByService(jbpmContext));
- ProcessInstance instance = jbpmContext.loadProcessInstanceForUpdate(instanceId);
- instance.signal();
- if (rollback && tx == null)
- jbpmContext.setRollbackOnly();
- }
- catch (RuntimeException e)
- {
- if (tx == null)
- jbpmContext.setRollbackOnly();
- throw e;
- }
- finally
- {
- jbpmContext.close();
- }
- if (tx != null)
- {
- if (rollback)
- tx.rollback();
- else
- tx.commit();
- }
- }
- catch (Exception e)
- {
- if (tx != null)
- tx.rollback();
- throw e;
- }
- }
-
- private boolean hasEnded(long instanceId) throws Exception
- {
- try
- {
- if (tx != null)
- tx.begin();
- JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- ProcessInstance instance;
- try
- {
- assertEquals(tx == null, isTxCreatedByService(jbpmContext));
- instance = jbpmContext.loadProcessInstanceForUpdate(instanceId);
- }
- catch (RuntimeException e)
- {
- if (tx == null)
- jbpmContext.setRollbackOnly();
- throw e;
- }
- finally
- {
- jbpmContext.close();
- }
- if (tx != null)
- tx.commit();
- return instance.hasEnded();
- }
- catch (Exception e)
- {
- if (tx != null)
- tx.rollback();
- throw e;
- }
- }
-
- private boolean isTxCreatedByService(JbpmContext jbpmContext)
- {
- JtaDbPersistenceService persistenceService = (JtaDbPersistenceService)jbpmContext.getServices().getPersistenceService();
- return persistenceService.isJtaTxCreated();
- }
-
- private static UserTransaction getUserTransaction() throws NamingException
- {
- Context initial = new InitialContext();
- return (UserTransaction)initial.lookup("java:comp/UserTransaction");
- }
-}
Copied: jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java (from rev 3024, jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/persistence/jta/JtaDbPersistenceTest.java)
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java (rev 0)
+++ jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java 2008-11-21 11:26:42 UTC (rev 3025)
@@ -0,0 +1,253 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbpm.enterprise.jta;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.transaction.UserTransaction;
+
+import junit.framework.Test;
+
+import org.apache.cactus.ServletTestCase;
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmContext;
+import org.jbpm.api.test.IntegrationTestSetup;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.persistence.jta.JtaDbPersistenceService;
+
+public class JtaDbPersistenceTest extends ServletTestCase
+{
+
+ private JbpmConfiguration jbpmConfiguration;
+ private UserTransaction tx;
+ private boolean rollback;
+
+ private static long definitionId;
+
+ public static Test suite() throws Exception
+ {
+ return new IntegrationTestSetup(JtaDbPersistenceTest.class, "enterprise-test.war");
+ }
+
+ protected void setUp() throws Exception
+ {
+ jbpmConfiguration = JbpmConfiguration.getInstance();
+ }
+
+ public void testUserTx() throws Exception
+ {
+ tx = getUserTransaction();
+ testServiceTx();
+ }
+
+ public void testUserTxRollback() throws Exception
+ {
+ tx = getUserTransaction();
+ testServiceTxRollback();
+ }
+
+ public void testServiceTx() throws Exception
+ {
+ long definitionId = deployProcess();
+ long instanceId = launchProcess(definitionId);
+ signal(instanceId);
+ assertTrue(hasEnded(instanceId));
+ }
+
+ public void testServiceTxRollback() throws Exception
+ {
+ rollback = true;
+ long definitionId = deployProcess();
+ long instanceId = launchProcess(definitionId);
+ signal(instanceId);
+ assertFalse(hasEnded(instanceId));
+ }
+
+ private long deployProcess() throws Exception
+ {
+ if (definitionId == 0)
+ {
+ try
+ {
+ if (tx != null)
+ tx.begin();
+ JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+ try
+ {
+ assertEquals(tx == null, isTxCreatedByService(jbpmContext));
+ ProcessDefinition definition = ProcessDefinition.parseXmlString("<process-definition name='tx'>" + " <start-state name='start'>"
+ + " <transition to='midway' />" + " </start-state>" + " <state name='midway'>" + " <transition to='end' />" + " </state>"
+ + " <end-state name='end' />" + "</process-definition>");
+ jbpmContext.deployProcessDefinition(definition);
+ definitionId = definition.getId();
+ }
+ catch (RuntimeException e)
+ {
+ if (tx == null)
+ jbpmContext.setRollbackOnly();
+ throw e;
+ }
+ finally
+ {
+ jbpmContext.close();
+ }
+ if (tx != null)
+ tx.commit();
+ }
+ catch (Exception e)
+ {
+ if (tx != null)
+ tx.rollback();
+ throw e;
+ }
+ }
+ return definitionId;
+ }
+
+ private long launchProcess(long definitionId) throws Exception
+ {
+ try
+ {
+ if (tx != null)
+ tx.begin();
+ JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+ ProcessInstance instance;
+ try
+ {
+ assertEquals(tx == null, isTxCreatedByService(jbpmContext));
+ ProcessDefinition definition = jbpmContext.getGraphSession().loadProcessDefinition(definitionId);
+ instance = new ProcessInstance(definition);
+ instance.signal();
+ jbpmContext.save(instance);
+ }
+ catch (RuntimeException e)
+ {
+ if (tx == null)
+ jbpmContext.setRollbackOnly();
+ throw e;
+ }
+ finally
+ {
+ jbpmContext.close();
+ }
+ if (tx != null)
+ tx.commit();
+ return instance.getId();
+ }
+ catch (Exception e)
+ {
+ if (tx != null)
+ tx.rollback();
+ throw e;
+ }
+ }
+
+ private void signal(long instanceId) throws Exception
+ {
+ try
+ {
+ if (tx != null)
+ tx.begin();
+ JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+ try
+ {
+ assertEquals(tx == null, isTxCreatedByService(jbpmContext));
+ ProcessInstance instance = jbpmContext.loadProcessInstanceForUpdate(instanceId);
+ instance.signal();
+ if (rollback && tx == null)
+ jbpmContext.setRollbackOnly();
+ }
+ catch (RuntimeException e)
+ {
+ if (tx == null)
+ jbpmContext.setRollbackOnly();
+ throw e;
+ }
+ finally
+ {
+ jbpmContext.close();
+ }
+ if (tx != null)
+ {
+ if (rollback)
+ tx.rollback();
+ else
+ tx.commit();
+ }
+ }
+ catch (Exception e)
+ {
+ if (tx != null)
+ tx.rollback();
+ throw e;
+ }
+ }
+
+ private boolean hasEnded(long instanceId) throws Exception
+ {
+ try
+ {
+ if (tx != null)
+ tx.begin();
+ JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+ ProcessInstance instance;
+ try
+ {
+ assertEquals(tx == null, isTxCreatedByService(jbpmContext));
+ instance = jbpmContext.loadProcessInstanceForUpdate(instanceId);
+ }
+ catch (RuntimeException e)
+ {
+ if (tx == null)
+ jbpmContext.setRollbackOnly();
+ throw e;
+ }
+ finally
+ {
+ jbpmContext.close();
+ }
+ if (tx != null)
+ tx.commit();
+ return instance.hasEnded();
+ }
+ catch (Exception e)
+ {
+ if (tx != null)
+ tx.rollback();
+ throw e;
+ }
+ }
+
+ private boolean isTxCreatedByService(JbpmContext jbpmContext)
+ {
+ JtaDbPersistenceService persistenceService = (JtaDbPersistenceService)jbpmContext.getServices().getPersistenceService();
+ return persistenceService.isJtaTxCreated();
+ }
+
+ private static UserTransaction getUserTransaction() throws NamingException
+ {
+ Context initial = new InitialContext();
+ return (UserTransaction)initial.lookup("java:comp/UserTransaction");
+ }
+}
More information about the jbpm-commits
mailing list