public void testPersistenceWorkItemsUserTransaction() throws Exception {
KieSession service = (KieSession) ctx.getBean( "jpaSingleSessionCommandService" );
int sessionId = service.getId();
ProcessInstance processInstance = service.startProcess( "org.drools.test.TestProcess" );
log.info( "Started process instance {}",
processInstance.getId() );
TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
WorkItem workItem = handler.getWorkItem();
assertNotNull( workItem );
service.dispose();
Environment env = new EnvironmentAdapter( KnowledgeBaseFactory.newEnvironment() );
env.set( EnvironmentName.ENTITY_MANAGER_FACTORY,
ctx.getBean( "myEmf" ) );
env.set( EnvironmentName.TRANSACTION_MANAGER,
ctx.getBean( "txManager" ) );
KieStoreServices kstore = (KieStoreServices) ctx.getBean( "kstore1" );
KieBase kbase1 = (KieBase) ctx.getBean( "kbProcessWorkItems" );
service = kstore.loadKieSession( sessionId,
kbase1,
null,
env );
processInstance = service.getProcessInstance( processInstance.getId() );
assertNotNull( processInstance );
service.dispose();
service = kstore.loadKieSession( sessionId,
kbase1,
null,
env );
service.getWorkItemManager().completeWorkItem( workItem.getId(),
null );
workItem = handler.getWorkItem();
assertNotNull( workItem );
service.dispose();
service = kstore.loadKieSession( sessionId,
kbase1,
null,
env );
processInstance = service.getProcessInstance( processInstance.getId() );
assertNotNull( processInstance );
service.dispose();
service = kstore.loadKieSession( sessionId,
kbase1,
null,
env );
service.getWorkItemManager().abortWorkItem( workItem.getId() );
workItem = handler.getWorkItem();
assertNotNull( workItem );
service.dispose();
service = kstore.loadKieSession( sessionId,
kbase1,
null,
env );
processInstance = service.getProcessInstance( processInstance.getId() );
assertNotNull( processInstance );
service.dispose();
service = kstore.loadKieSession( sessionId,
kbase1,
null,
env );
service.getWorkItemManager().completeWorkItem( workItem.getId(),
null );
workItem = handler.getWorkItem();
assertNull( workItem );
service.dispose();
service = kstore.loadKieSession( sessionId,
kbase1,
null,
env );
processInstance = service.getProcessInstance( processInstance.getId() );
assertNull( processInstance );
service.dispose();
}