Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

JBPM-3434: make test classes use marshalling framework

  • Loading branch information...
commit de588849c40c123f400707867283dcdb4954bf62 1 parent a203e12
@mrietveld mrietveld authored
Showing with 745 additions and 370 deletions.
  1. +1 −0  jbpm-bam/.gitignore
  2. +48 −67 jbpm-bam/src/test/java/org/jbpm/process/audit/JPAWorkingMemoryDbLoggerTest.java
  3. +8 −4 ...sistence-jpa/src/test/java/org/jbpm → jbpm-bam/src/test/java/org/jbpm/process/audit}/JbpmTestCase.java
  4. +28 −6 jbpm-bam/src/test/java/org/jbpm/process/audit/WorkingMemoryDbLoggerTest.java
  5. +2 −3 jbpm-bam/src/test/resources/hibernate.cfg.xml
  6. +0 −1  jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/BPMN2Test.java
  7. +8 −3 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/BPMN2XMLTest.java
  8. +20 −34 jbpm-bpmn2/src/test/java/org/jbpm/{ → bpmn2}/JbpmJUnitTestCase.java
  9. +31 −19 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/SimpleBPMNProcessTest.java
  10. +53 −0 jbpm-bpmn2/src/test/resources/log4j.xml
  11. +1 −0  jbpm-flow-builder/.gitignore
  12. +1 −0  jbpm-flow/.gitignore
  13. +20 −17 jbpm-gwt/jbpm-gwt-core/src/test/java/org/jbpm/integration/JbpmTestCase.java
  14. +0 −1  jbpm-gwt/jbpm-gwt-core/src/test/java/org/jbpm/integration/console/ProcessManagementTest.java
  15. +2 −4 ...am/src/test/java/org/jbpm → jbpm-persistence-jpa/src/test/java/org/jbpm/persistence}/JbpmTestCase.java
  16. +14 −28 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/map/impl/JpaBasedPersistenceTest.java
  17. +3 −4 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/map/impl/MapBasedPersistenceTest.java
  18. +10 −3 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/map/impl/MapPersistenceTest.java
  19. +33 −62 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/PersistentStatefulSessionTest.java
  20. +33 −53 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/SingleSessionCommandServiceTest.java
  21. +45 −23 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/VariablePersistenceStrategyTest.java
  22. +302 −0 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/WorkItemPersistenceTest.java
  23. +1 −1  jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/{ → objects}/MyEntity.java
  24. +1 −1  jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/{ → objects}/MyEntityMethods.java
  25. +1 −1  jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/{ → objects}/MyEntityOnlyFields.java
  26. +1 −1  jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/{ → objects}/MySubEntity.java
  27. +1 −1  jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/{ → objects}/MySubEntityMethods.java
  28. +3 −1 ...tence-jpa/src/test/java/org/jbpm/persistence/session/{ → objects}/MyVariableExtendingSerializable.java
  29. +1 −1  jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/{ → objects}/MyVariableSerializable.java
  30. +22 −0 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/objects/Person.java
  31. +1 −1  jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/{ → objects}/TestWorkItemHandler.java
  32. +1 −1  ...ce-jpa/src/test/java/org/jbpm/persistence/session/{ → objects}/VariableCheckerTestWorkItemHandler.java
  33. +1 −1  jbpm-persistence-jpa/src/test/resources/META-INF/MyWorkItemHandlers.conf
  34. +6 −6 jbpm-persistence-jpa/src/test/resources/VPSProcessWithWorkItems.rf
  35. +6 −6 jbpm-persistence-jpa/src/test/resources/VariablePersistenceStrategyProcess.rf
  36. +2 −2 jbpm-persistence-jpa/src/test/resources/VariablePersistenceStrategyProcessTypeChange.rf
  37. +6 −6 jbpm-persistence-jpa/src/test/resources/VariablePersistenceStrategySubProcess.rf
  38. +26 −6 jbpm-persistence-jpa/src/test/resources/log4j.xml
  39. +2 −2 jbpm-persistence-jpa/src/test/resources/testVariables.rf
View
1  jbpm-bam/.gitignore
@@ -11,3 +11,4 @@
# test database
/JPADroolsFlow.*.db
+/btm.*
View
115 jbpm-bam/src/test/java/org/jbpm/process/audit/JPAWorkingMemoryDbLoggerTest.java
@@ -16,7 +16,8 @@
package org.jbpm.process.audit;
-import static org.jbpm.persistence.util.PersistenceUtil.*;
+import static org.drools.persistence.util.PersistenceUtil.*;
+import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.HashMap;
@@ -24,9 +25,6 @@
import java.util.Map;
import java.util.Properties;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
@@ -34,47 +32,42 @@
import org.drools.builder.ResourceType;
import org.drools.io.impl.ClassPathResource;
import org.drools.persistence.jpa.JPAKnowledgeService;
+import org.drools.persistence.util.PersistenceUtil;
import org.drools.runtime.Environment;
-import org.drools.runtime.EnvironmentName;
import org.drools.runtime.KnowledgeSessionConfiguration;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.WorkItem;
import org.drools.runtime.process.WorkItemHandler;
import org.drools.runtime.process.WorkItemManager;
-import org.jbpm.JbpmTestCase;
import org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler;
-
-import bitronix.tm.TransactionManagerServices;
-import bitronix.tm.resource.jdbc.PoolingDataSource;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class JPAWorkingMemoryDbLoggerTest extends JbpmTestCase {
- PoolingDataSource ds1;
- EntityManagerFactory emf;
+ private HashMap<String, Object> context;
+ private Logger logger = LoggerFactory.getLogger(JPAWorkingMemoryDbLoggerTest.class);
- @Override
- protected void setUp() throws Exception {
- ds1 = setupPoolingDataSource();
- ds1.init();
-
- emf = Persistence.createEntityManagerFactory( PERSISTENCE_UNIT_NAME );
+ @Before
+ public void setUp() throws Exception {
+ context = setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME);
}
- @Override
- protected void tearDown() throws Exception {
- ds1.close();
+ @After
+ public void tearDown() throws Exception {
+ PersistenceUtil.tearDown(context);
}
+ @Test
public void testLogger1() throws Exception {
// load the process
KnowledgeBase kbase = createKnowledgeBase();
// create a new session
- Environment env = KnowledgeBaseFactory.newEnvironment();
- env.set( EnvironmentName.ENTITY_MANAGER_FACTORY,
- emf );
- env.set( EnvironmentName.TRANSACTION_MANAGER,
- TransactionManagerServices.getTransactionManager() );
+ Environment env = createEnvironment(context);
Properties properties = new Properties();
properties.put("drools.processInstanceManagerFactory", "org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");
properties.put("drools.processSignalManagerFactory", "org.jbpm.persistence.processinstance.JPASignalManagerFactory");
@@ -92,12 +85,12 @@ public void testLogger1() throws Exception {
// start process instance
long processInstanceId = session.startProcess("com.sample.ruleflow").getId();
- System.out.println("Checking process instances for process 'com.sample.ruleflow'");
+ logger.debug("Checking process instances for process 'com.sample.ruleflow'");
processInstances = log.findProcessInstances("com.sample.ruleflow");
assertEquals(initialProcessInstanceSize + 1, processInstances.size());
ProcessInstanceLog processInstance = processInstances.get(0);
- System.out.print(processInstance);
- System.out.println(" -> " + processInstance.getStart() + " - " + processInstance.getEnd());
+ logger.debug(processInstance.toString()
+ + " -> " + processInstance.getStart() + " - " + processInstance.getEnd());
assertNotNull(processInstance.getStart());
assertNotNull(processInstance.getEnd());
assertEquals(processInstanceId, processInstance.getProcessInstanceId());
@@ -105,7 +98,7 @@ public void testLogger1() throws Exception {
List<NodeInstanceLog> nodeInstances = log.findNodeInstances(processInstanceId);
assertEquals(6, nodeInstances.size());
for (NodeInstanceLog nodeInstance: nodeInstances) {
- System.out.println(nodeInstance);
+ logger.debug(nodeInstance.toString());
assertEquals(processInstanceId, processInstance.getProcessInstanceId());
assertEquals("com.sample.ruleflow", processInstance.getProcessId());
assertNotNull(nodeInstance.getDate());
@@ -116,15 +109,12 @@ public void testLogger1() throws Exception {
log.dispose();
}
+ @Test
public void testLogger2() {
// load the process
KnowledgeBase kbase = createKnowledgeBase();
// create a new session
- Environment env = KnowledgeBaseFactory.newEnvironment();
- env.set( EnvironmentName.ENTITY_MANAGER_FACTORY,
- emf );
- env.set( EnvironmentName.TRANSACTION_MANAGER,
- TransactionManagerServices.getTransactionManager() );
+ Environment env = createEnvironment(context);
Properties properties = new Properties();
properties.put("drools.processInstanceManagerFactory", "org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");
properties.put("drools.processSignalManagerFactory", "org.jbpm.persistence.processinstance.JPASignalManagerFactory");
@@ -143,16 +133,16 @@ public void testLogger2() {
session.startProcess("com.sample.ruleflow");
session.startProcess("com.sample.ruleflow");
- System.out.println("Checking process instances for process 'com.sample.ruleflow'");
+ logger.debug("Checking process instances for process 'com.sample.ruleflow'");
processInstances = log.findProcessInstances("com.sample.ruleflow");
assertEquals(initialProcessInstanceSize + 2, processInstances.size());
for (ProcessInstanceLog processInstance: processInstances) {
- System.out.print(processInstance);
- System.out.println(" -> " + processInstance.getStart() + " - " + processInstance.getEnd());
+ logger.debug(processInstance.toString()
+ + " -> " + processInstance.getStart() + " - " + processInstance.getEnd());
List<NodeInstanceLog> nodeInstances = log.findNodeInstances(processInstance.getProcessInstanceId());
for (NodeInstanceLog nodeInstance: nodeInstances) {
- System.out.print(nodeInstance);
- System.out.println(" -> " + nodeInstance.getDate());
+ logger.debug(nodeInstance.toString()
+ + " -> " + nodeInstance.getDate());
}
assertEquals(6, nodeInstances.size());
}
@@ -160,15 +150,12 @@ public void testLogger2() {
log.dispose();
}
+ @Test
public void testLogger3() {
// load the process
KnowledgeBase kbase = createKnowledgeBase();
// create a new session
- Environment env = KnowledgeBaseFactory.newEnvironment();
- env.set( EnvironmentName.ENTITY_MANAGER_FACTORY,
- emf );
- env.set( EnvironmentName.TRANSACTION_MANAGER,
- TransactionManagerServices.getTransactionManager() );
+ Environment env = createEnvironment(context);
Properties properties = new Properties();
properties.put("drools.processInstanceManagerFactory", "org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");
properties.put("drools.processSignalManagerFactory", "org.jbpm.persistence.processinstance.JPASignalManagerFactory");
@@ -186,20 +173,20 @@ public void testLogger3() {
// start process instance
long processInstanceId = session.startProcess("com.sample.ruleflow2").getId();
- System.out.println("Checking process instances for process 'com.sample.ruleflow2'");
+ logger.debug("Checking process instances for process 'com.sample.ruleflow2'");
processInstances = log.findProcessInstances("com.sample.ruleflow2");
assertEquals(initialProcessInstanceSize + 1, processInstances.size());
ProcessInstanceLog processInstance = processInstances.get(0);
- System.out.print(processInstance);
- System.out.println(" -> " + processInstance.getStart() + " - " + processInstance.getEnd());
+ logger.debug(processInstance.toString()
+ + " -> " + processInstance.getStart() + " - " + processInstance.getEnd());
assertNotNull(processInstance.getStart());
assertNotNull(processInstance.getEnd());
assertEquals(processInstanceId, processInstance.getProcessInstanceId());
assertEquals("com.sample.ruleflow2", processInstance.getProcessId());
List<NodeInstanceLog> nodeInstances = log.findNodeInstances(processInstanceId);
for (NodeInstanceLog nodeInstance: nodeInstances) {
- System.out.print(nodeInstance);
- System.out.println(" -> " + nodeInstance.getDate());
+ logger.debug(nodeInstance.toString()
+ + " -> " + nodeInstance.getDate());
assertEquals(processInstanceId, processInstance.getProcessInstanceId());
assertEquals("com.sample.ruleflow2", processInstance.getProcessId());
assertNotNull(nodeInstance.getDate());
@@ -209,15 +196,12 @@ public void testLogger3() {
log.dispose();
}
+ @Test
public void testLogger4() throws Exception {
// load the process
KnowledgeBase kbase = createKnowledgeBase();
// create a new session
- Environment env = KnowledgeBaseFactory.newEnvironment();
- env.set( EnvironmentName.ENTITY_MANAGER_FACTORY,
- emf );
- env.set( EnvironmentName.TRANSACTION_MANAGER,
- TransactionManagerServices.getTransactionManager() );
+ Environment env = createEnvironment(context);
Properties properties = new Properties();
properties.put("drools.processInstanceManagerFactory", "org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");
properties.put("drools.processSignalManagerFactory", "org.jbpm.persistence.processinstance.JPASignalManagerFactory");
@@ -249,13 +233,13 @@ public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
params.put("list", list);
long processInstanceId = session.startProcess("com.sample.ruleflow3", params).getId();
- System.out.println("Checking process instances for process 'com.sample.ruleflow3'");
+ logger.debug("Checking process instances for process 'com.sample.ruleflow3'");
processInstances =
log.findProcessInstances("com.sample.ruleflow3");
assertEquals(initialProcessInstanceSize + 1, processInstances.size());
ProcessInstanceLog processInstance = processInstances.get(0);
- System.out.print(processInstance);
- System.out.println(" -> " + processInstance.getStart() + " - " + processInstance.getEnd());
+ logger.debug(processInstance.toString()
+ + " -> " + processInstance.getStart() + " - " + processInstance.getEnd());
assertNotNull(processInstance.getStart());
assertNotNull(processInstance.getEnd());
assertEquals(processInstanceId, processInstance.getProcessInstanceId());
@@ -263,7 +247,7 @@ public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
List<VariableInstanceLog> variableInstances = log.findVariableInstances(processInstanceId);
assertEquals(6, variableInstances.size());
for (VariableInstanceLog variableInstance: variableInstances) {
- System.out.println(variableInstance);
+ logger.debug(variableInstance.toString());
assertEquals(processInstanceId, processInstance.getProcessInstanceId());
assertEquals("com.sample.ruleflow3", processInstance.getProcessId());
assertNotNull(variableInstance.getDate());
@@ -274,15 +258,12 @@ public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
log.dispose();
}
+ @Test
public void testLogger4LargeVariable() throws Exception {
// load the process
KnowledgeBase kbase = createKnowledgeBase();
// create a new session
- Environment env = KnowledgeBaseFactory.newEnvironment();
- env.set( EnvironmentName.ENTITY_MANAGER_FACTORY,
- emf );
- env.set( EnvironmentName.TRANSACTION_MANAGER,
- TransactionManagerServices.getTransactionManager() );
+ Environment env = createEnvironment(context);
Properties properties = new Properties();
properties.put("drools.processInstanceManagerFactory", "org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");
properties.put("drools.processSignalManagerFactory", "org.jbpm.persistence.processinstance.JPASignalManagerFactory");
@@ -318,12 +299,12 @@ public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
params.put("list", list);
long processInstanceId = session.startProcess("com.sample.ruleflow3", params).getId();
- System.out.println("Checking process instances for process 'com.sample.ruleflow3'");
+ logger.debug("Checking process instances for process 'com.sample.ruleflow3'");
processInstances = log.findProcessInstances("com.sample.ruleflow3");
assertEquals(initialProcessInstanceSize + 1, processInstances.size());
ProcessInstanceLog processInstance = processInstances.get(0);
- System.out.print(processInstance);
- System.out.println(" -> " + processInstance.getStart() + " - " + processInstance.getEnd());
+ logger.debug(processInstance.toString()
+ + " -> " + processInstance.getStart() + " - " + processInstance.getEnd());
assertNotNull(processInstance.getStart());
assertNotNull(processInstance.getEnd());
assertEquals(processInstanceId, processInstance.getProcessInstanceId());
@@ -331,7 +312,7 @@ public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
List<VariableInstanceLog> variableInstances = log.findVariableInstances(processInstanceId);
assertEquals(6, variableInstances.size());
for (VariableInstanceLog variableInstance: variableInstances) {
- System.out.println(variableInstance);
+ logger.debug(variableInstance.toString());
assertEquals(processInstanceId, processInstance.getProcessInstanceId());
assertEquals("com.sample.ruleflow3", processInstance.getProcessId());
assertNotNull(variableInstance.getDate());
View
12 .../src/test/java/org/jbpm/JbpmTestCase.java → .../org/jbpm/process/audit/JbpmTestCase.java
@@ -1,6 +1,4 @@
-package org.jbpm;
-
-import junit.framework.TestCase;
+package org.jbpm.process.audit;
import org.drools.compiler.ProcessBuilderFactory;
import org.drools.marshalling.impl.ProcessMarshallerFactory;
@@ -9,7 +7,13 @@
import org.jbpm.process.builder.ProcessBuilderFactoryServiceImpl;
import org.jbpm.process.instance.ProcessRuntimeFactoryServiceImpl;
-public abstract class JbpmTestCase extends TestCase {
+/**
+ * Base test case for the jbpm-bame module.
+ *
+ * Please keep this test class in the org.jbpm.bam package or otherwise give it a unique name.
+ *
+ */
+public abstract class JbpmTestCase {
static {
ProcessBuilderFactory.setProcessBuilderFactoryService(new ProcessBuilderFactoryServiceImpl());
View
34 jbpm-bam/src/test/java/org/jbpm/process/audit/WorkingMemoryDbLoggerTest.java
@@ -16,8 +16,11 @@
package org.jbpm.process.audit;
+import static org.drools.persistence.util.PersistenceUtil.*;
+import static org.junit.Assert.*;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.util.HashMap;
import java.util.List;
import java.util.Properties;
@@ -27,12 +30,29 @@
import org.drools.StatefulSession;
import org.drools.compiler.PackageBuilder;
import org.drools.impl.EnvironmentFactory;
+import org.drools.persistence.util.PersistenceUtil;
import org.drools.rule.Package;
-import org.jbpm.JbpmTestCase;
+import org.jbpm.process.audit.JbpmTestCase;
import org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
public class WorkingMemoryDbLoggerTest extends JbpmTestCase {
+
+ private HashMap<String, Object> context;
+ @Before
+ public void setUp() throws Exception {
+ context = setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ PersistenceUtil.tearDown(context);
+ }
+
+ @Test
public void testLogger1() {
// load the process
RuleBase ruleBase = createKnowledgeBase();
@@ -41,7 +61,7 @@ public void testLogger1() {
properties.put("drools.processInstanceManagerFactory", "org.jbpm.process.instance.impl.DefaultProcessInstanceManagerFactory");
properties.put("drools.processSignalManagerFactory", "org.jbpm.process.instance.event.DefaultSignalManagerFactory");
SessionConfiguration config = new SessionConfiguration(properties);
- StatefulSession session = ruleBase.newStatefulSession(config, EnvironmentFactory.newEnvironment());
+ StatefulSession session = ruleBase.newStatefulSession(config, createEnvironment(context));
new WorkingMemoryDbLogger(session);
session.getWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());
@@ -68,7 +88,8 @@ public void testLogger1() {
}
ProcessInstanceDbLog.clear();
}
-
+
+ @Test
public void testLogger2() {
// load the process
RuleBase ruleBase = createKnowledgeBase();
@@ -77,7 +98,7 @@ public void testLogger2() {
properties.put("drools.processInstanceManagerFactory", "org.jbpm.process.instance.impl.DefaultProcessInstanceManagerFactory");
properties.put("drools.processSignalManagerFactory", "org.jbpm.process.instance.event.DefaultSignalManagerFactory");
SessionConfiguration config = new SessionConfiguration(properties);
- StatefulSession session = ruleBase.newStatefulSession(config, EnvironmentFactory.newEnvironment());
+ StatefulSession session = ruleBase.newStatefulSession(config, createEnvironment(context));
new WorkingMemoryDbLogger(session);
session.getWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());
@@ -101,7 +122,8 @@ public void testLogger2() {
}
ProcessInstanceDbLog.clear();
}
-
+
+ @Test
public void testLogger3() {
// load the process
RuleBase ruleBase = createKnowledgeBase();
@@ -110,7 +132,7 @@ public void testLogger3() {
properties.put("drools.processInstanceManagerFactory", "org.jbpm.process.instance.impl.DefaultProcessInstanceManagerFactory");
properties.put("drools.processSignalManagerFactory", "org.jbpm.process.instance.event.DefaultSignalManagerFactory");
SessionConfiguration config = new SessionConfiguration(properties);
- StatefulSession session = ruleBase.newStatefulSession(config, EnvironmentFactory.newEnvironment());
+ StatefulSession session = ruleBase.newStatefulSession(config, createEnvironment(context));
new WorkingMemoryDbLogger(session);
session.getWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());
View
5 jbpm-bam/src/test/resources/hibernate.cfg.xml
@@ -10,9 +10,8 @@
<!-- Database connection settings -->
<property name="connection.driver_class">org.h2.Driver</property>
<property name="connection.url">jdbc:h2:mem:mydb</property>
- <!--property name="connection.url">jdbc:h2:file:/NotBackedUp/data/mydb</property-->
- <property name="connection.username">sa</property>
- <property name="connection.password">sasa</property>
+ <property name="connection.username"></property>
+ <property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
View
1  jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/BPMN2Test.java
@@ -28,7 +28,6 @@
import org.drools.runtime.KnowledgeSessionConfiguration;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.ProcessInstance;
-import org.jbpm.JbpmJUnitTestCase;
public class BPMN2Test extends JbpmJUnitTestCase {
View
11 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/BPMN2XMLTest.java
@@ -29,10 +29,14 @@
import org.jbpm.bpmn2.xml.XmlBPMNProcessDumper;
import org.jbpm.compiler.xml.XmlProcessReader;
import org.jbpm.ruleflow.core.RuleFlowProcess;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
public class BPMN2XMLTest extends XMLTestCase {
+ private Logger logger = LoggerFactory.getLogger(BPMN2XMLTest.class);
+
private static final String[] processes = {
"BPMN2-SimpleXMLProcess.bpmn2",
// "BPMN2-MinimalProcess.xml",
@@ -56,9 +60,10 @@ public void testXML() throws IOException, SAXException {
assertEquals(1, processes.size());
RuleFlowProcess p = (RuleFlowProcess) processes.get(0);
String result = XmlBPMNProcessDumper.INSTANCE.dump(p, XmlBPMNProcessDumper.META_DATA_USING_DI);
- System.out.println(original);
- System.out.println("---------------------------------------------------------------");
- System.out.println(result);
+ logger.debug(original);
+ logger.debug("---------------------------------------------------------------");
+ logger.debug(result);
+ // TODO: ? commented out: "Comparing original with result process"
// assertXMLEqual("Comparing original with result process", original, result);
}
}
View
54 ...test/java/org/jbpm/JbpmJUnitTestCase.java → ...ava/org/jbpm/bpmn2/JbpmJUnitTestCase.java
@@ -1,18 +1,15 @@
-package org.jbpm;
+package org.jbpm.bpmn2;
import static org.drools.persistence.util.PersistenceUtil.*;
-import java.sql.SQLException;
+
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-
import junit.framework.TestCase;
import org.drools.KnowledgeBase;
-import org.drools.KnowledgeBaseFactory;
import org.drools.audit.WorkingMemoryInMemoryLogger;
import org.drools.audit.event.LogEvent;
import org.drools.audit.event.RuleFlowNodeLogEvent;
@@ -22,8 +19,8 @@
import org.drools.definition.process.Node;
import org.drools.io.ResourceFactory;
import org.drools.persistence.jpa.JPAKnowledgeService;
+import org.drools.persistence.util.PersistenceUtil;
import org.drools.runtime.Environment;
-import org.drools.runtime.EnvironmentName;
import org.drools.runtime.KnowledgeSessionConfiguration;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.NodeInstance;
@@ -33,23 +30,23 @@
import org.drools.runtime.process.WorkItemHandler;
import org.drools.runtime.process.WorkItemManager;
import org.drools.runtime.process.WorkflowProcessInstance;
-import org.h2.tools.DeleteDbFiles;
-import org.h2.tools.Server;
import org.jbpm.process.audit.JPAProcessInstanceDbLog;
import org.jbpm.process.audit.JPAWorkingMemoryDbLogger;
import org.jbpm.process.audit.NodeInstanceLog;
import org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl;
-import bitronix.tm.TransactionManagerServices;
-import bitronix.tm.resource.jdbc.PoolingDataSource;
-
+/**
+ * Base test case for the jbpm-bpmn2 module.
+ *
+ * Please keep this test class in the org.jbpm.bpmn2 package or otherwise give it a unique name.
+ *
+ */
public abstract class JbpmJUnitTestCase extends TestCase {
protected final static String EOL = System.getProperty( "line.separator" );
- private boolean persistence = false;
- private PoolingDataSource ds1;
- private EntityManagerFactory emf;
+ protected boolean persistence = true;
+ private HashMap<String, Object> context;
private TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
public StatefulKnowledgeSession ksession;
@@ -70,21 +67,16 @@ public boolean isPersistence() {
}
protected void setUp() {
+ System.out.println( "RUNNING: " + getName() );
if (persistence) {
- ds1 = setupPoolingDataSource();
- ds1.init();
-
- emf = Persistence.createEntityManagerFactory( "org.jbpm.persistence.jpa" );
+ context = setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME);
}
}
protected void tearDown() {
- if (emf != null) {
- emf.close();
- }
- if (ds1 != null) {
- ds1.close();
- }
+ if(persistence) {
+ PersistenceUtil.tearDown(context);
+ }
}
protected KnowledgeBase createKnowledgeBase(String... process) {
@@ -152,10 +144,8 @@ protected KnowledgeBase createKnowledgeBaseGuvnor(boolean dynamic, String url, S
protected StatefulKnowledgeSession createKnowledgeSession(KnowledgeBase kbase) {
if (persistence) {
- Environment env = KnowledgeBaseFactory.newEnvironment();
- env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
- env.set(EnvironmentName.TRANSACTION_MANAGER,
- TransactionManagerServices.getTransactionManager());
+ Environment env = createEnvironment(context);
+
StatefulKnowledgeSession result = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
new JPAWorkingMemoryDbLogger(result);
if (log == null) {
@@ -180,11 +170,7 @@ protected StatefulKnowledgeSession restoreSession(StatefulKnowledgeSession ksess
KnowledgeBase kbase = ksession.getKnowledgeBase();
Environment env = null;
if (noCache) {
- env = KnowledgeBaseFactory.newEnvironment();
- emf = Persistence.createEntityManagerFactory( "org.jbpm.persistence.jpa" );
- env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
- env.set(EnvironmentName.TRANSACTION_MANAGER,
- TransactionManagerServices.getTransactionManager());
+ env = createEnvironment(context);
} else {
env = ksession.getEnvironment();
}
View
50 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/SimpleBPMNProcessTest.java
@@ -49,7 +49,6 @@
import org.drools.runtime.process.WorkItemHandler;
import org.drools.runtime.process.WorkItemManager;
import org.drools.runtime.process.WorkflowProcessInstance;
-import org.jbpm.JbpmJUnitTestCase;
import org.jbpm.bpmn2.core.Association;
import org.jbpm.bpmn2.core.DataStore;
import org.jbpm.bpmn2.core.Definitions;
@@ -64,12 +63,25 @@
import org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler;
import org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler;
import org.jbpm.ruleflow.core.RuleFlowProcess;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class SimpleBPMNProcessTest extends JbpmJUnitTestCase {
+ private Logger logger = LoggerFactory.getLogger(SimpleBPMNProcessTest.class);
+
+ protected void setUp() {
+ String testName = getName();
+ if( testName.startsWith("testEventBasedSplit") || testName.startsWith("testTimerBoundaryEvent")
+ || testName.startsWith("testIntermediateCatchEventTimer") || testName.startsWith("testTimerStart") ) {
+ persistence = false;
+ }
+ super.setUp();
+ }
+
public void testMinimalProcess() throws Exception {
KnowledgeBase kbase = createKnowledgeBase("BPMN2-MinimalProcess.bpmn2");
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
@@ -133,7 +145,7 @@ public void testRuleTask() throws Exception {
assertNotNull(p);
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder(conf);
- // System.out.println(XmlBPMNProcessDumper.INSTANCE.dump(p));
+ // logger.debug(XmlBPMNProcessDumper.INSTANCE.dump(p));
kbuilder.add(ResourceFactory.newReaderResource(new StringReader(
XmlBPMNProcessDumper.INSTANCE.dump(p))), ResourceType.BPMN2);
kbuilder.add(
@@ -141,7 +153,7 @@ public void testRuleTask() throws Exception {
ResourceType.DRL);
if (!kbuilder.getErrors().isEmpty()) {
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
- System.err.println(error);
+ logger.error(error.toString());
}
throw new IllegalArgumentException(
"Errors while parsing knowledge base");
@@ -180,7 +192,7 @@ public void testRuleTask2() throws Exception {
assertNotNull(p);
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder(conf);
- // System.out.println(XmlBPMNProcessDumper.INSTANCE.dump(p));
+ // logger.debug(XmlBPMNProcessDumper.INSTANCE.dump(p));
kbuilder.add(ResourceFactory.newReaderResource(new StringReader(
XmlBPMNProcessDumper.INSTANCE.dump(p))), ResourceType.BPMN2);
kbuilder.add(
@@ -188,7 +200,7 @@ public void testRuleTask2() throws Exception {
ResourceType.DRL);
if (!kbuilder.getErrors().isEmpty()) {
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
- System.err.println(error);
+ logger.error(error.toString());
}
throw new IllegalArgumentException(
"Errors while parsing knowledge base");
@@ -728,7 +740,7 @@ public void testCallActivity() throws Exception {
ResourceType.BPMN2);
if (!kbuilder.getErrors().isEmpty()) {
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
- System.err.println(error);
+ logger.error(error.toString());
}
throw new IllegalArgumentException(
"Errors while parsing knowledge base");
@@ -750,15 +762,15 @@ public void testSubProcess() throws Exception {
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
ksession.addEventListener(new DefaultProcessEventListener() {
public void afterProcessStarted(ProcessStartedEvent event) {
- System.out.println(event);
+ logger.debug(event.toString());
}
public void beforeVariableChanged(ProcessVariableChangedEvent event) {
- System.out.println(event);
+ logger.debug(event.toString());
}
public void afterVariableChanged(ProcessVariableChangedEvent event) {
- System.out.println(event);
+ logger.debug(event.toString());
}
});
ProcessInstance processInstance = ksession.startProcess("SubProcess");
@@ -874,7 +886,7 @@ public void testTimerBoundaryEventInterrupting() throws Exception {
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
Thread.sleep(1000);
ksession = restoreSession(ksession, true);
- System.out.println("Firing timer");
+ logger.debug("Firing timer");
ksession.fireAllRules();
assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
@@ -900,7 +912,7 @@ public void testAdHocSubProcess() throws Exception {
assertNotNull(p);
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder(conf);
- // System.out.println(XmlBPMNProcessDumper.INSTANCE.dump(p));
+ // logger.debug(XmlBPMNProcessDumper.INSTANCE.dump(p));
kbuilder.add(ResourceFactory.newReaderResource(new StringReader(
XmlBPMNProcessDumper.INSTANCE.dump(p))), ResourceType.BPMN2);
kbuilder.add(ResourceFactory
@@ -908,7 +920,7 @@ public void testAdHocSubProcess() throws Exception {
ResourceType.DRL);
if (!kbuilder.getErrors().isEmpty()) {
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
- System.err.println(error);
+ logger.error(error.toString());
}
throw new IllegalArgumentException(
"Errors while parsing knowledge base");
@@ -928,7 +940,7 @@ public void testAdHocSubProcess() throws Exception {
ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
workItemHandler);
ksession.fireAllRules();
- System.out.println("Signaling Hello2");
+ logger.debug("Signaling Hello2");
ksession.signalEvent("Hello2", null, processInstance.getId());
workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
@@ -958,7 +970,7 @@ public void testAdHocSubProcessAutoComplete() throws Exception {
RuleFlowProcess p = (RuleFlowProcess) processes.get(0);
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder(conf);
- // System.out.println(XmlBPMNProcessDumper.INSTANCE.dump(p));
+ // logger.debug(XmlBPMNProcessDumper.INSTANCE.dump(p));
kbuilder.add(ResourceFactory.newReaderResource(new StringReader(
XmlBPMNProcessDumper.INSTANCE.dump(p))), ResourceType.BPMN2);
kbuilder.add(ResourceFactory
@@ -966,7 +978,7 @@ public void testAdHocSubProcessAutoComplete() throws Exception {
ResourceType.DRL);
if (!kbuilder.getErrors().isEmpty()) {
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
- System.err.println(error);
+ logger.error(error.toString());
}
throw new IllegalArgumentException(
"Errors while parsing knowledge base");
@@ -1003,7 +1015,7 @@ public void testAdHocProcess() throws Exception {
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
new DoNothingWorkItemHandler());
- System.out.println("Triggering node");
+ logger.debug("Triggering node");
ksession.signalEvent("Task1", null, processInstance.getId());
assertProcessInstanceActive(processInstance.getId(), ksession);
ksession.signalEvent("User1", null, processInstance.getId());
@@ -1725,7 +1737,7 @@ private KnowledgeBase createKnowledgeBase(String process) throws Exception {
+ process));
for (Process p : processes) {
RuleFlowProcess ruleFlowProcess = (RuleFlowProcess) p;
- System.out.println(XmlBPMNProcessDumper.INSTANCE
+ logger.debug(XmlBPMNProcessDumper.INSTANCE
.dump(ruleFlowProcess));
kbuilder.add(ResourceFactory.newReaderResource(new StringReader(
XmlBPMNProcessDumper.INSTANCE.dump(ruleFlowProcess))),
@@ -1737,7 +1749,7 @@ private KnowledgeBase createKnowledgeBase(String process) throws Exception {
+ process))), ResourceType.BPMN2);
if (!kbuilder.getErrors().isEmpty()) {
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
- System.err.println(error);
+ logger.error(error.toString());
}
throw new IllegalArgumentException(
"Errors while parsing knowledge base");
@@ -1770,7 +1782,7 @@ private KnowledgeBase createKnowledgeBaseWithoutDumper(String process)
+ process))), ResourceType.BPMN2);
if (!kbuilder.getErrors().isEmpty()) {
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
- System.err.println(error);
+ logger.error(error.toString());
}
throw new IllegalArgumentException(
"Errors while parsing knowledge base");
View
53 jbpm-bpmn2/src/test/resources/log4j.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+ <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out"/>
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%-4r %d{dd/MM HH:mm:ss,SSS}[%t] %-5p %c{3}.%M %x - %m%n"/>
+ </layout>
+ </appender>
+
+ <logger name="org.jbpm">
+ <level value="INFO"/>
+ </logger>
+
+ <!-- marshalling utils -->
+ <logger name="org.drools.marshalling.util.CompareViaReflectionUtil">
+ <level value="INFO"/>
+ </logger>
+
+ <logger name="org.drools.marshalling.util">
+ <level value="DEBUG"/>
+ </logger>
+
+ <!-- bitronix -->
+ <logger name="bitronix.tm.twopc.Preparer">
+ <level value="ERROR"/>
+ </logger>
+
+ <!-- hibernate -->
+ <logger name="org.hibernate">
+ <level value="WARN"/>
+ </logger>
+ <logger name="org.hibernate.cfg.search">
+ <level value="WARN"/>
+ </logger>
+ <logger name="org.hibernate.cfg.annotations">
+ <level value="WARN"/>
+ </logger>
+ <logger name="org.hibernate.cfg.AnnotationBinder">
+ <level value="WARN"/>
+ </logger>
+ <logger name="org.hibernate.cfg.SettingsFactory">
+ <level value="WARN"/>
+ </logger>
+ <logger name="org.hibernate.tool.hbm2ddl">
+ <level value="WARN"/>
+ </logger>
+
+ <root>
+ <priority value="INFO"/>
+ <appender-ref ref="CONSOLE"/>
+ </root>
+</log4j:configuration>
View
1  jbpm-flow-builder/.gitignore
@@ -1,5 +1,6 @@
/target
/local
+/bin
# Eclipse, Netbeans and IntelliJ files
/.*
View
1  jbpm-flow/.gitignore
@@ -1,5 +1,6 @@
/target
/local
+/bin
# Eclipse, Netbeans and IntelliJ files
/.*
View
37 jbpm-gwt/jbpm-gwt-core/src/test/java/org/jbpm/integration/JbpmTestCase.java
@@ -1,12 +1,10 @@
package org.jbpm.integration;
-import static org.jbpm.persistence.util.PersistenceUtil.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
-import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
@@ -14,9 +12,7 @@
import javax.persistence.Persistence;
import org.drools.SystemEventListenerFactory;
-import org.h2.tools.DeleteDbFiles;
-import org.h2.tools.Server;
-import org.jbpm.process.audit.HibernateUtil;
+import org.drools.persistence.util.PersistenceUtil;
import org.jbpm.task.AccessType;
import org.jbpm.task.AllowedToDelegate;
import org.jbpm.task.Attachment;
@@ -45,32 +41,40 @@
import org.mvel2.MVEL;
import org.mvel2.ParserContext;
import org.mvel2.compiler.ExpressionCompiler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import bitronix.tm.resource.jdbc.PoolingDataSource;
+/**
+ * This is a.. wacky test (suite).
+ *
+ * ! Adding a @AfterClass method will mess up the tests.
+ */
public abstract class JbpmTestCase {
- private static PoolingDataSource ds1;
+ private static Logger logger = LoggerFactory.getLogger(JbpmTestCase.class);
+
+ private static HashMap<String, Object> context = null;
+ private static EntityManagerFactory emf;
+
static MinaTaskServer minaServer;
static Thread minaServerThread;
@BeforeClass
public static void setUp(){
+ if( context == null ) {
+ context = PersistenceUtil.setupWithPoolingDataSource(PersistenceUtil.JBPM_PERSISTENCE_UNIT_NAME, false);
+ }
if (minaServerThread==null){
- ds1 = setupPoolingDataSource();
- ds1.init();
-
System.setProperty("jbpm.console.directory","./src/test/resources");
-
startHumanTaskServer();
}
}
-
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
+
protected static void startHumanTaskServer(){
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.task");
+ emf = Persistence.createEntityManagerFactory("org.jbpm.task");
TaskService taskService = new TaskService(emf, SystemEventListenerFactory.getSystemEventListener());
TaskServiceSession taskSession = taskService.createSession();
@@ -101,9 +105,8 @@ protected static void startHumanTaskServer(){
minaServerThread.start();
taskSession.dispose();
- System.out.println("Task service started correctly !");
- System.out.println("Task service running ...");
-
+ logger.debug("Task service started correctly !");
+ logger.debug("Task service running ...");
}
@SuppressWarnings("rawtypes")
View
1  jbpm-gwt/jbpm-gwt-core/src/test/java/org/jbpm/integration/console/ProcessManagementTest.java
@@ -10,7 +10,6 @@
import org.jboss.bpm.console.client.model.ProcessInstanceRef.STATE;
import org.jbpm.integration.JbpmTestCase;
import org.jbpm.process.audit.JPAProcessInstanceDbLog;
-import org.jbpm.process.audit.ProcessInstanceDbLog;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
View
6 .../src/test/java/org/jbpm/JbpmTestCase.java → ...va/org/jbpm/persistence/JbpmTestCase.java
@@ -1,6 +1,4 @@
-package org.jbpm;
-
-import junit.framework.TestCase;
+package org.jbpm.persistence;
import org.drools.compiler.ProcessBuilderFactory;
import org.drools.marshalling.impl.ProcessMarshallerFactory;
@@ -9,7 +7,7 @@
import org.jbpm.process.builder.ProcessBuilderFactoryServiceImpl;
import org.jbpm.process.instance.ProcessRuntimeFactoryServiceImpl;
-public abstract class JbpmTestCase extends TestCase {
+public abstract class JbpmTestCase {
static {
ProcessBuilderFactory.setProcessBuilderFactoryService(new ProcessBuilderFactoryServiceImpl());
View
42 ...-persistence-jpa/src/test/java/org/jbpm/persistence/map/impl/JpaBasedPersistenceTest.java
@@ -1,41 +1,39 @@
package org.jbpm.persistence.map.impl;
import static org.drools.persistence.util.PersistenceUtil.*;
+import static org.drools.runtime.EnvironmentName.ENTITY_MANAGER_FACTORY;
+
+import java.util.HashMap;
import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
import org.drools.KnowledgeBase;
-import org.drools.KnowledgeBaseFactory;
-import org.drools.base.MapGlobalResolver;
+import org.drools.marshalling.util.MarshallingTestUtil;
import org.drools.persistence.jpa.JPAKnowledgeService;
import org.drools.persistence.jta.JtaTransactionManager;
+import org.drools.persistence.util.PersistenceUtil;
import org.drools.runtime.Environment;
import org.drools.runtime.EnvironmentName;
import org.drools.runtime.StatefulKnowledgeSession;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
-import bitronix.tm.TransactionManagerServices;
-import bitronix.tm.resource.jdbc.PoolingDataSource;
-
public class JpaBasedPersistenceTest extends MapPersistenceTest {
- private PoolingDataSource ds1;
+ private HashMap<String, Object> context;
private EntityManagerFactory emf;
private JtaTransactionManager txm;
private boolean useTransactions = false;
@Before
public void setUp() throws Exception {
- ds1 = setupPoolingDataSource();
- ds1.init();
-
- emf = Persistence.createEntityManagerFactory( JBPM_PERSISTENCE_UNIT_NAME );
+ context = PersistenceUtil.setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME);
+ emf = (EntityManagerFactory) context.get(ENTITY_MANAGER_FACTORY);
if( useTransactions() ) {
useTransactions = true;
- Environment env = createEnvironment();
+ Environment env = createEnvironment(context);
Object tm = env.get( EnvironmentName.TRANSACTION_MANAGER );
this.txm = new JtaTransactionManager( env.get( EnvironmentName.TRANSACTION ),
env.get( EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY ),
@@ -45,21 +43,19 @@ public void setUp() throws Exception {
@After
public void tearDown() throws Exception {
- emf.close();
- ds1.close();
+ PersistenceUtil.tearDown(context);
}
@Override
protected StatefulKnowledgeSession createSession(KnowledgeBase kbase) {
- return JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, createEnvironment() );
+ return JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, createEnvironment(context) );
}
@Override
- protected StatefulKnowledgeSession disposeAndReloadSession(StatefulKnowledgeSession ksession,
+ protected StatefulKnowledgeSession disposeAndReloadSession(StatefulKnowledgeSession ksession, int ksessionId,
KnowledgeBase kbase) {
- int ksessionId = ksession.getId();
ksession.dispose();
- return JPAKnowledgeService.loadStatefulKnowledgeSession( ksessionId, kbase, null, createEnvironment() );
+ return JPAKnowledgeService.loadStatefulKnowledgeSession( ksessionId, kbase, null, createEnvironment(context) );
}
@Override
@@ -88,14 +84,4 @@ protected int getKnowledgeSessionsCount() {
return size;
}
- private Environment createEnvironment(){
- Environment env = KnowledgeBaseFactory.newEnvironment();
- env.set( EnvironmentName.ENTITY_MANAGER_FACTORY,
- emf );
- env.set( EnvironmentName.TRANSACTION_MANAGER,
- TransactionManagerServices.getTransactionManager() );
- env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );
-
- return env;
- }
}
View
7 ...-persistence-jpa/src/test/java/org/jbpm/persistence/map/impl/MapBasedPersistenceTest.java
@@ -19,7 +19,7 @@
import org.jbpm.persistence.processinstance.ProcessInstanceInfo;
import org.junit.Before;
-public class MapBasedPersistenceTest extends MapPersistenceTest{
+public class MapBasedPersistenceTest extends MapPersistenceTest {
private SimpleProcessStorage storage;
@@ -44,9 +44,8 @@ protected StatefulKnowledgeSession createSession(KnowledgeBase kbase) {
}
@Override
- protected StatefulKnowledgeSession disposeAndReloadSession(StatefulKnowledgeSession ksession,
+ protected StatefulKnowledgeSession disposeAndReloadSession(StatefulKnowledgeSession ksession, int ksessionId,
KnowledgeBase kbase) {
- int sessionId = ksession.getId();
ksession.dispose();
EnvironmentBuilder envBuilder = new ProcessStorageEnvironmentBuilder( storage );
Environment env = KnowledgeBaseFactory.newEnvironment();
@@ -55,7 +54,7 @@ protected StatefulKnowledgeSession disposeAndReloadSession(StatefulKnowledgeSess
env.set( EnvironmentName.PERSISTENCE_CONTEXT_MANAGER,
envBuilder.getPersistenceContextManager() );
- return JPAKnowledgeService.loadStatefulKnowledgeSession( sessionId, kbase, null, env );
+ return JPAKnowledgeService.loadStatefulKnowledgeSession( ksessionId, kbase, null, env );
}
@Override
View
13 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/map/impl/MapPersistenceTest.java
@@ -13,6 +13,7 @@
import org.jbpm.ruleflow.instance.RuleFlowProcessInstance;
import org.junit.Assert;
import org.junit.Test;
+import org.slf4j.LoggerFactory;
public abstract class MapPersistenceTest {
@@ -42,6 +43,7 @@ public void createProcessStartItDisposeAndLoadItAgain() {
workName ) );
StatefulKnowledgeSession ksession = createSession(kbase);
+ int ksessionId = ksession.getId();
DummyWorkItemHandler handler = new DummyWorkItemHandler();
ksession.getWorkItemManager()
@@ -49,7 +51,9 @@ public void createProcessStartItDisposeAndLoadItAgain() {
long process1Id = ksession.startProcess(processId).getId();
- ksession = disposeAndReloadSession(ksession, kbase);
+ LoggerFactory.getLogger(this.getClass()).info("DISPOSE..");
+ ksession = disposeAndReloadSession(ksession, ksessionId, kbase);
+ LoggerFactory.getLogger(this.getClass()).info("..AND RELOAD");
ksession.getWorkItemManager().registerWorkItemHandler(workName, handler);
long workItemId = handler.getLatestWorkItem().getId();
@@ -99,7 +103,9 @@ public void executeMultipleProcessTest() {
workName ) );
StatefulKnowledgeSession ksession1 = createSession(kbase);
+ int ksession1Id = ksession1.getId();
StatefulKnowledgeSession ksession2 = createSession(kbase);
+ int ksession2Id = ksession2.getId();
DummyWorkItemHandler handler1 = new DummyWorkItemHandler();
ksession1.getWorkItemManager()
@@ -113,13 +119,13 @@ public void executeMultipleProcessTest() {
long process1Id = ksession1.startProcess( processId ).getId();
long workItem1Id = handler1.getLatestWorkItem().getId();
- ksession1 = disposeAndReloadSession( ksession1,
+ ksession1 = disposeAndReloadSession( ksession1, ksession1Id,
kbase);
ksession1.getWorkItemManager().completeWorkItem( workItem1Id,
null );
Assert.assertNull( ksession1.getProcessInstance( process1Id ) );
- ksession2 = disposeAndReloadSession(ksession2, kbase);
+ ksession2 = disposeAndReloadSession(ksession2, ksession2Id, kbase);
Assert.assertNotNull(ksession2);
ksession2.getWorkItemManager()
@@ -270,6 +276,7 @@ public void processWithSubProcessThatCrashTest() {
protected abstract StatefulKnowledgeSession createSession(KnowledgeBase kbase);
protected abstract StatefulKnowledgeSession disposeAndReloadSession(StatefulKnowledgeSession crmPersistentSession,
+ int ksessionId,
KnowledgeBase kbase);
protected abstract int getProcessInstancesCount();
View
95 ...istence-jpa/src/test/java/org/jbpm/persistence/session/PersistentStatefulSessionTest.java
@@ -1,6 +1,7 @@
package org.jbpm.persistence.session;
-import static org.drools.persistence.util.PersistenceUtil.*;
+import static org.drools.persistence.util.PersistenceUtil.JBPM_PERSISTENCE_UNIT_NAME;
+import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.HashMap;
@@ -8,13 +9,10 @@
import java.util.Map;
import javax.naming.InitialContext;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
import javax.transaction.UserTransaction;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
-import org.drools.base.MapGlobalResolver;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderFactory;
@@ -28,40 +26,37 @@
import org.drools.event.process.ProcessVariableChangedEvent;
import org.drools.io.ResourceFactory;
import org.drools.io.impl.ClassPathResource;
+import org.drools.marshalling.util.MarshallingTestUtil;
import org.drools.persistence.jpa.JPAKnowledgeService;
+import org.drools.persistence.util.PersistenceUtil;
import org.drools.runtime.Environment;
-import org.drools.runtime.EnvironmentName;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.ProcessInstance;
import org.drools.runtime.process.WorkItem;
-import org.jbpm.JbpmTestCase;
+import org.jbpm.persistence.session.objects.TestWorkItemHandler;
import org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
-import bitronix.tm.TransactionManagerServices;
-import bitronix.tm.resource.jdbc.PoolingDataSource;
+public class PersistentStatefulSessionTest {
-public class PersistentStatefulSessionTest extends JbpmTestCase {
-
- private PoolingDataSource ds1;
- private EntityManagerFactory emf;
+ private HashMap<String, Object> context;
private Environment env;
- @Override
- protected void setUp() throws Exception {
- ds1 = setupPoolingDataSource();
-
- ds1.init();
-
- env = KnowledgeBaseFactory.newEnvironment();
- emf = Persistence.createEntityManagerFactory( JBPM_PERSISTENCE_UNIT_NAME );
- env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );
+ @Before
+ public void setUp() throws Exception {
+ context = PersistenceUtil.setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME);
+ env = PersistenceUtil.createEnvironment(context);
}
- @Override
- protected void tearDown() throws Exception {
- ds1.close();
+ @After
+ public void tearDown() throws Exception {
+ PersistenceUtil.tearDown(context);
}
+ @Test
public void testLocalTransactionPerStatement() {
String str = "";
str += "package org.drools.test\n";
@@ -85,10 +80,6 @@ public void testLocalTransactionPerStatement() {
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
- env.set( EnvironmentName.TRANSACTION_MANAGER,
- TransactionManagerServices.getTransactionManager() );
- env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );
-
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
List<?> list = new ArrayList<Object>();
@@ -106,6 +97,7 @@ public void testLocalTransactionPerStatement() {
}
+ @Test
public void testUserTransactions() throws Exception {
String str = "";
str += "package org.drools.test\n";
@@ -129,10 +121,6 @@ public void testUserTransactions() throws Exception {
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
- env.set( EnvironmentName.TRANSACTION_MANAGER,
- TransactionManagerServices.getTransactionManager() );
- env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );
-
UserTransaction ut = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" );
ut.begin();
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
@@ -197,6 +185,7 @@ public void testUserTransactions() throws Exception {
list.size() );
}
+ @Test
public void testPersistenceWorkItems() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( new ClassPathResource( "WorkItemsProcess.rf" ),
@@ -204,8 +193,6 @@ public void testPersistenceWorkItems() {
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
- env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );
-
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
int origNumObjects = ksession.getObjects().size();
int id = ksession.getId();
@@ -262,15 +249,13 @@ public void testPersistenceWorkItems() {
}
+ @Test
public void testPersistenceWorkItems2() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
- kbuilder.add( new ClassPathResource( "WorkItemsProcess.rf" ),
- ResourceType.DRF );
+ kbuilder.add( new ClassPathResource( "WorkItemsProcess.rf" ), ResourceType.DRF );
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
- env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );
-
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
int id = ksession.getId();
@@ -326,6 +311,7 @@ public void testPersistenceWorkItems2() throws Exception {
}
+ @Test
public void testPersistenceWorkItems3() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( new ClassPathResource( "WorkItemsProcess.rf" ),
@@ -333,8 +319,6 @@ public void testPersistenceWorkItems3() {
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
- env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );
-
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
ksession.getWorkItemManager().registerWorkItemHandler("MyWork", new SystemOutWorkItemHandler());
ProcessInstance processInstance = ksession.startProcess( "org.drools.test.TestProcess" );
@@ -342,17 +326,13 @@ public void testPersistenceWorkItems3() {
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
+ @Test
public void testPersistenceState() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
- kbuilder.add( new ClassPathResource( "StateProcess.rf" ),
- ResourceType.DRF );
+ kbuilder.add( new ClassPathResource( "StateProcess.rf" ), ResourceType.DRF );
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
- env.set( EnvironmentName.TRANSACTION_MANAGER,
- TransactionManagerServices.getTransactionManager() );
- env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );
-
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
int id = ksession.getId();
@@ -371,6 +351,7 @@ public void testPersistenceState() {
assertNull( processInstance );
}
+ @Test
public void testPersistenceRuleSet() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( new ClassPathResource( "RuleSetProcess.rf" ),
@@ -380,10 +361,6 @@ public void testPersistenceRuleSet() {
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
- env.set( EnvironmentName.TRANSACTION_MANAGER,
- TransactionManagerServices.getTransactionManager() );
- env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );
-
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
int id = ksession.getId();
@@ -402,6 +379,7 @@ public void testPersistenceRuleSet() {
assertNull( processInstance );
}
+ @Test
public void testPersistenceEvents() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( new ClassPathResource( "EventsProcess.rf" ),
@@ -409,8 +387,6 @@ public void testPersistenceEvents() {
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
- env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );
-
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
int id = ksession.getId();
@@ -445,6 +421,7 @@ public void testPersistenceEvents() {
assertNull( processInstance );
}
+ @Test
public void testProcessListener() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( new ClassPathResource( "WorkItemsProcess.rf" ),
@@ -452,8 +429,6 @@ public void testProcessListener() {
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
- env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );
-
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
final List<ProcessEvent> events = new ArrayList<ProcessEvent>();
ProcessEventListener listener = new ProcessEventListener() {
@@ -526,6 +501,7 @@ public void beforeVariableChanged(ProcessVariableChangedEvent event) {
assertTrue(events.isEmpty());
}
+ @Test
public void testPersistenceSubProcess() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( new ClassPathResource( "SuperProcess.rf" ),
@@ -572,6 +548,7 @@ public void testPersistenceSubProcess() {
assertNull( processInstance );
}
+ @Test
public void testPersistenceVariables() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( new ClassPathResource( "VariablesProcess.rf" ), ResourceType.DRF );
@@ -581,8 +558,6 @@ public void testPersistenceVariables() {
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
- env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );
-
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
int id = ksession.getId();
@@ -621,6 +596,7 @@ public void testPersistenceVariables() {
assertNull( processInstance );
}
+ @Test
public void testSetFocus() {
String str = "";
str += "package org.drools.test\n";
@@ -645,10 +621,6 @@ public void testSetFocus() {
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
- env.set( EnvironmentName.TRANSACTION_MANAGER,
- TransactionManagerServices.getTransactionManager() );
- env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );
-
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
List<?> list = new ArrayList<Object>();
@@ -666,5 +638,4 @@ public void testSetFocus() {
list.size() );
}
-
-}
+}
View
86 ...tence-jpa/src/test/java/org/jbpm/persistence/session/SingleSessionCommandServiceTest.java
@@ -1,15 +1,15 @@
package org.jbpm.persistence.session;
-import static org.drools.persistence.util.PersistenceUtil.*;
+import static org.drools.persistence.util.PersistenceUtil.JBPM_PERSISTENCE_UNIT_NAME;
+import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
import java.util.Properties;
import javax.naming.InitialContext;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
import javax.transaction.UserTransaction;
import org.apache.log4j.xml.DOMConfigurator;
@@ -24,22 +24,25 @@
import org.drools.compiler.PackageBuilder;
import org.drools.definition.KnowledgePackage;
import org.drools.definitions.impl.KnowledgePackageImp;
+import org.drools.marshalling.util.MarshallingTestUtil;
import org.drools.persistence.SingleSessionCommandService;
import org.drools.persistence.jpa.JpaJDKTimerService;
import org.drools.persistence.jpa.JpaTimeJobFactoryManager;
import org.drools.persistence.jpa.processinstance.JPAWorkItemManagerFactory;
+import org.drools.persistence.util.PersistenceUtil;
import org.drools.process.core.Work;
import org.drools.process.core.impl.WorkImpl;
import org.drools.rule.Package;
import org.drools.runtime.Environment;
-import org.drools.runtime.EnvironmentName;
import org.drools.runtime.process.NodeInstance;
import org.drools.runtime.process.ProcessInstance;
import org.drools.runtime.process.WorkItem;
-import org.jbpm.JbpmTestCase;
import org.jbpm.compiler.ProcessBuilderImpl;
+import org.jbpm.persistence.JbpmTestCase;
+import org.jbpm.persistence.map.impl.JpaBasedPersistenceTest;
import org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory;
import org.jbpm.persistence.processinstance.JPASignalManagerFactory;
+import org.jbpm.persistence.session.objects.TestWorkItemHandler;
import org.jbpm.process.core.timer.Timer;
import org.jbpm.ruleflow.core.RuleFlowProcess;
import org.jbpm.ruleflow.instance.RuleFlowProcessInstance;
@@ -53,38 +56,39 @@
import org.jbpm.workflow.core.node.TimerNode;
import org.jbpm.workflow.core.node.WorkItemNode;
import org.jbpm.workflow.instance.node.SubProcessNodeInstance;
-
-import bitronix.tm.TransactionManagerServices;
-import bitronix.tm.resource.jdbc.PoolingDataSource;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
public class SingleSessionCommandServiceTest extends JbpmTestCase {
- private PoolingDataSource ds1;
- private EntityManagerFactory emf;
+ private HashMap<String, Object> context;
+ private Environment env;
static {
DOMConfigurator.configure(SingleSessionCommandServiceTest.class.getResource("/log4j.xml"));
}
- protected void setUp() {
- ds1 = setupPoolingDataSource();
-
- ds1.init();
- emf = Persistence.createEntityManagerFactory( JBPM_PERSISTENCE_UNIT_NAME );
+ @Before
+ public void setUp() {
+ String testMethodName = Thread.currentThread().getStackTrace()[2].getMethodName();
+ if( testMethodName.startsWith("testPersistenceTimer") ) {
+ context = PersistenceUtil.setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME, false);
+ }
+ else {
+ context = PersistenceUtil.setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME);
+ }
+ env = PersistenceUtil.createEnvironment(context);
}
- protected void tearDown() {
- emf.close();
- ds1.close();
+ @After
+ public void tearDown() {
+ PersistenceUtil.tearDown(context);
}
+ @Test
public void testPersistenceWorkItems() throws Exception {
- Environment env = KnowledgeBaseFactory.newEnvironment();
- env.set( EnvironmentName.ENTITY_MANAGER_FACTORY,
- emf );
- env.set( EnvironmentName.TRANSACTION_MANAGER,
- TransactionManagerServices.getTransactionManager() );
-
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
Collection<KnowledgePackage> kpkgs = getProcessWorkItems();
kbase.addKnowledgePackages( kpkgs );
@@ -193,14 +197,9 @@ public void testPersistenceWorkItems() throws Exception {
assertNull( processInstance );
service.dispose();
}
-
+
+ @Test
public void testPersistenceWorkItemsUserTransaction() throws Exception {
- Environment env = KnowledgeBaseFactory.newEnvironment();
- env.set( EnvironmentName.ENTITY_MANAGER_FACTORY,
- emf );
- env.set( EnvironmentName.TRANSACTION_MANAGER,
- TransactionManagerServices.getTransactionManager() );
-
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
Collection<KnowledgePackage> kpkgs = getProcessWorkItems();
kbase.addKnowledgePackages( kpkgs );
@@ -327,7 +326,6 @@ public void testPersistenceWorkItemsUserTransaction() throws Exception {
service.dispose();
}
- @SuppressWarnings("unused")
private Collection<KnowledgePackage> getProcessWorkItems() {
RuleFlowProcess process = new RuleFlowProcess();
process.setId( "org.drools.test.TestProcess" );
@@ -400,13 +398,8 @@ public void testPersistenceWorkItemsUserTransaction() throws Exception {
return list;
}
+ @Test
public void testPersistenceSubProcess() {
- Environment env = KnowledgeBaseFactory.newEnvironment();
- env.set( EnvironmentName.ENTITY_MANAGER_FACTORY,
- emf );
- env.set( EnvironmentName.TRANSACTION_MANAGER,
- TransactionManagerServices.getTransactionManager() );
-
Properties properties = new Properties();
properties.setProperty( "drools.commandService",
SingleSessionCommandService.class.getName() );
@@ -484,7 +477,6 @@ public void testPersistenceSubProcess() {
service.dispose();
}
- @SuppressWarnings("unused")
private Package getProcessSubProcess() {
RuleFlowProcess process = new RuleFlowProcess();
process.setId( "org.drools.test.TestProcess" );
@@ -591,13 +583,8 @@ private Package getProcessSubProcess() {
return packageBuilder.getPackage();
}
+ @Test
public void testPersistenceTimer() throws Exception {
- Environment env = KnowledgeBaseFactory.newEnvironment();
- env.set( EnvironmentName.ENTITY_MANAGER_FACTORY,
- emf );
- env.set( EnvironmentName.TRANSACTION_MANAGER,
- TransactionManagerServices.getTransactionManager() );
-
Properties properties = new Properties();
properties.setProperty( "drools.commandService",
SingleSessionCommandService.class.getName() );
@@ -649,7 +636,6 @@ public void testPersistenceTimer() throws Exception {
assertNull( processInstance );
}
- @SuppressWarnings("unused")
private List<KnowledgePackage> getProcessTimer() {
RuleFlowProcess process = new RuleFlowProcess();
process.setId( "org.drools.test.TestProcess" );
@@ -700,13 +686,8 @@ public void testPersistenceTimer() throws Exception {
return list;
}
+ @Test
public void testPersistenceTimer2() throws Exception {
- Environment env = KnowledgeBaseFactory.newEnvironment();
- env.set( EnvironmentName.ENTITY_MANAGER_FACTORY,
- emf );
- env.set( EnvironmentName.TRANSACTION_MANAGER,
- TransactionManagerServices.getTransactionManager() );
-
Properties properties = new Properties();
properties.setProperty( "drools.commandService",
SingleSessionCommandService.class.getName() );
@@ -745,7 +726,6 @@ public void testPersistenceTimer2() throws Exception {
assertNull( processInstance );
}
- @SuppressWarnings("unused")
private List<KnowledgePackage> getProcessTimer2() {
RuleFlowProcess process = new RuleFlowProcess();
process.setId( "org.drools.test.TestProcess" );
View
68 ...tence-jpa/src/test/java/org/jbpm/persistence/session/VariablePersistenceStrategyTest.java
@@ -1,6 +1,8 @@
package org.jbpm.persistence.session;
-import static org.drools.persistence.util.PersistenceUtil.*;
+import static org.drools.persistence.util.PersistenceUtil.JBPM_PERSISTENCE_UNIT_NAME;
+import static org.drools.runtime.EnvironmentName.ENTITY_MANAGER_FACTORY;
+import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.HashMap;
@@ -11,11 +13,11 @@
import javax.naming.NamingException;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
+import javax.transaction.Status;
import javax.transaction.SystemException;
import javax.transaction.UserTransaction;
@@ -35,8 +37,10 @@
import org.drools.marshalling.ObjectMarshallingStrategy;
import org.drools.marshalling.impl.ClassObjectMarshallingStrategyAcceptor;
import org.drools.marshalling.impl.SerializablePlaceholderResolverStrategy;
+import org.drools.marshalling.util.MarshallingTestUtil;
import org.drools.persistence.jpa.JPAKnowledgeService;
import org.drools.persistence.jpa.marshaller.JPAPlaceholderResolverStrategy;
+import org.drools.persistence.util.PersistenceUtil;
import org.drools.process.core.Work;
import org.drools.process.core.datatype.impl.type.ObjectDataType;
import org.drools.process.core.impl.WorkImpl;
@@ -47,7 +51,16 @@
import org.drools.runtime.process.ProcessInstance;
import org.drools.runtime.process.WorkItem;
import org.drools.runtime.process.WorkflowProcessInstance;
-import org.jbpm.JbpmTestCase;
+import org.jbpm.persistence.JbpmTestCase;
+import org.jbpm.persistence.map.impl.JpaBasedPersistenceTest;
+import org.jbpm.persistence.session.objects.MyEntity;
+import org.jbpm.persistence.session.objects.MyEntityMethods;
+import org.jbpm.persistence.session.objects.MyEntityOnlyFields;
+import org.jbpm.persistence.session.objects.MySubEntity;
+import org.jbpm.persistence.session.objects.MySubEntityMethods;
+import org.jbpm.persistence.session.objects.MyVariableExtendingSerializable;
+import org.jbpm.persistence.session.objects.MyVariableSerializable;
+import org.jbpm.persistence.session.objects.TestWorkItemHandler;
import org.jbpm.process.core.context.variable.Variable;
import org.jbpm.process.instance.impl.Action;
import org.jbpm.ruleflow.core.RuleFlowProcess;
@@ -60,33 +73,30 @@
import org.jbpm.workflow.core.node.StartNode;
import org.jbpm.workflow.core.node.WorkItemNode;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import bitronix.tm.TransactionManagerServices;
-import bitronix.tm.resource.jdbc.PoolingDataSource;
public class VariablePersistenceStrategyTest extends JbpmTestCase {
private static Logger logger = LoggerFactory.getLogger( VariablePersistenceStrategyTest.class );
- private PoolingDataSource ds1;
+ private HashMap<String, Object> context;
private EntityManagerFactory emf;
@Before
public void setUp() throws Exception {
- ds1 = setupPoolingDataSource();
- ds1.init();
-
- emf = Persistence.createEntityManagerFactory( JBPM_PERSISTENCE_UNIT_NAME );
+ context = PersistenceUtil.setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME);
+ emf = (EntityManagerFactory) context.get(ENTITY_MANAGER_FACTORY);
}
@After
public void tearDown() throws Exception {
- emf.close();
- ds1.close();
+ PersistenceUtil.tearDown(context);
}
@Test
@@ -168,9 +178,18 @@ public void execute(ProcessContext context) throws Exception {
@Test
public void testPersistenceVariables() throws NamingException, NotSupportedException, SystemException, RollbackException, HeuristicMixedException, HeuristicRollbackException {
- int origNumMyEntities = emf.createEntityManager().createQuery("select i from MyEntity i").getResultList().size();
- int origNumMyEntityMethods = emf.createEntityManager().createQuery("select i from MyEntityMethods i").getResultList().size();
- int origNumMyEntityOnlyFields = emf.createEntityManager().createQuery("select i from MyEntityOnlyFields i").getResultList().size();
+ EntityManager em = emf.createEntityManager();
+ UserTransaction utx = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" );
+ if( utx.getStatus() == Status.STATUS_NO_TRANSACTION ) {
+ utx.begin();
+ em.joinTransaction();
+ }
+ int origNumMyEntities = em.createQuery("select i from MyEntity i").getResultList().size();
+ int origNumMyEntityMethods = em.createQuery("select i from MyEntityMethods i").getResultList().size();
+ int origNumMyEntityOnlyFields = em.createQuery("select i from MyEntityOnlyFields i").getResultList().size();
+ if( utx.getStatus() == Status.STATUS_ACTIVE ) {
+ utx.commit();
+ }
// Setup entities
MyEntity myEntity = new MyEntity("This is a test Entity with annotation in fields");
@@ -179,8 +198,7 @@ public void testPersistenceVariables() throws NamingException, NotSupportedExcep
MyVariableSerializable myVariableSerializable = new MyVariableSerializable("This is a test SerializableObject");
// persist entities
- EntityManager em = emf.createEntityManager();
- UserTransaction utx = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" );
+ utx = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" );
utx.begin();
em.joinTransaction();
em.persist(myEntity);
@@ -286,18 +304,25 @@ public void testPersistenceVariables() throws NamingException, NotSupportedExcep
@Test
public void testPersistenceVariablesWithTypeChange() throws NamingException, NotSupportedException, SystemException, RollbackException, HeuristicMixedException, HeuristicRollbackException {
+
MyEntity myEntity = new MyEntity("This is a test Entity with annotation in fields");
MyEntityMethods myEntityMethods = new MyEntityMethods("This is a test Entity with annotations in methods");
MyEntityOnlyFields myEntityOnlyFields = new MyEntityOnlyFields("This is a test Entity with annotations in fields and without accesors methods");
MyVariableSerializable myVariableSerializable = new MyVariableSerializable("This is a test SerializableObject");
+
EntityManager em = emf.createEntityManager();
UserTransaction utx = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" );
- utx.begin();
+ int s = utx.getStatus();
+ if( utx.getStatus() == Status.STATUS_NO_TRANSACTION ) {
+ utx.begin();
+ }
em.joinTransaction();
em.persist(myEntity);
em.persist(myEntityMethods);
em.persist(myEntityOnlyFields);
- utx.commit();
+ if( utx.getStatus() == Status.STATUS_ACTIVE ) {
+ utx.commit();
+ }
em.close();
Environment env = createEnvironment();
KnowledgeBase kbase = createKnowledgeBase( "VariablePersistenceStrategyProcessTypeChange.rf" );
@@ -549,10 +574,7 @@ private KnowledgeBase createKnowledgeBase(String flowFile) {
}
private Environment createEnvironment() {
- Environment env = KnowledgeBaseFactory.newEnvironment();
- env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
- env.set(EnvironmentName.GLOBALS, new MapGlobalResolver());
- env.set( EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager() );
+ Environment env = PersistenceUtil.createEnvironment(context);
env.set(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, new ObjectMarshallingStrategy[]{
new JPAPlaceholderResolverStrategy(env),
new SerializablePlaceholderResolverStrategy( ClassObjectMarshallingStrategyAcceptor.DEFAULT )
@@ -566,4 +588,4 @@ private void connect(Node sourceNode,
targetNode, Node.CONNECTION_DEFAULT_TYPE);
}
-}
+}
View
302 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/WorkItemPersistenceTest.java
@@ -0,0 +1,302 @@
+package org.jbpm.persistence.session;
+
+import static org.drools.persistence.util.PersistenceUtil.*;
+import static org.drools.runtime.EnvironmentName.ENTITY_MANAGER_FACTORY;
+import static org.junit.Assert.*;
+
+import java.io.Reader;
+import java.io.StringReader;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.drools.KnowledgeBase;
+import org.drools.KnowledgeBaseFactory;
+import org.drools.WorkItemHandlerNotFoundException;
+import org.drools.builder.KnowledgeBuilder;
+import org.drools.builder.KnowledgeBuilderFactory;
+import org.drools.builder.ResourceType;
+import org.drools.common.AbstractRuleBase;
+import org.drools.impl.InternalKnowledgeBase;
+import org.drools.io.ResourceFactory;
+import org.drools.persistence.jpa.JPAKnowledgeService;
+import org.drools.persistence.jta.JtaTransactionManager;
+import org.drools.persistence.util.PersistenceUtil;
+import org.drools.process.core.ParameterDefinition;
+import org.drools.process.core.Work;
+import org.drools.process.core.datatype.impl.type.IntegerDataType;
+import org.drools.process.core.datatype.impl.type.ObjectDataType;
+import org.drools.process.core.datatype.impl.type.StringDataType;
+import org.drools.process.core.impl.ParameterDefinitionImpl;
+import org.drools.process.core.impl.WorkImpl;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.process.ProcessInstance;
+import org.drools.runtime.process.ProcessRuntimeFactory;
+import org.jbpm.persistence.processinstance.ProcessInstanceInfo;
+import org.jbpm.persistence.session.objects.Person;
+import org.jbpm.process.core.context.variable.Variable;
+import org.jbpm.process.instance.ProcessRuntimeFactoryServiceImpl;
+import org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler;
+import org.jbpm.ruleflow.core.RuleFlowProcess;
+import org.jbpm.workflow.core.Node;
+import org.jbpm.workflow.core.impl.ConnectionImpl;
+import org.jbpm.workflow.core.node.EndNode;
+import org.jbpm.workflow.core.node.HumanTaskNode;
+import org.jbpm.workflow.core.node.StartNode;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class WorkItemPersistenceTest {
+
+ private static Logger logger = LoggerFactory.getLogger(WorkItemPersistenceTest.class);
+
+ private HashMap<String, Object> context;
+ private EntityManagerFactory emf;
+
+ static {
+ ProcessRuntimeFactory.setProcessRuntimeFactoryService(new ProcessRuntimeFactoryServiceImpl());
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ context = setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME, false);
+ emf = (EntityManagerFactory) context.get(ENTITY_MANAGER_FACTORY);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ PersistenceUtil.tearDown(context);
+ }
+
+ protected StatefulKnowledgeSession createSession(KnowledgeBase kbase) {
+ return JPAKnowledgeService.newStatefulKnow