SingleSessionCommandService service = new SingleSessionCommandService( kbase,
config,
env );
int sessionId = service.getSessionId();
UserTransaction ut = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" );
ut.begin();
StartProcessCommand startProcessCommand = new StartProcessCommand();
startProcessCommand.setProcessId( "org.drools.test.TestProcess" );
ProcessInstance processInstance = service.execute( startProcessCommand );
System.out.println( "Started process instance " + processInstance.getId() );
ut.commit();
TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
WorkItem workItem = handler.getWorkItem();
assertNotNull( workItem );
service.dispose();
service = new SingleSessionCommandService( sessionId,
kbase,
config,
env );
ut.begin();
GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId( processInstance.getId() );
processInstance = service.execute( getProcessInstanceCommand );
assertNotNull( processInstance );
ut.commit();
service.dispose();
service = new SingleSessionCommandService( sessionId,
kbase,
config,
env );
ut.begin();
CompleteWorkItemCommand completeWorkItemCommand = new CompleteWorkItemCommand();
completeWorkItemCommand.setWorkItemId( workItem.getId() );
service.execute( completeWorkItemCommand );
ut.commit();
workItem = handler.getWorkItem();
assertNotNull( workItem );
service.dispose();
service = new SingleSessionCommandService( sessionId,
kbase,
config,
env );
ut.begin();
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId( processInstance.getId() );
processInstance = service.execute( getProcessInstanceCommand );
ut.commit();
assertNotNull( processInstance );
service.dispose();
service = new SingleSessionCommandService( sessionId,
kbase,
config,
env );
ut.begin();
completeWorkItemCommand = new CompleteWorkItemCommand();
completeWorkItemCommand.setWorkItemId( workItem.getId() );
service.execute( completeWorkItemCommand );
ut.commit();
workItem = handler.getWorkItem();
assertNotNull( workItem );
service.dispose();
service = new SingleSessionCommandService( sessionId,
kbase,
config,
env );
ut.begin();
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId( processInstance.getId() );
processInstance = service.execute( getProcessInstanceCommand );
ut.commit();
assertNotNull( processInstance );
service.dispose();
service = new SingleSessionCommandService( sessionId,
kbase,
config,
env );
ut.begin();
completeWorkItemCommand = new CompleteWorkItemCommand();
completeWorkItemCommand.setWorkItemId( workItem.getId() );
service.execute( completeWorkItemCommand );
ut.commit();
workItem = handler.getWorkItem();
assertNull( workItem );
service.dispose();
service = new SingleSessionCommandService( sessionId,
kbase,
config,
env );
ut.begin();
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId( processInstance.getId() );
processInstance = service.execute( getProcessInstanceCommand );
ut.commit();
assertNull( processInstance );
service.dispose();
}