[Design of JBoss jBPM] - Test Driven Process Development conveniences
by kukeltje
More and more, I'm becomming a fan of this. But my tests quickly become unreadable by anyone that is not kind of familiar with some jBPM internals/api things.
I therefore started to create more and more convenience methods in an class that extended AbstractDBTestcase. Things like deploying processes (to prevent things Bernd ran into), testing if tasks exist, are assigned to a specific actor, a specific number of tasks exist etc... all in the context of a processinstance.
Things I came up with until now are
For each method in the class under test:
- Deploy a processdefinition that has the same filename and name as the method itself
- If not exists deploy a process that has the same filename and name as the class under test
- Start an instance of it and make sure it is running and usable
- At the end, clean up all the 'leftovers'
When working with a processinstance I have the following assertion methods:
- assertTaskExists(String taskname)
- assertTaskExistsForActor(String taskname, String expectedActorId)
- assertTaskListLength(int expectedTasklistLength)
- assertTaskHasEnded(String taskname)
- assertProcessHasEnded()
- assertVariableValue(String variableName, Object expectedValue)
- assertNodeActive(String nodeName)
To prevent the need to use more low level jBPM classes, I choose to use strings. Methods that do use them could ofcourse be introduced as well.
Additional convenience methods that might be in the api eventually are:
- endTask(String taskName);
- endTask(String taskName, String transition);
- assignTask(String taskName, String actorId);
- unassignTask(String taskName); // same as assignTask with actorId being null or empty string
- setVariable(String variableName, Object variableValue)
More methods could be added, but these are the ones I encountered most. I'm currently cleaning up my class before posting it on my blog but hope to get some feedback in advance about this. I also want to add it to the jBPM codebase since it makes tests a lot more easier to read.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4195522#4195522
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4195522
15 years, 5 months
[Design of JBoss jBPM] - Re: AbstractDbTestCase -> deleteProcessDefinition -> hiberna
by camunda
Investigated further:
1) With jbpm.loadToken instead of jbpm.loadTokenForUpdate it works
2) Using jbpmContext.newProcessInstanceForUpdate("Test") also causes the exception.
So my guess is, that the registered autoSave somehow messes in combination with the deletaion.
So my next try was to start a new transaction before deleting, and I get a green bar again:
| ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(xml);
| jbpmContext.deployProcessDefinition(processDefinition);
|
| ProcessInstance processInstance = jbpmContext.newProcessInstanceForUpdate("Test");
| // ProcessInstance processInstance = processDefinition.createProcessInstance();
| Token token = jbpmContext.loadTokenForUpdate(processInstance.getRootToken().getId());
|
| newTransaction();
|
| jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4195493#4195493
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4195493
15 years, 5 months
[Design of JBoss jBPM] - AbstractDbTestCase -> deleteProcessDefinition -> hibernate c
by camunda
Hi all.
I have some very strange problems when writing Tests for Commands. I extended AbstractDbTestCase. The tests worked standalone in Eclipse, but when running the whole test suite with Maven, other tests failed.
Okay, problems with test isolation. So lets clean up after my tests. Hence I deleted the ProcessDefinitions afterwards.Now my tests throw Exceptions :-/
I stripped it down to the following code, which results in a exception what I don't understand completly yet. Anybody an idea?
| public class WhateverTest extends AbstractDbTestCase
| {
| public void testDBProblem() {
| String xml = "<process-definition name='Test'>"
| +" <start-state name='start'>"
| +" <transition to='end' />"
| +" </start-state>"
| +" <end-state name='end' />"
| +"</process-definition>";
| ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(xml);
| jbpmContext.deployProcessDefinition(processDefinition);
| ProcessInstance processInstance = processDefinition.createProcessInstance();
| Token token = jbpmContext.loadTokenForUpdate(processInstance.getRootToken().getId());
| jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
| }
| }
|
The Exception is
| org.jbpm.persistence.JbpmPersistenceException: hibernate commit failed
| at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:223)
| at org.jbpm.svc.Services.close(Services.java:236)
| at org.jbpm.JbpmContext.close(JbpmContext.java:136)
| at org.jbpm.db.AbstractDbTestCase.closeJbpmContext(AbstractDbTestCase.java:193)
| at org.jbpm.db.AbstractDbTestCase.commitAndCloseSession(AbstractDbTestCase.java:116)
| at org.jbpm.db.AbstractDbTestCase.tearDown(AbstractDbTestCase.java:71)
| at junit.framework.TestCase.runBare(TestCase.java:130)
| at junit.framework.TestResult$1.protect(TestResult.java:106)
| at junit.framework.TestResult.runProtected(TestResult.java:124)
| at junit.framework.TestResult.run(TestResult.java:109)
| at junit.framework.TestCase.run(TestCase.java:118)
| at junit.framework.TestSuite.runTest(TestSuite.java:208)
| at junit.framework.TestSuite.run(TestSuite.java:203)
| at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
| at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
| at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
| at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
| at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
| at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
| Caused by: org.hibernate.AssertionFailure: null id in org.jbpm.graph.exe.ProcessInstance entry (don't flush the Session after an exception occurs)
| at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:55)
| at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:164)
| at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:120)
| at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
| at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
| at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
| at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
| at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
| at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
| at org.jbpm.persistence.db.DbPersistenceService.commit(DbPersistenceService.java:262)
| at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:218)
| ... 18 more
|
The problem is the jbpmContext.loadTokenForUpdate, if I remove the statement, the test works... But that should work because of Hibernate SessionCache, or am I totally wrong here?
Thanks for any help or hints!
Cheers
Bernd
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4195487#4195487
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4195487
15 years, 5 months