use of org.jbpm.workflow.instance.WorkflowProcessInstance in project jbpm by kiegroup.
the class GlobalTimerServiceBaseTest method testInterediateTimerWithHTBeforeWithGlobalTestServiceRollback.
@Test(timeout = 20000)
public void testInterediateTimerWithHTBeforeWithGlobalTestServiceRollback() throws Exception {
// prepare listener to assert results
Properties properties = new Properties();
properties.setProperty("mary", "HR");
properties.setProperty("john", "HR");
UserGroupCallback userGroupCallback = new JBossUserGroupCallbackImpl(properties);
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycleWithHT2.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).userGroupCallback(userGroupCallback).get();
manager = getManager(environment, true);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
long ksessionId = ksession.getIdentifier();
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "R3/PT1S");
ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent", params);
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
// get tasks
List<Status> statuses = new ArrayList<Status>();
statuses.add(Status.Reserved);
List<TaskSummary> tasks = runtime.getTaskService().getTasksAssignedAsPotentialOwnerByStatus("john", statuses, "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
runtime.getTaskService().start(task.getId(), "john");
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
try {
ut.begin();
runtime.getTaskService().complete(task.getId(), "john", null);
} finally {
ut.rollback();
}
processInstance = ksession.getProcessInstance(processInstance.getId());
Collection<NodeInstance> activeNodes = ((WorkflowProcessInstance) processInstance).getNodeInstances();
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
assertTrue(activeNodes.iterator().next() instanceof HumanTaskNodeInstance);
TimerService timerService = TimerServiceRegistry.getInstance().get(manager.getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
Collection<TimerJobInstance> timerInstances = timerService.getTimerJobInstances(ksessionId);
assertNotNull(timerInstances);
assertEquals(0, timerInstances.size());
// clean up
ksession.abortProcessInstance(processInstance.getId());
manager.disposeRuntimeEngine(runtime);
}
use of org.jbpm.workflow.instance.WorkflowProcessInstance in project jbpm by kiegroup.
the class ServiceTaskHandlerTest method assertServiceTaskCompleted.
private void assertServiceTaskCompleted(String processName, int jbpmmodule) throws Exception {
if (jbpmmodule == BPMN2) {
ksession.getWorkItemManager().registerWorkItemHandler("Service Task", bpmn2Handler);
} else if (jbpmmodule == WORKITEMS) {
ksession.getWorkItemManager().registerWorkItemHandler("Service Task", workitemsHandler);
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("IntegerVar", new Integer(12345));
params.put("DateVar", new Date());
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess(processName.replace("-", ""), params);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
assertEquals(Integer.valueOf(1), processInstance.getVariable("IntegerVar"));
}
use of org.jbpm.workflow.instance.WorkflowProcessInstance in project jbpm by kiegroup.
the class EventSubprocessTest method testErrorCodeException.
@Test
@BZ("1082111")
public void testErrorCodeException() {
KieSession ksession = createKSession(ERROR_CODE_EXCEPTION);
ksession.getWorkItemManager().registerWorkItemHandler("Request Handler", new SignallingTaskHandlerDecorator(ExceptionOnPurposeHandler.class, "Error-90277"));
ksession.getWorkItemManager().registerWorkItemHandler("Error Handler", new SystemOutWorkItemHandler());
try {
ProcessInstance processInstance = ksession.startProcess(ERROR_CODE_EXCEPTION_ID);
assertProcessInstanceNotActive(processInstance.getId(), ksession);
Assertions.assertThat(((WorkflowProcessInstance) processInstance).getOutcome()).isEqualTo("90277");
} catch (WorkflowRuntimeException e) {
fail("Error code exceptions in subprocess does not work.");
}
}
use of org.jbpm.workflow.instance.WorkflowProcessInstance in project jbpm by kiegroup.
the class KjarRuntimeEnvironmentTest method testXStreamUnmarshalCustomObject.
@Test
public void testXStreamUnmarshalCustomObject() {
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId(GROUP_ID, "xstream-test", VERSION);
File kjar = new File("src/test/resources/kjar/jbpm-module.jar");
File pom = new File("src/test/resources/kjar/pom.xml");
KieMavenRepository repository = getKieMavenRepository();
repository.installArtifact(releaseId, kjar, pom);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(releaseId).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("Rest", new WorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
Map<String, Object> results = new HashMap<String, Object>();
results.put("Result", "<pv207.finepayment.Client><exists>true</exists><name>Pavel</name></pv207.finepayment.Client>");
manager.completeWorkItem(workItem.getId(), results);
}
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
}
});
return handlers;
}
}).userGroupCallback(userGroupCallback).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
assertNotNull(engine);
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance processInstance = engine.getKieSession().startProcess("RESTTask.RestProcess", params);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
Object processClient = ((WorkflowProcessInstance) processInstance).getVariable("processClient");
assertNotNull(processClient);
assertEquals("pv207.finepayment.Client", processClient.getClass().getName());
assertEquals("Pavel", valueOf(processClient, "name"));
assertEquals("true", valueOf(processClient, "exists"));
}
Aggregations