Search in sources :

Example 51 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class ExecutionErrorHandlingRuntimeManagerTest method testScriptFailureAfterUserTask.

@Test
public void testScriptFailureAfterUserTask() {
    RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession1 = runtime1.getKieSession();
    assertNotNull(ksession1);
    ProcessInstance pi = ksession1.startProcess("UserTaskWithRollback");
    manager.disposeRuntimeEngine(runtime1);
    runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi.getId()));
    ksession1 = runtime1.getKieSession();
    TaskService taskService = runtime1.getTaskService();
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, tasks.size());
    long taskId = tasks.get(0).getId();
    taskService.start(taskId, "john");
    Map<String, Object> results = new HashMap<>();
    results.put("output1", "rollback");
    try {
        taskService.complete(taskId, "john", results);
        fail("Complete task should fail due to broken script");
    } catch (Throwable e) {
    // expected
    }
    manager.disposeRuntimeEngine(runtime1);
    ExecutionErrorManager errorManager = ((AbstractRuntimeManager) manager).getExecutionErrorManager();
    ExecutionErrorStorage storage = errorManager.getStorage();
    List<ExecutionError> errors = storage.list(0, 10);
    assertNotNull(errors);
    assertEquals(1, errors.size());
    assertExecutionError(errors.get(0), "Process", "UserTaskWithRollback", "Script Task 1");
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExecutionError(org.kie.internal.runtime.error.ExecutionError) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) ExecutionErrorManager(org.kie.internal.runtime.error.ExecutionErrorManager) TaskSummary(org.kie.api.task.model.TaskSummary) ExecutionErrorStorage(org.kie.internal.runtime.error.ExecutionErrorStorage) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 52 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class ExecutionErrorHandlingRuntimeManagerTest method testUserTaskFailure.

@SuppressWarnings("unchecked")
@Test
public void testUserTaskFailure() {
    RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession1 = runtime1.getKieSession();
    assertNotNull(ksession1);
    ksession1.startProcess("UserTaskWithRollback");
    TaskService taskService = runtime1.getTaskService();
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, tasks.size());
    long taskId = tasks.get(0).getId();
    try {
        ((EventService<TaskLifeCycleEventListener>) taskService).registerTaskEventListener(new DefaultTaskEventListener() {

            @Override
            public void afterTaskStartedEvent(TaskEvent event) {
                throw new TaskExecutionException("On purpose");
            }
        });
        taskService.start(taskId, "john");
        fail("Start task should fail due to broken script");
    } catch (Throwable e) {
    // expected
    }
    manager.disposeRuntimeEngine(runtime1);
    ExecutionErrorManager errorManager = ((AbstractRuntimeManager) manager).getExecutionErrorManager();
    ExecutionErrorStorage storage = errorManager.getStorage();
    List<ExecutionError> errors = storage.list(0, 10);
    assertNotNull(errors);
    assertEquals(1, errors.size());
    assertExecutionError(errors.get(0), "Task", "UserTaskWithRollback", "Hello");
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExecutionError(org.kie.internal.runtime.error.ExecutionError) TaskService(org.kie.api.task.TaskService) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) EventService(org.kie.internal.task.api.EventService) DefaultTaskEventListener(org.jbpm.services.task.events.DefaultTaskEventListener) TaskExecutionException(org.jbpm.services.task.exception.TaskExecutionException) ExecutionErrorManager(org.kie.internal.runtime.error.ExecutionErrorManager) TaskSummary(org.kie.api.task.model.TaskSummary) TaskEvent(org.kie.api.task.TaskEvent) ExecutionErrorStorage(org.kie.internal.runtime.error.ExecutionErrorStorage) KieSession(org.kie.api.runtime.KieSession) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 53 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class MigrationManagerTest method assertMigratedTaskAndComplete.

protected void assertMigratedTaskAndComplete(TaskService taskService, String processId, Long processInstanceId, String taskName) {
    List<TaskSummary> tasks = taskService.getTasksByStatusByProcessInstanceId(processInstanceId, Arrays.asList(Status.Reserved), "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    TaskSummary task = tasks.get(0);
    assertNotNull(task);
    assertEquals(processId, task.getProcessId());
    assertEquals(DEPLOYMENT_ID_V2, task.getDeploymentId());
    assertEquals(taskName, task.getName());
    taskService.start(task.getId(), USER_JOHN);
    taskService.complete(task.getId(), USER_JOHN, null);
}
Also used : TaskSummary(org.kie.api.task.model.TaskSummary)

Example 54 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class MigrationManagerTest method testMigrateUserTaskProcessInstance.

@Test
public void testMigrateUserTaskProcessInstance() {
    createRuntimeManagers("migration/v1/BPMN2-UserTask-v1.bpmn2", "migration/v2/BPMN2-UserTask-v2.bpmn2");
    assertNotNull(managerV1);
    assertNotNull(managerV2);
    RuntimeEngine runtime = managerV1.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ProcessInstance pi1 = ksession.startProcess(PROCESS_ID_V1);
    assertNotNull(pi1);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    JPAAuditLogService auditService = new JPAAuditLogService(emf);
    ProcessInstanceLog log = auditService.findProcessInstance(pi1.getId());
    assertNotNull(log);
    assertEquals(PROCESS_ID_V1, log.getProcessId());
    assertEquals(PROCESS_NAME_V1, log.getProcessName());
    assertEquals(DEPLOYMENT_ID_V1, log.getExternalId());
    TaskService taskService = runtime.getTaskService();
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner(USER_JOHN, "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    TaskSummary task = tasks.get(0);
    assertNotNull(task);
    assertEquals(PROCESS_ID_V1, task.getProcessId());
    assertEquals(DEPLOYMENT_ID_V1, task.getDeploymentId());
    assertEquals(TASK_NAME_V1, task.getName());
    managerV1.disposeRuntimeEngine(runtime);
    MigrationSpec migrationSpec = new MigrationSpec(DEPLOYMENT_ID_V1, pi1.getId(), DEPLOYMENT_ID_V2, PROCESS_ID_V2);
    MigrationManager migrationManager = new MigrationManager(migrationSpec);
    MigrationReport report = migrationManager.migrate();
    assertNotNull(report);
    assertTrue(report.isSuccessful());
    log = auditService.findProcessInstance(pi1.getId());
    assertNotNull(log);
    assertEquals(PROCESS_ID_V2, log.getProcessId());
    assertEquals(PROCESS_NAME_V2, log.getProcessName());
    assertEquals(DEPLOYMENT_ID_V2, log.getExternalId());
    auditService.dispose();
    runtime = managerV2.getRuntimeEngine(EmptyContext.get());
    taskService = runtime.getTaskService();
    tasks = taskService.getTasksAssignedAsPotentialOwner(USER_JOHN, "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    task = tasks.get(0);
    assertNotNull(task);
    assertEquals(PROCESS_ID_V2, task.getProcessId());
    assertEquals(DEPLOYMENT_ID_V2, task.getDeploymentId());
    // same name as the node mapping was not given
    assertEquals(TASK_NAME_V2, task.getName());
    managerV2.disposeRuntimeEngine(runtime);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TaskService(org.kie.api.task.TaskService) TaskSummary(org.kie.api.task.model.TaskSummary) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 55 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class MigrationManagerTest method assertTaskAndComplete.

protected void assertTaskAndComplete(TaskService taskService, String processId, Long processInstanceId, String taskName) {
    List<TaskSummary> tasks = taskService.getTasksByStatusByProcessInstanceId(processInstanceId, Arrays.asList(Status.Reserved), "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    TaskSummary task = tasks.get(0);
    assertNotNull(task);
    assertEquals(processId, task.getProcessId());
    assertEquals(DEPLOYMENT_ID_V1, task.getDeploymentId());
    assertEquals(taskName, task.getName());
    taskService.start(task.getId(), USER_JOHN);
    taskService.complete(task.getId(), USER_JOHN, null);
}
Also used : TaskSummary(org.kie.api.task.model.TaskSummary)

Aggregations

TaskSummary (org.kie.api.task.model.TaskSummary)371 Test (org.junit.Test)327 HashMap (java.util.HashMap)132 QueryFilter (org.kie.internal.query.QueryFilter)126 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)100 Task (org.kie.api.task.model.Task)91 ArrayList (java.util.ArrayList)87 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)86 KieSession (org.kie.api.runtime.KieSession)84 TaskService (org.kie.api.task.TaskService)66 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)58 StringReader (java.io.StringReader)55 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)49 QueryContext (org.kie.api.runtime.query.QueryContext)49 Status (org.kie.api.task.model.Status)47 InternalTask (org.kie.internal.task.api.model.InternalTask)47 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)41 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)38 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)36 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)28