Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removing drools-persistence-jpa/test-jar from dependencies and using …

…the jbpm-peristence-jpa/test-jar instead

- This commit modifies the jbpm-persistence-jpa test code heavily
  as well as the jbpm-bam, jbpm-bpmn2, and jbpm-test test code
- Given the development of test code in both the dev and QA groups,
  it's just easier to move the marshalling/util code to jbpm for the
  time being.
- The maven property usage has been made more transparent.
  • Loading branch information...
commit 1fb625788bc478422a1f6b1cec3cba49ea868e25 1 parent 2d94f32
Marco Rietveld mrietveld authored
Showing with 3,650 additions and 891 deletions.
  1. +1 −0  .gitignore
  2. +0 −7 jbpm-bam/pom.xml
  3. +2 −2 jbpm-bam/src/test/filtered-resources/META-INF/persistence.xml
  4. +1 −1  jbpm-bam/src/test/filtered-resources/hibernate.cfg.xml
  5. +0 −12 jbpm-bpmn2/build.properties
  6. +2 −2 jbpm-bpmn2/pom.xml
  7. +1 −1  jbpm-bpmn2/src/test/filtered-resources/META-INF/persistence.xml
  8. +6 −14 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/BoundaryEventWithCancelActivityTest.java
  9. +19 −26 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/JbpmBpmn2TestCase.java
  10. +6 −2 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/ProcessFactoryTest.java
  11. +25 −45 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/SimpleBPMNProcessTest.java
  12. +0 −75 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/SimplePersistenceBPMNProcessTest.java
  13. +11 −7 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java
  14. +1 −1  jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/concurrency/MultipleProcessesPerThreadTest.java
  15. +3 −5 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/concurrency/persistence/MultipleProcessesPerThreadPersistenceTest.java
  16. +3 −5 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/concurrency/persistence/OneProcessPerThreadPersistenceTest.java
  17. +10 −30 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/{ → persistence}/Hibernate4ProcessPersistenceTest.java
  18. +62 −2 ...g/jbpm/bpmn2/persistence/{SimplePersistedBPMNProcessTest.java → SimplePersistenceBPMNProcessTest.java}
  19. +17 −65 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/persistence/TimerCycleOnBinaryPackageTest.java
  20. +16 −33 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/persistence/TimerPersistenceTest.java
  21. +15 −75 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/persistence/UnmarshallingOverdueTimersTest.java
  22. +2 −1  jbpm-gwt/jbpm-gwt-core/.gitignore
  23. +2 −2 jbpm-gwt/jbpm-gwt-core/pom.xml
  24. +1 −1  jbpm-gwt/jbpm-gwt-core/src/test/filtered-resources/META-INF/persistence.xml
  25. +4 −7 jbpm-gwt/jbpm-gwt-core/src/test/java/org/jbpm/integration/JbpmGwtCoreTestCase.java
  26. +0 −23 jbpm-gwt/jbpm-gwt-core/src/test/java/org/jbpm/integration/console/UserManagementTest.java
  27. +0 −6 jbpm-persistence-jpa/pom.xml
  28. +93 −102 jbpm-persistence-jpa/src/test/filtered-resources/META-INF/persistence.xml
  29. +9 −19 jbpm-persistence-jpa/src/test/java/org/jbpm/marshalling/DebugJbpmUnmarshallingTest.java
  30. +788 −0 jbpm-persistence-jpa/src/test/java/org/jbpm/marshalling/util/CompareViaReflectionUtil.java
  31. +450 −0 jbpm-persistence-jpa/src/test/java/org/jbpm/marshalling/util/EntityManagerFactoryProxy.java
  32. +162 −0 jbpm-persistence-jpa/src/test/java/org/jbpm/marshalling/util/MarshalledData.java
  33. +252 −0 jbpm-persistence-jpa/src/test/java/org/jbpm/marshalling/util/MarshallingDBUtil.java
  34. +641 −4 jbpm-persistence-jpa/src/test/java/org/jbpm/marshalling/util/MarshallingTestUtil.java
  35. +393 −0 jbpm-persistence-jpa/src/test/java/org/jbpm/marshalling/util/Readme.md
  36. +219 −0 jbpm-persistence-jpa/src/test/java/org/jbpm/marshalling/util/TestMarshallingUtilsTest.java
  37. +115 −0 jbpm-persistence-jpa/src/test/java/org/jbpm/marshalling/util/UserTransactionProxy.java
  38. +4 −8 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/map/impl/JpaBasedPersistenceTest.java
  39. +3 −7 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/map/impl/ProcessCreatorForHelp.java
  40. +6 −15 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/processinstance/ParameterMappingTest.java
  41. +6 −19 ...persistence-jpa/src/test/java/org/jbpm/persistence/processinstance/ProcessInstanceResolverStrategyTest.java
  42. +1 −1  jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/GetProcessInstancesTest.java
  43. +8 −26 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/PersistentStatefulSessionTest.java
  44. +11 −29 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/SingleSessionCommandServiceTest.java
  45. +13 −45 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/VariablePersistenceStrategyTest.java
  46. +9 −28 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/WorkItemPersistenceTest.java
  47. +38 −16 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/objects/Person.java
  48. +170 −0 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/util/LoggingPrintStream.java
  49. +6 −15 jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/util/PersistenceUtil.java
  50. +2 −2 jbpm-test/pom.xml
  51. +11 −9 jbpm-test/src/main/java/org/jbpm/test/JbpmJUnitTestCase.java
  52. +11 −42 jbpm-test/src/test/java/org/jbpm/persistence/PatientVariablePersistenceStrategyTest.java
  53. +5 −3 jbpm-test/src/test/java/org/jbpm/persistence/timer/TimerPersistenceTest.java
  54. +2 −2 jbpm-test/src/test/java/org/jbpm/tasks/LocalTasksServiceTest.java
  55. +9 −46 jbpm-test/src/test/java/org/jbpm/tasks/admin/AdminAPIsWithListenerTest.java
  56. +3 −3 pom.xml
1  .gitignore
View
@@ -21,6 +21,7 @@ bin/
/settings*.xml
/lib-jdbc/
bitronix-default-config.properties
+*.db
# modules that don't exist in this branch
/jbpm-human-task-war/
7 jbpm-bam/pom.xml
View
@@ -76,15 +76,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.drools</groupId>
- <artifactId>drools-persistence-jpa</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-persistence-jpa</artifactId>
- <version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
4 jbpm-bam/src/test/filtered-resources/META-INF/persistence.xml
View
@@ -19,7 +19,7 @@
<class>org.jbpm.process.audit.NodeInstanceLog</class>
<class>org.jbpm.process.audit.VariableInstanceLog</class>
- <class>org.drools.marshalling.util.MarshalledData</class>
+ <class>org.jbpm.marshalling.util.MarshalledData</class>
<properties>
<property name="hibernate.max_fetch_depth" value="3"/>
@@ -38,4 +38,4 @@
<property name="hibernate.default_schema" value="${maven.jdbc.schema}" />
</properties>
</persistence-unit>
-</persistence>
+</persistence>
2  jbpm-bam/src/test/filtered-resources/hibernate.cfg.xml
View
@@ -35,4 +35,4 @@
</session-factory>
-</hibernate-configuration>
+</hibernate-configuration>
12 jbpm-bpmn2/build.properties
View
@@ -1,12 +0,0 @@
-src.includes = .,\
- build.properties,\
- META-INF/,\
- src/,\
- pom.xml
-bin.includes = .,\
- META-INF/,\
- build.properties
-source.. = src/main/java/,\
- src/main/resources/
-output.. = target/classes/
-jars.compile.order = .
4 jbpm-bpmn2/pom.xml
View
@@ -47,8 +47,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.drools</groupId>
- <artifactId>drools-persistence-jpa</artifactId>
+ <groupId>org.jbpm</groupId>
+ <artifactId>jbpm-persistence-jpa</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
2  jbpm-bpmn2/src/test/filtered-resources/META-INF/persistence.xml
View
@@ -19,7 +19,7 @@
<class>org.jbpm.process.audit.NodeInstanceLog</class>
<class>org.jbpm.process.audit.VariableInstanceLog</class>
- <class>org.drools.marshalling.util.MarshalledData</class>
+ <class>org.jbpm.marshalling.util.MarshalledData</class>
<properties>
<property name="hibernate.max_fetch_depth" value="3"/>
20 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/BoundaryEventWithCancelActivityTest.java
View
@@ -1,31 +1,23 @@
package org.jbpm.bpmn2;
-import static org.junit.Assert.*;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
+import java.io.*;
import org.drools.KnowledgeBase;
-import org.drools.builder.KnowledgeBuilder;
-import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.ResourceType;
+import org.drools.builder.*;
import org.drools.core.util.DroolsStreamUtils;
import org.drools.definition.KnowledgePackage;
-import org.drools.event.process.DefaultProcessEventListener;
-import org.drools.event.process.ProcessNodeLeftEvent;
-import org.drools.event.process.ProcessNodeTriggeredEvent;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.ProcessInstance;
-import org.jbpm.bpmn2.JbpmBpmn2TestCase.TestWorkItemHandler;
import org.jbpm.bpmn2.objects.Person;
import org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler;
-import org.junit.Test;
public class BoundaryEventWithCancelActivityTest extends JbpmBpmn2TestCase {
+ protected void setUp() {
+ persistence = false;
+ }
+
public void testConditionalBoundaryEventInterrupting() throws Exception {
KnowledgeBase kbase = readKnowledgeBaseFromDisc("BPMN2-ConditionalBoundaryEventInterrupting.bpmn2");
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
45 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/JbpmBpmn2TestCase.java
View
@@ -1,38 +1,26 @@
package org.jbpm.bpmn2;
-import static org.drools.persistence.util.PersistenceUtil.*;
+import static org.jbpm.persistence.util.PersistenceUtil.*;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import junit.framework.TestCase;
import org.drools.KnowledgeBase;
+import org.drools.SessionConfiguration;
import org.drools.audit.WorkingMemoryInMemoryLogger;
import org.drools.audit.event.LogEvent;
import org.drools.audit.event.RuleFlowNodeLogEvent;
-import org.drools.builder.KnowledgeBuilder;
-import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.ResourceType;
+import org.drools.builder.*;
import org.drools.definition.process.Node;
+import org.drools.impl.EnvironmentFactory;
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.KnowledgeSessionConfiguration;
-import org.drools.runtime.StatefulKnowledgeSession;
-import org.drools.runtime.process.NodeInstance;
-import org.drools.runtime.process.NodeInstanceContainer;
-import org.drools.runtime.process.ProcessInstance;
-import org.drools.runtime.process.WorkItem;
-import org.drools.runtime.process.WorkItemHandler;
-import org.drools.runtime.process.WorkItemManager;
-import org.drools.runtime.process.WorkflowProcessInstance;
-import org.jbpm.process.audit.JPAProcessInstanceDbLog;
-import org.jbpm.process.audit.JPAWorkingMemoryDbLogger;
-import org.jbpm.process.audit.NodeInstanceLog;
+import org.drools.runtime.*;
+import org.drools.runtime.process.*;
+import org.jbpm.process.audit.*;
+import org.jbpm.process.instance.event.DefaultSignalManagerFactory;
+import org.jbpm.process.instance.impl.DefaultProcessInstanceManagerFactory;
import org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl;
/**
@@ -54,7 +42,7 @@
private WorkingMemoryInMemoryLogger logger;
public JbpmBpmn2TestCase() {
- this(false);
+ this(true);
}
public JbpmBpmn2TestCase(boolean persistence) {
@@ -74,7 +62,7 @@ protected void setUp() {
protected void tearDown() {
if(persistence) {
- PersistenceUtil.tearDown(context);
+ cleanUp(context);
}
}
@@ -150,8 +138,13 @@ protected StatefulKnowledgeSession createKnowledgeSession(KnowledgeBase kbase) {
JPAProcessInstanceDbLog.setEnvironment(result.getEnvironment());
return result;
} else {
- StatefulKnowledgeSession result = kbase.newStatefulKnowledgeSession();
- logger = new WorkingMemoryInMemoryLogger(result);
+ Properties defaultProps = new Properties();
+ defaultProps.setProperty("drools.processSignalManagerFactory", DefaultSignalManagerFactory.class.getName());
+ defaultProps.setProperty("drools.processInstanceManagerFactory", DefaultProcessInstanceManagerFactory.class.getName());
+ SessionConfiguration sessionConfig = new SessionConfiguration(defaultProps);
+
+ StatefulKnowledgeSession result = kbase.newStatefulKnowledgeSession(sessionConfig, EnvironmentFactory.newEnvironment());
+ logger = new WorkingMemoryInMemoryLogger(result);
return result;
}
}
8 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/ProcessFactoryTest.java
View
@@ -27,7 +27,11 @@
import org.jbpm.ruleflow.core.RuleFlowProcessFactory;
public class ProcessFactoryTest extends JbpmBpmn2TestCase {
-
+
+ public ProcessFactoryTest() {
+ super(false);
+ }
+
public void testProcessFactory() {
RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
factory
@@ -45,7 +49,7 @@ public void testProcessFactory() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes()), ResourceType.BPMN2);
KnowledgeBase kbase = kbuilder.newKnowledgeBase();
- StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
+ StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
ksession.startProcess("org.jbpm.process");
}
70 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/SimpleBPMNProcessTest.java
View
@@ -16,60 +16,30 @@
package org.jbpm.bpmn2;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import java.io.*;
+import java.util.*;
-import java.io.ByteArrayInputStream;
-import java.io.InputStreamReader;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.*;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
-import org.drools.builder.KnowledgeBuilder;
-import org.drools.builder.KnowledgeBuilderConfiguration;
-import org.drools.builder.KnowledgeBuilderError;
-import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.ResourceType;
+import org.drools.builder.*;
import org.drools.compiler.PackageBuilderConfiguration;
import org.drools.definition.process.Process;
-import org.drools.event.process.DefaultProcessEventListener;
-import org.drools.event.process.ProcessCompletedEvent;
-import org.drools.event.process.ProcessNodeLeftEvent;
-import org.drools.event.process.ProcessNodeTriggeredEvent;
-import org.drools.event.process.ProcessStartedEvent;
-import org.drools.event.process.ProcessVariableChangedEvent;
-import org.drools.event.rule.DebugAgendaEventListener;
-import org.drools.event.rule.DebugWorkingMemoryEventListener;
+import org.drools.event.process.*;
import org.drools.impl.KnowledgeBaseFactoryServiceImpl;
import org.drools.io.ResourceFactory;
import org.drools.process.core.datatype.impl.type.ObjectDataType;
import org.drools.process.instance.impl.WorkItemImpl;
import org.drools.runtime.StatefulKnowledgeSession;
-import org.drools.runtime.process.ProcessInstance;
-import org.drools.runtime.process.WorkItem;
-import org.drools.runtime.process.WorkItemHandler;
-import org.drools.runtime.process.WorkItemManager;
-import org.drools.runtime.process.WorkflowProcessInstance;
+import org.drools.runtime.process.*;
import org.drools.runtime.rule.FactHandle;
-import org.jbpm.bpmn2.core.Association;
-import org.jbpm.bpmn2.core.DataStore;
-import org.jbpm.bpmn2.core.Definitions;
+import org.jbpm.bpmn2.core.*;
import org.jbpm.bpmn2.handler.ReceiveTaskHandler;
import org.jbpm.bpmn2.handler.SendTaskHandler;
import org.jbpm.bpmn2.handler.ServiceTaskHandler;
import org.jbpm.bpmn2.objects.Person;
-import org.jbpm.bpmn2.xml.BPMNDISemanticModule;
-import org.jbpm.bpmn2.xml.BPMNExtensionsSemanticModule;
-import org.jbpm.bpmn2.xml.BPMNSemanticModule;
-import org.jbpm.bpmn2.xml.XmlBPMNProcessDumper;
+import org.jbpm.bpmn2.xml.*;
import org.jbpm.compiler.xml.XmlProcessReader;
import org.jbpm.process.instance.impl.RuleAwareProcessEventLister;
import org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler;
@@ -78,12 +48,9 @@
import org.jbpm.workflow.instance.node.DynamicNodeInstance;
import org.jbpm.workflow.instance.node.DynamicUtils;
import org.joda.time.DateTime;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
+import org.w3c.dom.*;
public class SimpleBPMNProcessTest extends JbpmBpmn2TestCase {
@@ -91,9 +58,22 @@
protected void setUp() {
String testName = getName();
- if( testName.startsWith("testEventBasedSplit") || testName.startsWith("testTimerBoundaryEvent")
- || testName.startsWith("testIntermediateCatchEventTimer") || testName.startsWith("testTimerStart") ) {
- persistence = false;
+ String [] testFailsWithPersistence = {
+ "testEventBasedSplit", "testTimerBoundaryEvent", "testIntermediateCatchEventTimer", "testTimerStart",
+ // broken, but should work?!?
+ "testSignalBoundaryEvent",
+ "testEscalationBoundaryEventOnTask", "testErrorBoundaryEventOnTask",
+ "testBusinessRuleTask",
+ "testNullVariableInScriptTaskProcess",
+ "testConditionalBoundaryEvent",
+ "testMessageBoundaryEventOnTask",
+ "testMessageBoundaryEvent",
+ "testCallActivityWithBoundaryEvent"
+ };
+ for( String testNameBegin : testFailsWithPersistence ) {
+ if( testName.startsWith(testNameBegin) ) {
+ persistence = false;
+ }
}
super.setUp();
}
75 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/SimplePersistenceBPMNProcessTest.java
View
@@ -1,75 +0,0 @@
-package org.jbpm.bpmn2;
-
-import org.drools.KnowledgeBase;
-import org.drools.event.process.DefaultProcessEventListener;
-import org.drools.event.process.ProcessNodeLeftEvent;
-import org.drools.event.process.ProcessNodeTriggeredEvent;
-import org.drools.runtime.StatefulKnowledgeSession;
-import org.drools.runtime.process.ProcessInstance;
-import org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler;
-
-public class SimplePersistenceBPMNProcessTest extends JbpmBpmn2TestCase {
-
- public SimplePersistenceBPMNProcessTest() {
- super(true);
- }
-
- public void testCompensateEndEventProcess() throws Exception {
- KnowledgeBase kbase = createKnowledgeBase("BPMN2-CompensateEndEvent.bpmn2");
- StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
- ProcessInstance processInstance = ksession
- .startProcess("CompensateEndEvent");
- assertProcessInstanceCompleted(processInstance.getId(), ksession);
- assertNodeTriggered(processInstance.getId(), "StartProcess", "Task", "CompensateEvent", "CompensateEvent2", "Compensate", "EndEvent");
- }
-
- public void testSignalBoundaryEventOnTask() throws Exception {
- KnowledgeBase kbase = createKnowledgeBase("BPMN2-BoundarySignalEventOnTaskbpmn2.bpmn");
- StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
- ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
- new TestWorkItemHandler());
- ksession.addEventListener(new DefaultProcessEventListener() {
-
- @Override
- public void afterNodeLeft(ProcessNodeLeftEvent event) {
- System.out.println("After node left " + event.getNodeInstance().getNodeName());
- }
-
- @Override
- public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
- System.out.println("After node triggered " + event.getNodeInstance().getNodeName());
- }
-
- @Override
- public void beforeNodeLeft(ProcessNodeLeftEvent event) {
- System.out.println("Before node left " + event.getNodeInstance().getNodeName());
- }
-
- @Override
- public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
- System.out.println("Before node triggered " + event.getNodeInstance().getNodeName());
- }
-
- });
- ProcessInstance processInstance = ksession.startProcess("BoundarySignalOnTask");
- ksession.signalEvent("MySignal", "hello");
- assertProcessInstanceCompleted(processInstance.getId(), ksession);
- assertNodeTriggered(processInstance.getId(), "StartProcess", "User Task", "Boundary event", "Signal received", "End2");
- }
-
- public void testIntermediateCatchEventSignal() throws Exception {
- KnowledgeBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventSignal.bpmn2");
- StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
- ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
- new DoNothingWorkItemHandler());
- ProcessInstance processInstance = ksession
- .startProcess("IntermediateCatchEvent");
- assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
- ksession = restoreSession(ksession, true);
- // now signal process instance
- ksession.signalEvent("MyMessage", "SomeValue", processInstance.getId());
- assertProcessInstanceCompleted(processInstance.getId(), ksession);
- assertNodeTriggered(processInstance.getId(), "StartProcess", "UserTask", "EndProcess", "event");
- }
-
-}
18 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java
View
@@ -17,15 +17,11 @@
package org.jbpm.bpmn2;
import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import junit.framework.TestCase;
-import org.drools.KnowledgeBase;
-import org.drools.KnowledgeBaseFactory;
+import org.drools.*;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderConfiguration;
import org.drools.builder.KnowledgeBuilderError;
@@ -35,6 +31,7 @@
import org.drools.definition.process.Process;
import org.drools.event.process.DefaultProcessEventListener;
import org.drools.event.process.ProcessStartedEvent;
+import org.drools.impl.EnvironmentFactory;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.ProcessInstance;
@@ -50,6 +47,8 @@
import org.jbpm.bpmn2.xml.XmlBPMNProcessDumper;
import org.jbpm.compiler.xml.XmlProcessReader;
import org.jbpm.process.ProcessBaseFactoryService;
+import org.jbpm.process.instance.event.DefaultSignalManagerFactory;
+import org.jbpm.process.instance.impl.DefaultProcessInstanceManagerFactory;
import org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler;
import org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler;
import org.jbpm.ruleflow.core.RuleFlowProcess;
@@ -838,7 +837,12 @@ private KnowledgeBase createKnowledgeBase(String process) throws Exception {
}
protected StatefulKnowledgeSession createKnowledgeSession(KnowledgeBase kbase) {
- return kbase.newStatefulKnowledgeSession();
+ Properties defaultProps = new Properties();
+ defaultProps.setProperty("drools.processSignalManagerFactory", DefaultSignalManagerFactory.class.getName());
+ defaultProps.setProperty("drools.processInstanceManagerFactory", DefaultProcessInstanceManagerFactory.class.getName());
+ SessionConfiguration sessionConfig = new SessionConfiguration(defaultProps);
+
+ return kbase.newStatefulKnowledgeSession(sessionConfig, EnvironmentFactory.newEnvironment());
}
public void assertProcessInstanceCompleted(long processInstanceId, StatefulKnowledgeSession ksession) {
2  jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/concurrency/MultipleProcessesPerThreadTest.java
View
@@ -18,7 +18,7 @@
import org.drools.event.process.ProcessStartedEvent;
import org.drools.event.process.ProcessVariableChangedEvent;
import org.drools.io.ResourceFactory;
-import org.drools.persistence.util.LoggingPrintStream;
+import org.jbpm.persistence.util.LoggingPrintStream;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.WorkItem;
import org.drools.runtime.process.WorkItemHandler;
8 ...pmn2/src/test/java/org/jbpm/bpmn2/concurrency/persistence/MultipleProcessesPerThreadPersistenceTest.java
View
@@ -1,18 +1,16 @@
package org.jbpm.bpmn2.concurrency.persistence;
-import static org.drools.persistence.util.PersistenceUtil.*;
+import static org.jbpm.persistence.util.PersistenceUtil.*;
import java.util.HashMap;
import org.drools.KnowledgeBase;
import org.drools.persistence.jpa.JPAKnowledgeService;
-import org.drools.persistence.util.PersistenceUtil;
import org.drools.runtime.Environment;
import org.drools.runtime.StatefulKnowledgeSession;
import org.jbpm.bpmn2.concurrency.MultipleProcessesPerThreadTest;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
+import org.jbpm.persistence.util.PersistenceUtil;
+import org.junit.*;
/**
* Class to reproduce bug with multiple threads using persistence and each
8 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/concurrency/persistence/OneProcessPerThreadPersistenceTest.java
View
@@ -1,18 +1,16 @@
package org.jbpm.bpmn2.concurrency.persistence;
-import static org.drools.persistence.util.PersistenceUtil.*;
+import static org.jbpm.persistence.util.PersistenceUtil.*;
import java.util.HashMap;
import org.drools.KnowledgeBase;
import org.drools.persistence.jpa.JPAKnowledgeService;
-import org.drools.persistence.util.PersistenceUtil;
import org.drools.runtime.Environment;
import org.drools.runtime.StatefulKnowledgeSession;
import org.jbpm.bpmn2.concurrency.OneProcessPerThreadTest;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
+import org.jbpm.persistence.util.PersistenceUtil;
+import org.junit.*;
/**
* Class to reproduce bug with multiple threads using persistence and each
40 .../jbpm/bpmn2/Hibernate4ProcessPersistenceTest.java → ...persistence/Hibernate4ProcessPersistenceTest.java
View
@@ -1,49 +1,29 @@
-package org.jbpm.bpmn2;
+package org.jbpm.bpmn2.persistence;
import static junit.framework.Assert.*;
-import static org.drools.persistence.util.PersistenceUtil.*;
+import static org.jbpm.persistence.util.PersistenceUtil.*;
import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
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;
-import org.drools.builder.KnowledgeBuilder;
-import org.drools.builder.KnowledgeBuilderConfiguration;
-import org.drools.builder.KnowledgeBuilderError;
-import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.ResourceType;
+import org.drools.builder.*;
import org.drools.compiler.PackageBuilderConfiguration;
import org.drools.definition.process.Process;
import org.drools.io.ResourceFactory;
import org.drools.persistence.jpa.JPAKnowledgeService;
-import org.drools.runtime.Environment;
-import org.drools.runtime.KnowledgeSessionConfiguration;
-import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.*;
import org.drools.runtime.process.ProcessInstance;
import org.drools.runtime.process.WorkItem;
-import org.drools.runtime.process.WorkflowProcessInstance;
+import org.jbpm.bpmn2.JbpmBpmn2TestCase;
+import org.jbpm.bpmn2.SimpleBPMNProcessTest;
import org.jbpm.bpmn2.JbpmBpmn2TestCase.TestWorkItemHandler;
-import org.jbpm.bpmn2.handler.ReceiveTaskHandler;
-import org.jbpm.bpmn2.xml.BPMNDISemanticModule;
-import org.jbpm.bpmn2.xml.BPMNSemanticModule;
-import org.jbpm.bpmn2.xml.XmlBPMNProcessDumper;
+import org.jbpm.bpmn2.xml.*;
import org.jbpm.compiler.xml.XmlProcessReader;
-import org.jbpm.process.audit.JPAProcessInstanceDbLog;
-import org.jbpm.process.audit.JPAWorkingMemoryDbLogger;
-import org.jbpm.process.audit.NodeInstanceLog;
-import org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler;
+import org.jbpm.process.audit.*;
import org.jbpm.ruleflow.core.RuleFlowProcess;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
64 ...2/persistence/SimplePersistedBPMNProcessTest.java → ...persistence/SimplePersistenceBPMNProcessTest.java
View
@@ -28,6 +28,7 @@
import org.drools.runtime.process.ProcessInstance;
import org.drools.runtime.process.WorkflowProcessInstance;
import org.jbpm.bpmn2.JbpmBpmn2TestCase;
+import org.jbpm.bpmn2.JbpmBpmn2TestCase.TestWorkItemHandler;
import org.jbpm.bpmn2.objects.Person;
import org.jbpm.process.audit.JPAProcessInstanceDbLog;
import org.jbpm.process.audit.NodeInstanceLog;
@@ -36,9 +37,9 @@
import org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler;
import org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler;
-public class SimplePersistedBPMNProcessTest extends JbpmBpmn2TestCase {
+public class SimplePersistenceBPMNProcessTest extends JbpmBpmn2TestCase {
- public SimplePersistedBPMNProcessTest() {
+ public SimplePersistenceBPMNProcessTest() {
super(true);
}
@@ -241,4 +242,63 @@ public void testBusinessRuleTaskDynamic() throws Exception {
assertEquals(1, fired);
assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
+
+ public void testCompensateEndEventProcess() throws Exception {
+ KnowledgeBase kbase = createKnowledgeBase("BPMN2-CompensateEndEvent.bpmn2");
+ StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
+ ProcessInstance processInstance = ksession
+ .startProcess("CompensateEndEvent");
+ assertProcessInstanceCompleted(processInstance.getId(), ksession);
+ assertNodeTriggered(processInstance.getId(), "StartProcess", "Task", "CompensateEvent", "CompensateEvent2", "Compensate", "EndEvent");
+ }
+
+ public void testSignalBoundaryEventOnTask() throws Exception {
+ KnowledgeBase kbase = createKnowledgeBase("BPMN2-BoundarySignalEventOnTaskbpmn2.bpmn");
+ StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
+ ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
+ new TestWorkItemHandler());
+ ksession.addEventListener(new DefaultProcessEventListener() {
+
+ @Override
+ public void afterNodeLeft(ProcessNodeLeftEvent event) {
+ System.out.println("After node left " + event.getNodeInstance().getNodeName());
+ }
+
+ @Override
+ public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
+ System.out.println("After node triggered " + event.getNodeInstance().getNodeName());
+ }
+
+ @Override
+ public void beforeNodeLeft(ProcessNodeLeftEvent event) {
+ System.out.println("Before node left " + event.getNodeInstance().getNodeName());
+ }
+
+ @Override
+ public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
+ System.out.println("Before node triggered " + event.getNodeInstance().getNodeName());
+ }
+
+ });
+ ProcessInstance processInstance = ksession.startProcess("BoundarySignalOnTask");
+ ksession.signalEvent("MySignal", "hello");
+ assertProcessInstanceCompleted(processInstance.getId(), ksession);
+ assertNodeTriggered(processInstance.getId(), "StartProcess", "User Task", "Boundary event", "Signal received", "End2");
+ }
+
+ public void testIntermediateCatchEventSignal() throws Exception {
+ KnowledgeBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventSignal.bpmn2");
+ StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
+ ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
+ new DoNothingWorkItemHandler());
+ ProcessInstance processInstance = ksession
+ .startProcess("IntermediateCatchEvent");
+ assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
+ ksession = restoreSession(ksession, true);
+ // now signal process instance
+ ksession.signalEvent("MyMessage", "SomeValue", processInstance.getId());
+ assertProcessInstanceCompleted(processInstance.getId(), ksession);
+ assertNodeTriggered(processInstance.getId(), "StartProcess", "UserTask", "EndProcess", "event");
+ }
+
}
82 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/persistence/TimerCycleOnBinaryPackageTest.java
View
@@ -1,83 +1,56 @@
package org.jbpm.bpmn2.persistence;
+import static org.jbpm.persistence.util.PersistenceUtil.*;
import static org.junit.Assert.assertEquals;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
+import java.io.*;
+import java.util.*;
import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
import org.drools.KnowledgeBase;
import org.drools.WorkingMemory;
-import org.drools.builder.KnowledgeBuilder;
-import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.ResourceType;
+import org.drools.builder.*;
import org.drools.command.impl.CommandBasedStatefulKnowledgeSession;
import org.drools.command.impl.KnowledgeCommandContext;
import org.drools.core.util.DroolsStreamUtils;
import org.drools.definition.KnowledgePackage;
-import org.drools.event.ActivationCancelledEvent;
-import org.drools.event.ActivationCreatedEvent;
-import org.drools.event.AfterActivationFiredEvent;
-import org.drools.event.AgendaEventListener;
-import org.drools.event.AgendaGroupPoppedEvent;
-import org.drools.event.AgendaGroupPushedEvent;
-import org.drools.event.BeforeActivationFiredEvent;
-import org.drools.event.RuleFlowGroupActivatedEvent;
-import org.drools.event.RuleFlowGroupDeactivatedEvent;
+import org.drools.event.*;
import org.drools.event.process.DefaultProcessEventListener;
import org.drools.event.process.ProcessStartedEvent;
import org.drools.impl.EnvironmentFactory;
import org.drools.impl.StatefulKnowledgeSessionImpl;
import org.drools.io.ResourceFactory;
import org.drools.persistence.jpa.JPAKnowledgeService;
-import org.drools.runtime.Environment;
-import org.drools.runtime.EnvironmentName;
-import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.*;
import org.jbpm.process.audit.JPAWorkingMemoryDbLogger;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import bitronix.tm.resource.jdbc.PoolingDataSource;
+import org.junit.*;
public class TimerCycleOnBinaryPackageTest {
- private PoolingDataSource ds = new PoolingDataSource();
-
+ private HashMap<String, Object> context;
+ private Environment env;
@Before
public void setUp() {
- ds.setUniqueName("jdbc/testDS1");
- ds.setClassName("org.h2.jdbcx.JdbcDataSource");
- ds.setMaxPoolSize(3);
- ds.setAllowLocalTransactions(true);
- ds.getDriverProperties().put("user", "sa");
- ds.getDriverProperties().put("password", "sasa");
- ds.getDriverProperties().put("URL", "jdbc:h2:mem:mydb");
- ds.init();
+ context = setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME);
+
+ // load up the knowledge base
+ env = EnvironmentFactory.newEnvironment();
+ EntityManagerFactory emf = (EntityManagerFactory) context.get(EnvironmentName.ENTITY_MANAGER_FACTORY);
+ env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
}
@After
public void tearDown() {
- ds.close();
+ env = null;
+ cleanUp(context);
}
@Test
public void testStartTimerCycleFromDisc() throws Exception {
-
- // load up the knowledge base
KnowledgeBase kbase = readKnowledgeBaseFromDisc();
- Environment env = EnvironmentFactory.newEnvironment();
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
- env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
-
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
new JPAWorkingMemoryDbLogger(ksession);
@@ -122,18 +95,11 @@ public void beforeProcessStarted(ProcessStartedEvent event) {
assertEquals(3, list2.size());
ksession.dispose();
- emf.close();
}
@Test
public void testStartTimerCycleFromClassPath() throws Exception {
-
- // load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
- Environment env = EnvironmentFactory.newEnvironment();
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
- env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
-
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
new JPAWorkingMemoryDbLogger(ksession);
@@ -178,18 +144,11 @@ public void beforeProcessStarted(ProcessStartedEvent event) {
assertEquals(3, list2.size());
ksession.dispose();
- emf.close();
}
@Test
public void testStartTimerCycleFromDiscDRL() throws Exception {
-
- // load up the knowledge base
KnowledgeBase kbase = readKnowledgeBaseFromDiscDRL();
- Environment env = EnvironmentFactory.newEnvironment();
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
- env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
-
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
new JPAWorkingMemoryDbLogger(ksession);
@@ -224,18 +183,12 @@ public void testStartTimerCycleFromDiscDRL() throws Exception {
assertEquals(3, list2.size());
ksession.dispose();
- emf.close();
}
@Test
public void testStartTimerCycleFromClasspathDRL() throws Exception {
-
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBaseDRL();
- Environment env = EnvironmentFactory.newEnvironment();
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
- env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
-
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
new JPAWorkingMemoryDbLogger(ksession);
@@ -270,7 +223,6 @@ public void testStartTimerCycleFromClasspathDRL() throws Exception {
assertEquals(3, list2.size());
ksession.dispose();
- emf.close();
}
private KnowledgeBase readKnowledgeBaseFromDisc() throws Exception {
49 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/persistence/TimerPersistenceTest.java
View
@@ -15,55 +15,44 @@
*/
package org.jbpm.bpmn2.persistence;
+import static org.jbpm.persistence.util.PersistenceUtil.*;
import static org.junit.Assert.assertEquals;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
import org.drools.KnowledgeBase;
-import org.drools.builder.KnowledgeBuilder;
-import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.ResourceType;
-import org.drools.event.process.DefaultProcessEventListener;
-import org.drools.event.process.ProcessEventListener;
-import org.drools.event.process.ProcessNodeLeftEvent;
+import org.drools.builder.*;
+import org.drools.event.process.*;
import org.drools.impl.EnvironmentFactory;
import org.drools.io.ResourceFactory;
import org.drools.persistence.jpa.JPAKnowledgeService;
-import org.drools.runtime.Environment;
-import org.drools.runtime.EnvironmentName;
-import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.*;
import org.drools.runtime.process.ProcessInstance;
import org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import bitronix.tm.resource.jdbc.PoolingDataSource;
+import org.junit.*;
public class TimerPersistenceTest {
- private PoolingDataSource ds = new PoolingDataSource();
+ private HashMap<String, Object> context;
+ private Environment env;
@Before
public void setUp() {
- ds.setUniqueName("jdbc/testDS1");
- ds.setClassName("org.h2.jdbcx.JdbcDataSource");
- ds.setMaxPoolSize(3);
- ds.setAllowLocalTransactions(true);
- ds.getDriverProperties().put("user", "sa");
- ds.getDriverProperties().put("password", "sasa");
- ds.getDriverProperties().put("URL", "jdbc:h2:mem:mydb");
- ds.init();
+ context = setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME);
+
+ // load up the knowledge base
+ env = EnvironmentFactory.newEnvironment();
+ EntityManagerFactory emf = (EntityManagerFactory) context.get(EnvironmentName.ENTITY_MANAGER_FACTORY);
+ env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
}
@After
public void tearDown() {
- ds.close();
+ env = null;
+ cleanUp(context);
}
@Test
@@ -71,11 +60,6 @@ public void testTimerBoundaryEventCycleISO() throws Exception {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase("BPMN2-TimerBoundaryEventCycleISO.bpmn2");
- Environment env = EnvironmentFactory.newEnvironment();
- EntityManagerFactory emf = Persistence
- .createEntityManagerFactory("org.jbpm.persistence.jpa");
- env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
-
StatefulKnowledgeSession ksession = JPAKnowledgeService
.newStatefulKnowledgeSession(kbase, null, env);
@@ -113,7 +97,6 @@ public void afterNodeLeft(ProcessNodeLeftEvent event) {
ksession.abortProcessInstance(processInstance.getId());
Thread.sleep(1000);
ksession.dispose();
- emf.close();
assertEquals(2, list.size());
}
90 jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/persistence/UnmarshallingOverdueTimersTest.java
View
@@ -1,88 +1,38 @@
package org.jbpm.bpmn2.persistence;
-import static junit.framework.Assert.*;
-import static org.drools.runtime.EnvironmentName.*;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.Map;
+import static junit.framework.Assert.assertTrue;
+import static org.jbpm.persistence.util.PersistenceUtil.*;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
+import java.text.SimpleDateFormat;
+import java.util.*;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
-import org.drools.base.MapGlobalResolver;
-import org.drools.builder.KnowledgeBuilder;
-import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.ResourceType;
-import org.drools.impl.EnvironmentFactory;
+import org.drools.builder.*;
import org.drools.io.ResourceFactory;
import org.drools.persistence.jpa.JPAKnowledgeService;
-import org.drools.runtime.Environment;
-import org.drools.runtime.KnowledgeSessionConfiguration;
-import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.*;
import org.drools.runtime.process.ProcessInstance;
import org.jbpm.bpmn2.concurrency.MultipleProcessesPerThreadTest;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.jbpm.persistence.util.PersistenceUtil;
+import org.junit.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import bitronix.tm.BitronixTransactionManager;
-import bitronix.tm.TransactionManagerServices;
-import bitronix.tm.resource.jdbc.PoolingDataSource;
-
public class UnmarshallingOverdueTimersTest {
private static Logger logger = LoggerFactory.getLogger(MultipleProcessesPerThreadTest.class);
- private static EntityManagerFactory emf;
- private static PoolingDataSource pds;
+ private HashMap<String, Object> context;
@Before
public void setup() {
- pds = new PoolingDataSource();
-
- // The name must match what's in the persistence.xml!
- pds.setUniqueName("jdbc/testDS1");
-
- pds.setMaxPoolSize(16);
- pds.setAllowLocalTransactions(true);
-
- pds.setClassName("bitronix.tm.resource.jdbc.lrc.LrcXADataSource");
- pds.getDriverProperties().put("user", "sa");
- pds.getDriverProperties().put("password", "sasa");
- pds.getDriverProperties().put("url", "jdbc:h2:file:jbpm-test");
- pds.getDriverProperties().put("driverClassName", "org.h2.Driver" );
-
- pds.init();
-
- emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
- assertNotNull("EntityManagerFactory is null.", emf);
+ context = PersistenceUtil.setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME);
}
@After
public void tearDown() throws Exception {
- BitronixTransactionManager txm = TransactionManagerServices.getTransactionManager();
- if (txm != null) {
- txm.shutdown();
- }
-
- try {
- emf.close();
- } catch (Throwable t) {
- t.printStackTrace();
- }
-
- try {
- pds.close();
- } catch (Throwable t) {
- t.printStackTrace();
- }
-
+ cleanUp(context);
}
private static KnowledgeBase loadKnowledgeBase(String bpmn2FileName) {
@@ -93,18 +43,8 @@ private static KnowledgeBase loadKnowledgeBase(String bpmn2FileName) {
return kbase;
}
- private static Environment createEnvironment() {
- Environment env = EnvironmentFactory.newEnvironment();
-
- env.set(ENTITY_MANAGER_FACTORY, emf);
- env.set(TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());
- env.set(GLOBALS, new MapGlobalResolver());
-
- return env;
- }
-
- private static StatefulKnowledgeSession createStatefulKnowledgeSession(KnowledgeBase kbase) {
- Environment env = createEnvironment();
+ private StatefulKnowledgeSession createStatefulKnowledgeSession(KnowledgeBase kbase) {
+ Environment env = createEnvironment(context);
return JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
}
@@ -115,12 +55,12 @@ private static int knowledgeSessionDispose(StatefulKnowledgeSession ksession) {
return ksessionId;
}
- private static StatefulKnowledgeSession reloadStatefulKnowledgeSession(String bpmn2FileName, int ksessionId) {
+ private StatefulKnowledgeSession reloadStatefulKnowledgeSession(String bpmn2FileName, int ksessionId) {
KnowledgeBase kbase = loadKnowledgeBase(bpmn2FileName);
logger.debug(". reloading ksession " + ksessionId);
Environment env = null;
- env = createEnvironment();
+ env = createEnvironment(context);
return JPAKnowledgeService.loadStatefulKnowledgeSession(ksessionId, kbase, null, env);
}
3  jbpm-gwt/jbpm-gwt-core/.gitignore
View
@@ -9,5 +9,6 @@
/*.iws
/*.iml
-# test database
+# test database/info
/*.db
+data/
4 jbpm-gwt/jbpm-gwt-core/pom.xml
View
@@ -169,8 +169,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.drools</groupId>
- <artifactId>drools-persistence-jpa</artifactId>
+ <groupId>org.jbpm</groupId>
+ <artifactId>jbpm-persistence-jpa</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
2  jbpm-gwt/jbpm-gwt-core/src/test/filtered-resources/META-INF/persistence.xml
View
@@ -19,7 +19,7 @@
<class>org.jbpm.process.audit.NodeInstanceLog</class>
<class>org.jbpm.process.audit.VariableInstanceLog</class>
- <class>org.drools.marshalling.util.MarshalledData</class>
+ <class>org.jbpm.marshalling.util.MarshalledData</class>
<properties>
<property name="hibernate.max_fetch_depth" value="3"/>
11 jbpm-gwt/jbpm-gwt-core/src/test/java/org/jbpm/integration/JbpmGwtCoreTestCase.java
View
@@ -1,10 +1,8 @@
package org.jbpm.integration;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.Reader;
+import static org.jbpm.persistence.util.PersistenceUtil.*;
+
+import java.io.*;
import java.util.HashMap;
import java.util.Map;
@@ -14,7 +12,6 @@
import junit.framework.Assert;
import org.drools.SystemEventListenerFactory;
-import org.drools.persistence.util.PersistenceUtil;
import org.jbpm.task.Group;
import org.jbpm.task.User;
import org.jbpm.task.service.TaskService;
@@ -42,7 +39,7 @@
@BeforeClass
public static void setUp(){
if( context == null ) {
- context = PersistenceUtil.setupWithPoolingDataSource(PersistenceUtil.JBPM_PERSISTENCE_UNIT_NAME, false);
+ context = setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME, false);
}
if (minaServerThread==null){
System.setProperty("jbpm.console.directory","./src/test/resources");
23 jbpm-gwt/jbpm-gwt-core/src/test/java/org/jbpm/integration/console/UserManagementTest.java
View
@@ -1,23 +0,0 @@
-package org.jbpm.integration.console;
-
-import static org.junit.Assert.*;
-
-import org.junit.Ignore;
-import org.junit.Test;
-
-public class UserManagementTest {
- UserManagement userManager = new UserManagement();
-
- @Test @Ignore
- public void testGetActorsForGroup(){
- fail("Unimplemented");
- assertEquals(true,userManager.getActorsForGroup("Knights Templar").contains("krisv"));
-
- }
-
- @Test @Ignore
- public void testGetGroupsForActor(){
- fail("Unimplemented");
- assertEquals(true, userManager.getActorsForGroup("krisv").contains("Knights Templar"));
- }
-}
6 jbpm-persistence-jpa/pom.xml
View
@@ -60,12 +60,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.drools</groupId>
- <artifactId>drools-persistence-jpa</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
195 jbpm-persistence-jpa/src/test/filtered-resources/META-INF/persistence.xml
View
@@ -1,104 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
-<persistence version="1.0"
- xmlns="http://java.sun.com/xml/ns/persistence"
- xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd">
-
- <persistence-unit name="org.jbpm.persistence.jpa" transaction-type="JTA">
- <provider>org.hibernate.ejb.HibernatePersistence</provider>
- <jta-data-source>jdbc/testDS1</jta-data-source>
- <mapping-file>META-INF/JBPMorm.xml</mapping-file>
- <mapping-file>META-INF/ProcessInstanceInfo.hbm.xml</mapping-file>
-
- <class>org.drools.persistence.info.SessionInfo</class>
- <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
- <class>org.drools.persistence.info.WorkItemInfo</class>
-
- <class>org.jbpm.persistence.session.objects.MyEntity</class>
- <class>org.jbpm.persistence.session.objects.MyEntityMethods</class>
- <class>org.jbpm.persistence.session.objects.MyEntityOnlyFields</class>
- <class>org.jbpm.persistence.session.objects.MyVariableExtendingSerializable</class>
- <class>org.jbpm.persistence.processinstance.objects.NonSerializableClass</class>
-
- <class>org.drools.marshalling.util.MarshalledData</class>
-
- <properties>
- <property name="hibernate.max_fetch_depth" value="3"/>
- <property name="hibernate.hbm2ddl.auto" value="update" />
- <property name="hibernate.show_sql" value="false" />
- <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.BTMTransactionManagerLookup" />
-
- <property name="hibernate.dialect" value="${maven.hibernate.dialect}"/>
-
- <property name="hibernate.connection.driver_class" value="${maven.jdbc.driver.class}" />
- <property name="hibernate.connection.url" value="${maven.jdbc.url}mem:mydb" />
- <property name="hibernate.connection.username" value="${maven.jdbc.username}" />
- <property name="hibernate.connection.password" value="${maven.jdbc.password}" />
- </properties>
- </persistence-unit>
- <persistence-unit name="org.jbpm.task">
- <provider>org.hibernate.ejb.HibernatePersistence</provider>
- <mapping-file>META-INF/taskOrm.xml</mapping-file>
- <class>org.jbpm.task.Attachment</class>
- <class>org.jbpm.task.Content</class>
- <class>org.jbpm.task.BooleanExpression</class>
- <class>org.jbpm.task.Comment</class>
- <class>org.jbpm.task.Deadline</class>
- <class>org.jbpm.task.Comment</class>
- <class>org.jbpm.task.Deadline</class>
- <class>org.jbpm.task.Delegation</class>
- <class>org.jbpm.task.Escalation</class>
- <class>org.jbpm.task.Group</class>
- <class>org.jbpm.task.I18NText</class>
- <class>org.jbpm.task.Notification</class>
- <class>org.jbpm.task.EmailNotification</class>
- <class>org.jbpm.task.EmailNotificationHeader</class>
- <class>org.jbpm.task.PeopleAssignments</class>
- <class>org.jbpm.task.Reassignment</class>
- <class>org.jbpm.task.Status</class>
- <class>org.jbpm.task.Task</class>
- <class>org.jbpm.task.TaskData</class>
- <class>org.jbpm.task.SubTasksStrategy</class>
- <class>org.jbpm.task.OnParentAbortAllSubTasksEndStrategy</class>
- <class>org.jbpm.task.OnAllSubTasksEndParentEndStrategy</class>
- <class>org.jbpm.task.User</class>
- <properties>
- <property name="hibernate.dialect" value="${maven.hibernate.dialect}"/>
- <property name="hibernate.connection.driver_class" value="${maven.jdbc.driver.class}"/>
- <property name="hibernate.connection.url" value="${maven.jdbc.url}mem:mydb" />
- <property name="hibernate.connection.username" value="${maven.jdbc.username}"/>
- <property name="hibernate.connection.password" value="${maven.jdbc.password}"/>
- <property name="hibernate.connection.autocommit" value="false" />
- <property name="hibernate.max_fetch_depth" value="3"/>
- <property name="hibernate.hbm2ddl.auto" value="update" />
- <property name="hibernate.show_sql" value="true" />
- </properties>
- </persistence-unit>
-
- <persistence-unit name="org.jbpm.persistence.patient.example">
- <provider>org.hibernate.ejb.HibernatePersistence</provider>
-
-
- <class>org.jbpm.persistence.session.objects.Patient</class>
- <class>org.jbpm.persistence.session.objects.MedicalRecord</class>
-
-
- <properties>
- <property name="hibernate.max_fetch_depth" value="3"/>
- <property name="hibernate.hbm2ddl.auto" value="update" />
- <property name="hibernate.show_sql" value="true" />
- <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.BTMTransactionManagerLookup" />
-
- <property name="hibernate.dialect" value="${maven.hibernate.dialect}"/>
-
- <property name="hibernate.connection.driver_class" value="${maven.jdbc.driver.class}" />
- <property name="hibernate.connection.url" value="${maven.jdbc.url}mem:mydb" />
- <property name="hibernate.connection.username" value="${maven.jdbc.username}" />
- <property name="hibernate.connection.password" value="${maven.jdbc.password}" />
-
- <!-- neccessary when testing db2 -->
- <property name="hibernate.default_schema" value="${maven.jdbc.schema}" />
- </properties>
- </persistence-unit>
+<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd">
+
+ <persistence-unit name="org.jbpm.persistence.jpa" transaction-type="JTA">
+ <provider>org.hibernate.ejb.HibernatePersistence</provider>
+ <jta-data-source>jdbc/testDS1</jta-data-source>
+ <mapping-file>META-INF/JBPMorm.xml</mapping-file>
+ <mapping-file>META-INF/ProcessInstanceInfo.hbm.xml</mapping-file>
+
+ <class>org.drools.persistence.info.SessionInfo</class>
+ <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
+ <class>org.drools.persistence.info.WorkItemInfo</class>
+
+ <class>org.jbpm.persistence.session.objects.MyEntity</class>
+ <class>org.jbpm.persistence.session.objects.MyEntityMethods</class>
+ <class>org.jbpm.persistence.session.objects.MyEntityOnlyFields</class>
+ <class>org.jbpm.persistence.session.objects.MyVariableExtendingSerializable</class>
+ <class>org.jbpm.persistence.processinstance.objects.NonSerializableClass</class>
+
+ <class>org.jbpm.marshalling.util.MarshalledData</class>
+
+ <properties>
+ <property name="hibernate.max_fetch_depth" value="3" />
+ <property name="hibernate.hbm2ddl.auto" value="update" />
+ <property name="hibernate.show_sql" value="false" />
+ <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.BTMTransactionManagerLookup" />
+
+ <property name="hibernate.dialect" value="${maven.hibernate.dialect}" />
+
+ <property name="hibernate.connection.driver_class" value="${maven.jdbc.driver.class}" />
+ <property name="hibernate.connection.url" value="${maven.jdbc.url}" />
+ <property name="hibernate.connection.username" value="${maven.jdbc.username}" />
+ <property name="hibernate.connection.password" value="${maven.jdbc.password}" />
+ </properties>
+ </persistence-unit>
+
+ <persistence-unit name="org.jbpm.persistence.jpa.local" transaction-type="RESOURCE_LOCAL">
+ <provider>org.hibernate.ejb.HibernatePersistence</provider>
+ <non-jta-data-source>jdbc/testDS1</non-jta-data-source>
+
+ <mapping-file>META-INF/JBPMorm.xml</mapping-file>
+ <mapping-file>META-INF/ProcessInstanceInfo.hbm.xml</mapping-file>
+
+ <class>org.drools.persistence.info.SessionInfo</class>
+ <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
+ <class>org.drools.persistence.info.WorkItemInfo</class>
+
+ <class>org.jbpm.persistence.session.objects.MyEntity</class>
+ <class>org.jbpm.persistence.session.objects.MyEntityMethods</class>
+ <class>org.jbpm.persistence.session.objects.MyEntityOnlyFields</class>
+ <class>org.jbpm.persistence.session.objects.MyVariableExtendingSerializable</class>
+ <class>org.jbpm.persistence.processinstance.objects.NonSerializableClass</class>
+
+ <class>org.jbpm.marshalling.util.MarshalledData</class>
+
+ <properties>
+ <property name="hibernate.max_fetch_depth" value="3" />
+ <property name="hibernate.hbm2ddl.auto" value="update" />
+ <property name="hibernate.show_sql" value="false" />
+
+ <property name="hibernate.dialect" value="${maven.hibernate.dialect}" />
+
+ <property name="hibernate.connection.driver_class" value="${maven.jdbc.driver.class}" />
+ <property name="hibernate.connection.url" value="${maven.jdbc.url}" />
+ <property name="hibernate.connection.username" value="${maven.jdbc.username}" />
+ <property name="hibernate.connection.password" value="${maven.jdbc.password}" />
+ </properties>
+ </persistence-unit>
+
+ <persistence-unit name="org.jbpm.persistence.patient.example">
+ <provider>org.hibernate.ejb.HibernatePersistence</provider>
+
+ <class>org.jbpm.persistence.session.objects.Patient</class>
+ <class>org.jbpm.persistence.session.objects.MedicalRecord</class>
+
+ <properties>
+ <property name="hibernate.max_fetch_depth" value="3" />
+ <property name="hibernate.hbm2ddl.auto" value="update" />
+ <property name="hibernate.show_sql" value="true" />
+ <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.BTMTransactionManagerLookup" />
+
+ <property name="hibernate.dialect" value="${maven.hibernate.dialect}" />
+
+ <property name="hibernate.connection.driver_class" value="${maven.jdbc.driver.class}" />
+ <property name="hibernate.connection.url" value="${maven.jdbc.url}" />
+ <property name="hibernate.connection.username" value="${maven.jdbc.username}" />
+ <property name="hibernate.connection.password" value="${maven.jdbc.password}" />
+
+ <!-- neccessary when testing db2 -->
+ <property name="hibernate.default_schema" value="${maven.jdbc.schema}" />
+ </properties>
+ </persistence-unit>
</persistence>
28 jbpm-persistence-jpa/src/test/java/org/jbpm/marshalling/DebugJbpmUnmarshallingTest.java
View
@@ -1,29 +1,19 @@
package org.jbpm.marshalling;
-import static org.drools.marshalling.util.MarshallingDBUtil.initializeMarshalledDataEMF;
-import static org.drools.marshalling.util.MarshallingTestUtil.retrieveMarshallingData;
-import static org.drools.persistence.util.PersistenceUtil.*;
import static org.drools.runtime.EnvironmentName.ENTITY_MANAGER_FACTORY;
+import static org.jbpm.marshalling.util.MarshallingDBUtil.initializeMarshalledDataEMF;
+import static org.jbpm.marshalling.util.MarshallingTestUtil.retrieveMarshallingData;
+import static org.jbpm.persistence.util.PersistenceUtil.*;
import static org.junit.Assert.*;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.io.*;
+import java.util.*;
import javax.persistence.EntityManagerFactory;
-import org.drools.marshalling.util.CompareViaReflectionUtil;
-import org.drools.marshalling.util.MarshalledData;
-import org.drools.marshalling.util.MarshallingTestUtil;
import org.drools.persistence.info.SessionInfo;
import org.drools.persistence.info.WorkItemInfo;
+import org.jbpm.marshalling.util.*;
import org.jbpm.persistence.processinstance.ProcessInstanceInfo;
import org.junit.Ignore;
import org.junit.Test;
@@ -100,7 +90,7 @@ public void debugUnmarshallingSpecificMarshalledData() {
fail( "[" + e.getClass().getSimpleName() + "]: " + e.getMessage() );
}
finally {
- tearDown(testContext);
+ cleanUp(testContext);
}
}
@@ -147,7 +137,7 @@ public void compareUnmarshalledObjects() {
fail( "[" + e.getClass().getSimpleName() + "]: " + e.getMessage() );
}
finally {
- tearDown(testContext);
+ cleanUp(testContext);
}
objects[i] = unmarshalledObject;
@@ -186,7 +176,7 @@ public void checkMarshalledSessionInfoObjects() throws IOException {
marshalledDataList = retrieveMarshallingData(emf);
}
finally {
- tearDown(testContext);
+ cleanUp(testContext);
}
return marshalledDataList;
}
788 jbpm-persistence-jpa/src/test/java/org/jbpm/marshalling/util/CompareViaReflectionUtil.java
View
@@ -0,0 +1,788 @@
+/*
+ * Copyright 2011 Red Hat Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jbpm.marshalling.util;
+
+import static org.junit.Assert.fail;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.math.BigDecimal;
+import java.util.AbstractCollection;
+import java.util.AbstractSet;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.IdentityHashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicIntegerArray;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicLongArray;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.concurrent.atomic.AtomicReferenceArray;
+
+import org.drools.base.ClassFieldAccessorCache;
+import org.drools.common.AbstractRuleBase;
+import org.drools.common.AbstractWorkingMemory;
+import org.drools.core.util.AbstractHashTable;
+import org.drools.impl.KnowledgeBaseImpl;
+import org.drools.process.instance.impl.WorkItemImpl;
+import org.drools.reteoo.ReteooRuleBase;
+import org.drools.time.impl.JDKTimerService;
+import org.junit.Assert;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CompareViaReflectionUtil {
+
+ private static Logger logger = LoggerFactory.getLogger(CompareViaReflectionUtil.class);
+
+ public static IdentityHashMap<Object, Object> seenObjects = null;
+ private static Class<?> OBJECT_ARRAY_CLASS = (new Object[0]).getClass();
+
+ private static int TO_ARRAY = 0;
+ private static int ENTRY_SET = 1;
+ private static HashSet<Package> javaPackages = new HashSet<Package>();
+ static {
+ // primitives ("package null")
+ javaPackages.add(long.class.getPackage());
+ // java.math
+ javaPackages.add(BigDecimal.class.getPackage());
+ // java.util
+ javaPackages.add(AbstractCollection.class.getPackage());
+ // java.util.concurrent
+ javaPackages.add(BlockingQueue.class.getPackage());
+ // java.util.concurrent.atomic
+ javaPackages.add(AtomicInteger.class.getPackage());
+ // java.util.concurrent.atomic
+// javaPackages.add(ReentrantLock.class.getPackage());
+ javaPackages.add(Long.class.getPackage());
+ }
+
+ private static HashMap<Class<?>, Integer> arrClassMap = new HashMap<Class<?>, Integer>();
+ {
+ arrClassMap.put((new byte[0]).getClass(), BYTE);
+ arrClassMap.put((new short[0]).getClass(), SHORT);
+ arrClassMap.put((new int[0]).getClass(), INT);
+ arrClassMap.put((new long[0]).getClass(), LONG);
+ arrClassMap.put((new float[0]).getClass(), FLOAT);
+ arrClassMap.put((new double[0]).getClass(), DOUBLE);
+ arrClassMap.put((new boolean[0]).getClass(), BOOLEAN);
+ arrClassMap.put((new char[0]).getClass(), CHAR);
+ arrClassMap.put((new Object[0]).getClass(), OBJECT);
+ }
+
+
+ private static HashSet<Field> doNotCompareFieldsMap = new HashSet<Field>();
+ static {
+ try {
+ doNotCompareFieldsMap.add(AbstractWorkingMemory.class.getDeclaredField("id"));
+ doNotCompareFieldsMap.add(KnowledgeBaseImpl.class.getDeclaredField("mappedKnowledgeBaseListeners"));
+ doNotCompareFieldsMap.add(AbstractRuleBase.class.getDeclaredField("id"));
+ doNotCompareFieldsMap.add(AbstractRuleBase.class.getDeclaredField("workingMemoryCounter"));
+ doNotCompareFieldsMap.add(WorkItemImpl.class.getDeclaredField("id"));
+ doNotCompareFieldsMap.add(WorkItemImpl.class.getDeclaredField("processInstanceId"));
+ doNotCompareFieldsMap.add(ClassFieldAccessorCache.class.getDeclaredField("classLoader"));
+ doNotCompareFieldsMap.add(AbstractWorkingMemory.class.getDeclaredField("globalResolver"));
+ doNotCompareFieldsMap.add(JDKTimerService.class.getDeclaredField("scheduler"));
+ doNotCompareFieldsMap.add(AbstractRuleBase.class.getDeclaredField("classFieldAccessorCache"));
+ } catch (Exception e) {
+ logger.error(e.getClass().getSimpleName() + ": " + e.getMessage());
+ // do nothing
+ }
+ }
+
+ private final static int BYTE = 0;
+ private final static int SHORT = 1;
+ private final static int INT = 2;
+ private final static int LONG = 3;
+ private final static int FLOAT = 4;
+ private final static int DOUBLE = 5;
+ private final static int BOOLEAN = 6;
+ private final static int CHAR = 7;
+ private final static int OBJECT = 8;
+ private final static int NULL = 9;
+
+ @SuppressWarnings("rawtypes")
+ private static HashSet<Class> atomicPrimitiveClasses = new HashSet<Class>();
+ static {
+ atomicPrimitiveClasses.add(AtomicBoolean.class);
+ atomicPrimitiveClasses.add(AtomicInteger.class);
+ atomicPrimitiveClasses.add(AtomicLong.class);
+ atomicPrimitiveClasses.add(AtomicReference.class);
+ }
+
+ @SuppressWarnings("rawtypes")
+ private static HashSet<Class> atomicArrayClasses = new HashSet<Class>();
+ static {
+ atomicArrayClasses.add(AtomicIntegerArray.class);
+ atomicArrayClasses.add(AtomicLongArray.class);
+ atomicArrayClasses.add(AtomicReferenceArray.class);
+ }
+
+ /**
+ * This method compares two objects recursively.
+ * @see #compareInstances(DebugContext, Object, Object)
+ * @param objA The object to be compared to objB.
+ * @param objB The object to be compared to objA.
+ * @return Whether or not the two objects are equal.
+ */
+ public static boolean compareInstances(Object objA, Object objB ) {
+ seenObjects = new IdentityHashMap<Object, Object>();
+ return compareInstances(null, objA, objB);
+ }
+
+ /**
+ * A Java object basically consists (or can consist) of 3 things: <ol>
+ * <li>Methods, if present</li>
+ * <li>Fields (attributes) which contain other Java objects</li>
+ * <li>Fields which contain primitives or primitive based objects (int, Integer, String, etc.)</li>
+ * <li>Fields which contain arrays, Java collection objects (byte [], Set, HashMap, LinkedBlockingQueue, etc..)</li>
+ * </ol>
+ * This means, that when we compare two instantiations of the same class, we can do it as follows:<ul>
+ * <li>Methods:
+ * <ul><li>We don't have to compare methods, since those don't have any "state".</li></ul>
+ * </li><li>Objects:
+ * <ul><li>Comparing fields containing other Java objects (that are don't belong to a java.* package) is simply a recursive operation.</li></ul>
+ * </li><li>Primitive based:
+ * <ul><li>Comparing primitive or primitive based objects can be done using <pre>objA.equals(objB)</pre></li></ul>
+ * </li><li>Arrays:
+ * <ul><li>We iterate through the array and compare elements to each other recursively.</li></ul>
+ * </li><li>Collections:
+ * <ul>
+ * <li>Fields containing collection objects end up having one of two methods:<ul>
+ * <li>toArray(), which returns an Object&lt;?&gt; []</li>
+ * <li>entrySet(), which returns a Set&lt;Map.Entry&lt;K, V&gt;&gt; object</li>
+ * </ul></li>
+ * </ul>
+ * </ul>
+ * And that is exactly what we do in this method! We recursively step through the object tree which
+ * has, as its root node, the class defined by the initial objects given to this method.
+ * </p>
+ * Lastly, you might see the following output if the TRACE level is set for logging out of this object:
+ * <pre>
+ * 0 : objA and objB are both null
+ * X : objA and objB are unequal
+ * = : objA and objB are equal
+ * == : objA and objB are the <i>same</i> instance (of the same object)
+ * (=) : objA and objB are class objects and thus both equal and the same
+ * % : objA and objB are not being compared
+ * ! : objA has already been compared and will not be compared again
+ * in order to avoid cycles in the object tree</pre>
+ * <b>Note</b>: This method has a few weaknesses:<ul>
+ * <li>If the object tree contains objects that <i>extend</i> collection objects (HashMap, List, etc.), this method might not compare them
+ * correctly or efficiently. The logic to do this fairly trivial but just hasn't been added yet.</li>
+ * <li>If the object tree contains objects that are "home made" collection objects, this method might
+ * also not compare these correctly or efficiently. The logic to do this is non-trivial and to some degree
+ * dependent on how the objects are implemented and what type of access is given to the data in the object.</li>
+ * </ul>
+ * One last thing to remember here is the following issue:<ul>
+ * <li>Due to how some objects are created, it's possible that the object tree of objA and object tree of objB
+ * contain the <i>same</i> object instantiation. This will mostly be the result of a static object being used
+ * during the the initialization of the objects. But this is nonetheless wierd, because I don't expect this.
+ * </li><li>When this happens, we say that objA and objB are the same</li>
+ * </ul>
+ * </p>
+ * @param context This contains logging information (recursive level, position in object tree of objA/objB)
+ * @param objA The first instantiation to be compared.
+ * @param objB The first instantiation to be compared.
+ * @return Whether or not objA and objB are equal, given the criteria above.
+ */
+ private static boolean compareInstances(DebugContext context, Object objA, Object objB ) {
+ if( context == null ) {
+ context = new DebugContext(0, "", true);
+ }
+
+ boolean same = false;
+
+ if( objA == null && objB == null ) {
+ context.name += "0";
+ same = true;
+ }
+ else if( objA == null || objB == null ) {
+ context.name += "X";
+ same = false;
+ }
+ else if( objA == objB ) {
+ context.name += objA.getClass().getSimpleName() + " ";
+ String stateSymbol = "==";
+ if( objA instanceof Class<?> | objA instanceof Class) {
+ stateSymbol = "(=)";
+ }
+ context.name += stateSymbol;
+ same = true;
+ }
+ else if( objA.getClass().getName().equals(objB.getClass().getName()) ) {
+ Class<?> objClass = objA.getClass();
+ context.name += "|" + context.level + "| " + objClass.getSimpleName();
+
+ boolean primitiveBasedObjectOrCollection = false;
+ if( javaPackages.contains(objClass.getPackage()) ) {
+ primitiveBasedObjectOrCollection = true;
+ same = comparePrimitiveBasedOrCollectionInstances(context, objA, objB);
+ }
+ else if( objA instanceof AbstractHashTable ) {
+ primitiveBasedObjectOrCollection = true;
+ same = compareDroolsSets(context, objA, objB);
+ }
+ else if( objA.getClass().isArray() ) {
+ primitiveBasedObjectOrCollection = true;
+ same = compareArrays(context, objA, objB);
+ }
+ else {
+ // Check if it's an enum
+ Class<?> superClass = objClass.getSuperclass();
+ while( superClass != null ) {
+ if( superClass.equals(Enum.class) ) {
+ same = objA.equals(objB);
+ primitiveBasedObjectOrCollection = true;
+ break;
+ }
+ superClass = superClass.getSuperclass();
+ }
+ }
+
+ if( ! primitiveBasedObjectOrCollection ) {
+ if( seenObjects.put(objA, objA) == null ) {
+ same = compareInstancesOfSameClass(context, objA, objB);
+ if( !same ) {
+ seenObjects.remove(objA);
+ }
+ }
+ else {
+ context.name += ": !";
+ same = true;
+ }
+ }
+ }
+ else {
+ context.name += ": X";
+ }
+
+ if( context.print ) {
+ logger.trace( context.name );
+ }
+ return same;
+ }
+
+ public static boolean compareArrays(DebugContext context, Object objA, Object objB) {
+
+ // Determine array type class
+ Object classTypeValue = arrClassMap.get(objA.getClass());
+ int classType = -1;
+ if( classTypeValue != null) {
+ classType = (Integer) classTypeValue;
+ }
+ else if( objA.getClass().isArray() ) {
+ classType = OBJECT;
+ }
+ else if( classTypeValue == null ) {
+ classType = NULL;
+ }
+
+ // Check Sameness
+ boolean same = false;
+ switch(classType) {
+ case BYTE:
+ same = Arrays.equals((byte []) objB,(byte [])objA);
+ break;
+ case SHORT:
+ same = Arrays.equals((short []) objB,(short [])objA);
+ break;
+ case INT:
+ same = Arrays.equals((int []) objB,(int [])objA);
+ break;
+ case LONG:
+ same = Arrays.equals((long []) objB,(long [])objA);
+ break;
+ case FLOAT:
+ same = Arrays.equals((float []) objB,(float [])objA);
+ break;
+ case DOUBLE:
+ same = Arrays.equals((double []) objB,(double [])objA);
+ break;
+ case BOOLEAN:
+ same = Arrays.equals((boolean []) objB,(boolean [])objA);
+ break;
+ case CHAR:
+ same = Arrays.equals((char []) objB,(char [])objA);
+ break;
+ case OBJECT:
+ int lengthA = Array.getLength(objA);
+ int lengthB = Array.getLength(objB);
+ if( lengthA != lengthB ) {
+ same = false;
+ }
+ else if( lengthA == 0 ) {
+ same = true;
+ }
+ else {
+ same = true;
+ for( int i = 0; same && i < lengthA; ++i ) {
+ DebugContext subContext = context.clone();
+ subContext.level = context.level + 1;
+ subContext.name = context.name + ": (" + i + ") ";
+ same = compareInstances(subContext, Array.get(objA, i), Array.get(objB, i));
+ }
+ }
+ break;
+ case NULL:
+ same = objA == objB;
+ break;
+ default:
+ fail( "Unable to determine class of array [" + classType + "]");
+ }
+
+ return same;
+ }
+
+ /**
+ * This method should be called when we've been able to ascertain (all) of the following:<ul>
+ * <li>Neither of the objects are null</li>
+ * <li>Both of the objects belong to the same class</li>
+ * </ul>
+ * In this method, we go through <i>all</i> fields of the object and compare them (recursively).
+ * <br/>
+ * @param context This contains logging information (recursive level, position in object tree of objA/objB)
+ * @param objA The first instantiation to be compared.
+ * @param objB The first instantiation to be compared.
+ * @return Whether or not objA and objB are equal.
+ */
+ private static boolean compareInstancesOfSameClass(DebugContext context, Object objA, Object objB) {
+ boolean same = false;
+ try {
+ Class<?> objClass = objA.getClass();
+ do {
+ Field [] fields = objClass.getDeclaredFields();
+ if( fields.length == 0 ) {
+ same = true;
+ }
+ else {
+ same = true;
+ for( int i = 0; same && i < fields.length; ++i ) {
+ DebugContext subContext = context.clone();
+ subContext.level = context.level + 1;
+ subContext.name = context.name + ": " + fields[i].getName() + " > ";
+
+ if( Modifier.isTransient(fields[i].getModifiers()) ||
+ doNotCompareFieldsMap.contains(fields[i]) ) {
+ if( context.print ) {
+ logger.trace( context.name + ": " + fields[i].getName() + " %" );
+ }
+ continue;
+ }
+
+ fields[i].setAccessible(true);
+ Object subObjA = fields[i].get(objA);
+ Object subObjB = fields[i].get(objB);
+ same = compareInstances(subContext, subObjA, subObjB);
+ }
+ }
+ objClass = objClass.getSuperclass();
+ } while( objClass != null && same);
+ context.name += ": " + (same == true ? "=" : "X");
+ }
+ catch( Exception e ) {
+ same = false;
+ e.printStackTrace();
+ Assert.fail(e.getClass().getSimpleName() + ": " + e.getMessage() );
+ }
+ return same;
+ }
+
+
+ private static boolean compareDroolsSets(DebugContext context, Object objA, Object objB) {
+ boolean same = true;
+
+ int length = 0;
+ try {
+ Method sizeMethod = AbstractHashTable.class.getDeclaredMethod("size", (Class []) null);
+ Integer sizeA = (Integer) sizeMethod.invoke(objA, (Object []) null);
+ Integer sizeB = (Integer) sizeMethod.invoke(objB, (Object []) null);
+
+ if( ! sizeA.equals(sizeB) ) {
+ return false;
+ }
+ length = sizeA.intValue();
+ }
+ catch( Exception e ) {
+ same = false;
+ Assert.fail(e.getClass().getSimpleName() + ": " + e.getMessage() );
+ }
+
+ if( length == 0 ) {
+ return true;
+ }
+
+ Method toArrayMethod = null;
+ try {
+ toArrayMethod = AbstractHashTable.class.getDeclaredMethod("toArray", (Class []) null);
+ }
+ catch( Exception e ) {
+ same = false;
+ Assert.fail(e.getClass().getSimpleName() + ": " + e.getMessage() );
+ }
+
+ if( toArrayMethod == null ) {
+ fail("Could not retrieve toArray() method for " + objA.getClass().getName());
+ }
+
+ Object [] arrayA = null;
+ Object [] arrayB = null;
+
+ try {
+ arrayA = (Object []) toArrayMethod.invoke(objA, (Object []) null);
+ arrayB = (Object []) toArrayMethod.invoke(objB, (Object []) null);
+ } catch (Exception e) {
+ same = false;
+ fail(e.getClass().getSimpleName() + ": " + e.getMessage() );
+ }
+
+ if( arrayA == null && arrayB == null ) {
+ return true;
+ }
+ else if( arrayA == null || arrayB == null ) {
+ return false;
+ }
+
+ for( int a = 0; a < length; ++a ) {
+ boolean elementIsSame = false;
+ for( int b = 0; b < length; ++b ) {
+ Object subObjA = arrayA[a];
+ Object subObjB = arrayA[b];
+ try {
+ Method getValueMethod = subObjA.getClass().getMethod("getValue", (Class []) null);
+ subObjA = getValueMethod.invoke(subObjA, (Object [])null);
+ subObjB = getValueMethod.invoke(subObjB, (Object [])null);
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ fail("Could not retrieve getValue() method for " + subObjA.getClass().getName());
+ }
+
+ DebugContext entryContext = context.clone();
+ String name = context.name + ": ";
+ entryContext.level = context.level + 1;
+ entryContext.name = name + "<entry> ";
+ entryContext.print = false;
+ if( compareInstances(entryContext, subObjA, subObjB) ) {
+ logger.trace(entryContext.name);
+ elementIsSame = true;
+ break;
+ }
+ }
+
+ if( ! elementIsSame ) {
+ // a matching element was not found in arrayB
+ same = false;
+ break;
+ }
+ }
+
+ return same;
+ }
+
+ /**
+ * Compare two objects which are all of the following: <ul>
+ * <li>A primitive or primitive based object</li>
+ * <li>A collection object</li>
+ * </ul>
+ * @param context This contains logging information (recursive level, position in object tree of objA/objB)
+ * @param objA The first instantiation to be compared.
+ * @param objB The first instantiation to be compared.
+ * @return Whether or not objA and objB are equal.
+ */
+ private static boolean comparePrimitiveBasedOrCollectionInstances(DebugContext context, Object objA, Object objB) {
+ boolean same = false;
+
+ Class<?> objClass = objA.getClass();
+ Method [] methods = getMethodToRetrieveCollection(objClass);
+ try {
+ if( methods[TO_ARRAY] != null ) {
+ same = compareArrayBasedObjects(context, methods[TO_ARRAY], objA, objB);
+ }
+ else if( methods[ENTRY_SET] != null) {
+ same = compareEntrySetBasedObjects(context, methods[ENTRY_SET], objA, objB);
+ }
+ else if( objClass.isArray() ) {
+ same = compareArrays(context, objA, objB);
+ }
+ else if( atomicPrimitiveClasses.contains(objClass) ) {
+ same = compareAtomicPrimitives(objA, objB);
+ }
+ else if( atomicArrayClasses.contains(objClass) ) {
+ same = compareAtomicArrays(context, objA, objB);
+ }
+ else {
+ same = objA.equals(objB);
+ }
+ context.name += ": " + (same == true ? "=" : "X");
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ same = false;
+ Assert.fail(e.getClass().getSimpleName() + ": " + e.getMessage() );
+ }
+
+ return same;
+ }
+
+ protected static boolean compareAtomicPrimitives(Object objA, Object objB) {
+ boolean same = false;
+ try {
+ Method getMethod = objA.getClass().getMethod("get", new Class[0]);
+ Object valA = getMethod.invoke(objA, (Object []) null);
+ Object valB = getMethod.invoke(objB, (Object []) null);
+ if( valA.equals(valB) ) {
+ same = true;
+ }
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ same = false;
+ Assert.fail(e.getClass().getSimpleName() + ": " + e.getMessage() );
+ }
+ return same;
+ }
+
+ protected static boolean compareAtomicArrays(DebugContext context, Object objA, Object objB) {
+ boolean same = false;
+ int length = 0;
+ try {
+ Method lengthMethod = objA.getClass().getMethod("length", new Class[0]);
+ Object valA = lengthMethod.invoke(objA, (Object []) null);
+ Object valB = lengthMethod.invoke(objB, (Object []) null);
+ if( valA.equals(valB) ) {
+ same = true;
+ length = (Integer) valA;
+ }
+ else {
+ return false;
+ }
+ }
+ catch( Exception e ) {
+ same = false;
+ Assert.fail(e.getClass().getSimpleName() + ": " + e.getMessage() );
+ }
+
+ try {
+ Method getMethod = objA.getClass().getMethod("get", new Class[] { int.class } );
+ for( int i = 0; i < length && same; ++i ) {
+ Object subObjA = getMethod.invoke(objA, i);
+ Object subObjB = getMethod.invoke(objB, i);
+
+ if( subObjA == null && subObjB == null ) {
+ continue;
+ }
+
+ DebugContext subContext = context.clone();
+ subContext.level = context.level + 1;
+ subContext.name = context.name + ": (" + i + ") ";
+ same = compareInstances(subContext, subObjA, subObjB);
+ }
+ } catch (Exception e) {
+ same = false;
+ Assert.fail(e.getClass().getSimpleName() + ": " + e.getMessage() );
+ }
+
+ return same;
+ }
+
+ /**
+ * Collection based objects (Array based or Set based), should basically always implement
+ * one of two methods:<ul>
+ * <li>.toArray()</li>
+ * <li>.entrySet()</li>
+ * </ul>
+ * <p/>
+ * This method retrieves the appropriate method for the given object (so that we can later retrieve
+ * the list/array/set that this Object is based on).
+ * @param objA The object that we want to retrieve this method for.
+ * @return The requested Method.
+ */
+ private static Method [] getMethodToRetrieveCollection(Class<?> objClass) {
+ Method [] methods = new Method[2];
+
+ do {
+ Method [] objMethods = objClass.getDeclaredMethods();
+ for( int m = 0; m < objMethods.length; ++m ) {
+ if(objMethods[m].getName().equals("toArray")
+ && objMethods[m].getParameterTypes().length == 0
+ && objMethods[m].getReturnType().equals(OBJECT_ARRAY_CLASS) ) {
+ methods[TO_ARRAY] = objMethods[m];
+ methods[TO_ARRAY].setAccessible(true);
+ break;
+ }
+ else if(objMethods[m].getName().equals("entrySet")
+ && objMethods[m].getParameterTypes().length == 0
+ && objMethods[m].getReturnType().equals(Set.class) ) {
+ methods[ENTRY_SET] = objMethods[m];
+ methods[ENTRY_SET].setAccessible(true);
+ break;
+ }
+ }
+ objClass = objClass.getSuperclass();
+ } while( objClass != null && methods[TO_ARRAY] == null && methods[ENTRY_SET] == null );
+
+ return methods;
+ }
+
+ private static boolean compareArrayBasedObjects(DebugContext context, Method toArrayMethod, Object objA, Object objB) throws Exception {
+ boolean same = true;
+
+ Object [] arrayA = (Object []) toArrayMethod.invoke(objA, (Object []) null);
+ Object [] arrayB = (Object []) toArrayMethod.invoke(objB, (Object []) null);
+
+ // Simple checks
+ if( arrayA == null && arrayB == null ) {
+ return true;
+ }
+ else if( arrayA == null || arrayB == null ) {
+ return false;
+ }
+ else {
+ if( arrayA.length != arrayB.length ) {
+ return false;
+ }
+ if( arrayA.length == 0 ) {
+ return true;
+ }
+
+ // Check whether order matters
+ Class<?> superClass = objA.getClass().getSuperclass();
+ boolean isSet = false;
+ while( superClass != null ) {
+ if( superClass.equals(AbstractSet.class) ) {
+ isSet = true;
+ }
+ superClass = superClass.getSuperclass();
+ }
+
+ // Check content
+ for( int a = 0; same && a < arrayA.length; ++a ) {
+ Object subObjA = arrayA[a];
+
+ if( ! isSet ) {
+ // order matters, compare element a from both arrays
+ Object subObjB = arrayB[a];
+
+ DebugContext subContext = context.clone();
+ subContext.level = context.level + 1;
+ subContext.name = context.name + ": " + "<elem> ";
+ same = compareInstances(subContext, subObjA, subObjB);
+ }
+ else {
+ // order doesn't matter, check if a matching element exists in arrayB
+ boolean elementIsSame = false;
+ for( int b = 0; ! elementIsSame && b < arrayB.length; ++b ) {
+ Object subObjB = arrayB[b];
+
+ DebugContext subContext = context.clone();
+ subContext.level = context.level + 1;
+ subContext.name = context.name + ": " + "<elem> ";