Search in sources :

Example 21 with KieServicesException

use of org.kie.server.api.exception.KieServicesException in project droolsjbpm-integration by kiegroup.

the class ProcessInstanceMigrationIntegrationTest method testUpgradeInvalidParentInstanceWithSubprocesses.

@Test
public void testUpgradeInvalidParentInstanceWithSubprocesses() {
    Long processParentInstanceId = processClient.startProcess(CONTAINER_ID, PARENT_WITH_MULTIPLE_SUBPROCESSES_ID);
    try {
        assertNotNull(processParentInstanceId);
        assertTrue(processParentInstanceId > 0);
        logger.info("Process in container {} has started {}", CONTAINER_ID, processParentInstanceId);
        List<ProcessInstance> childrenProcessInstance = processClient.findProcessInstancesByParent(CONTAINER_ID, processParentInstanceId, 0, 10);
        assertEquals(1, childrenProcessInstance.size());
        Long childrenProcessInstanceId = childrenProcessInstance.get(0).getId();
        assertNotNull(childrenProcessInstanceId);
        assertTrue(childrenProcessInstanceId > 0);
        assertProcessInstancesInfo(childrenProcessInstance, "subprocessCallingAnotherSubProcess", "1.0", CONTAINER_ID, SUBPROCESS_CALLING_ANOTHER_SUBPROCESS_ID, processParentInstanceId);
        List<ProcessInstance> childrenSubProcessInstance = processClient.findProcessInstancesByParent(CONTAINER_ID, childrenProcessInstanceId, 0, 10);
        assertEquals(1, childrenSubProcessInstance.size());
        assertProcessInstancesInfo(childrenSubProcessInstance, "subprocess", "1.0", CONTAINER_ID, SUBPROCESS_ID, childrenSubProcessInstance.get(0).getParentId());
        List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertEquals(1, tasks.size());
        assertTasksInfo(tasks, "Evaluate items?", CONTAINER_ID, SUBPROCESS_ID);
        MigrationSpecification spec = new MigrationSpecification();
        MigrationProcessSpecification pSpecParent = new MigrationProcessSpecification();
        pSpecParent.setSourceProcessId(PARENT_WITH_MULTIPLE_SUBPROCESSES_ID);
        pSpecParent.setTargetProcessId(PARENT_WITH_MULTIPLE_SUBPROCESSES_ID_2);
        MigrationProcessSpecification pSpecChild = new MigrationProcessSpecification();
        pSpecChild.setSourceProcessId(SUBPROCESS_CALLING_ANOTHER_SUBPROCESS_ID);
        pSpecChild.setTargetProcessId(SUBPROCESS_CALLING_ANOTHER_SUBPROCESS_ID_2);
        MigrationProcessSpecification pSpecSubChild = new MigrationProcessSpecification();
        pSpecSubChild.setSourceProcessId(SUBPROCESS_ID);
        pSpecSubChild.setTargetProcessId(SUBPROCESS_ID_2);
        spec.setProcesses(Arrays.asList(pSpecParent, pSpecChild, pSpecSubChild));
        assertThrows(KieServicesException.class, () -> processAdminClient.migrateProcessInstanceWithSubprocess(CONTAINER_ID, childrenProcessInstanceId, CONTAINER_ID_2, spec));
    } finally {
        try {
            processClient.getProcessInstance(CONTAINER_ID_2, processParentInstanceId);
            processClient.abortProcessInstance(CONTAINER_ID_2, processParentInstanceId);
        } catch (KieServicesException e) {
            processClient.abortProcessInstance(CONTAINER_ID, processParentInstanceId);
        }
    }
}
Also used : MigrationProcessSpecification(org.kie.server.api.model.admin.MigrationProcessSpecification) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) MigrationSpecification(org.kie.server.api.model.admin.MigrationSpecification) KieServicesException(org.kie.server.api.exception.KieServicesException) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 22 with KieServicesException

use of org.kie.server.api.exception.KieServicesException in project droolsjbpm-integration by kiegroup.

the class ProcessInstanceMigrationIntegrationTest method testUpgradeProcessInstancesWithNodeMapping.

@Test
public void testUpgradeProcessInstancesWithNodeMapping() {
    List<Long> ids = new ArrayList<Long>();
    for (int i = 0; i < 5; i++) {
        Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION);
        ids.add(processInstanceId);
    }
    try {
        List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertEquals(5, tasks.size());
        for (TaskSummary task : tasks) {
            assertEquals("Evaluate items?", tasks.get(0).getName());
            assertEquals(CONTAINER_ID, task.getContainerId());
            assertEquals(PROCESS_ID_EVALUATION, task.getProcessId());
        }
        Map<String, String> nodeMapping = new HashMap<String, String>();
        nodeMapping.put("_4E8E7545-FB70-494E-9136-2B9ABE655889", "_56FB3E50-DEDD-415B-94DD-0357C91836B9");
        // migrate process instance to evaluation 2 in container 2
        List<MigrationReportInstance> reports = processAdminClient.migrateProcessInstances(CONTAINER_ID, ids, CONTAINER_ID_2, PROCESS_ID_EVALUATION_2, nodeMapping);
        assertNotNull(reports);
        assertEquals(5, reports.size());
        for (MigrationReportInstance report : reports) {
            assertTrue(report.isSuccessful());
        }
        // but next task should be Approve user task
        tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertEquals(5, tasks.size());
        for (TaskSummary task : tasks) {
            assertEquals("Approve", task.getName());
            assertEquals(CONTAINER_ID_2, task.getContainerId());
            assertEquals(PROCESS_ID_EVALUATION_2, task.getProcessId());
        }
    } finally {
        for (Long processInstanceId : ids) {
            try {
                processClient.getProcessInstance(CONTAINER_ID_2, processInstanceId);
                processClient.abortProcessInstance(CONTAINER_ID_2, processInstanceId);
            } catch (KieServicesException e) {
                processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) MigrationReportInstance(org.kie.server.api.model.admin.MigrationReportInstance) ArrayList(java.util.ArrayList) TaskSummary(org.kie.server.api.model.instance.TaskSummary) KieServicesException(org.kie.server.api.exception.KieServicesException) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 23 with KieServicesException

use of org.kie.server.api.exception.KieServicesException in project droolsjbpm-integration by kiegroup.

the class UserTaskServiceIntegrationTest method testFindTaskEventsSortedBy.

@Test
public void testFindTaskEventsSortedBy() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("stringData", "waiting for signal");
    parameters.put("personData", createPersonInstance(USER_JOHN));
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK, parameters);
    try {
        List<TaskSummary> tasks = taskClient.findTasksByStatusByProcessInstanceId(processInstanceId, null, 0, 10);
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        TaskSummary taskInstance = tasks.get(0);
        taskClient.startTask(CONTAINER_ID, taskInstance.getId(), USER_YODA);
        taskClient.stopTask(CONTAINER_ID, taskInstance.getId(), USER_YODA);
        List<TaskEventInstance> events = taskClient.findTaskEvents(CONTAINER_ID, taskInstance.getId(), 0, 4, SORT_BY_TASK_EVENTS_TYPE, true);
        assertEquals(TaskEvent.TaskEventType.ACTIVATED.toString(), events.get(0).getType());
        assertEquals(TaskEvent.TaskEventType.ADDED.toString(), events.get(1).getType());
        assertEquals(TaskEvent.TaskEventType.STARTED.toString(), events.get(2).getType());
        assertEquals(TaskEvent.TaskEventType.STOPPED.toString(), events.get(3).getType());
        try {
            events = taskClient.findTaskEvents(CONTAINER_ID, taskInstance.getId(), 2, 3, SORT_BY_TASK_EVENTS_TYPE, true);
            KieServerAssert.assertNullOrEmpty("Task events list is not empty.", events);
        } catch (KieServicesException ee) {
            if (configuration.isRest()) {
                KieServerAssert.assertResultContainsString(ee.getMessage(), "Could not find task instance with id " + taskInstance.getId());
                KieServicesHttpException httpEx = (KieServicesHttpException) ee;
                assertEquals(Integer.valueOf(404), httpEx.getHttpCode());
            } else {
                assertTrue(ee.getMessage().contains("No task found with id " + taskInstance.getId()));
            }
        }
        events = taskClient.findTaskEvents(CONTAINER_ID, taskInstance.getId(), 0, 4, SORT_BY_TASK_EVENTS_TYPE, false);
        assertEquals(TaskEvent.TaskEventType.STOPPED.toString(), events.get(0).getType());
        assertEquals(TaskEvent.TaskEventType.STARTED.toString(), events.get(1).getType());
        assertEquals(TaskEvent.TaskEventType.ADDED.toString(), events.get(2).getType());
        assertEquals(TaskEvent.TaskEventType.ACTIVATED.toString(), events.get(3).getType());
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
    }
}
Also used : KieServicesHttpException(org.kie.server.api.exception.KieServicesHttpException) HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) KieServicesException(org.kie.server.api.exception.KieServicesException) TaskEventInstance(org.kie.server.api.model.instance.TaskEventInstance) Test(org.junit.Test)

Example 24 with KieServicesException

use of org.kie.server.api.exception.KieServicesException in project droolsjbpm-integration by kiegroup.

the class ProcessInstanceAdminServiceIntegrationTest method testErrorHandlingFailedToStartBulkAck.

@Test
public void testErrorHandlingFailedToStartBulkAck() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("timer", "invalid value");
    try {
        processClient.startProcess(CONTAINER_ID, PROCESS_ID_TIMER, parameters);
        fail("Process instance should fail as it has invalid timer expression");
    } catch (KieServicesException e) {
    // expected as the variable to configure timer duration is invalid
    }
    try {
        processClient.startProcess(CONTAINER_ID, PROCESS_ID_TIMER, parameters);
        fail("Process instance should fail as it has invalid timer expression");
    } catch (KieServicesException e) {
    // expected as the variable to configure timer duration is invalid
    }
    List<ExecutionErrorInstance> errors = processAdminClient.getErrors(CONTAINER_ID, false, 0, 10);
    errors = filterErrorsByProcessId(errors, PROCESS_ID_TIMER);
    assertNotNull(errors);
    assertEquals(2, errors.size());
    ExecutionErrorInstance errorInstance = errors.get(0);
    assertFalse(errorInstance.isAcknowledged());
    assertNull(errorInstance.getAcknowledgedAt());
    assertNull(errorInstance.getAcknowledgedBy());
    ExecutionErrorInstance errorInstance2 = errors.get(1);
    assertFalse(errorInstance2.isAcknowledged());
    assertNull(errorInstance2.getAcknowledgedAt());
    assertNull(errorInstance2.getAcknowledgedBy());
    processAdminClient.acknowledgeError(CONTAINER_ID, errorInstance.getErrorId(), errorInstance2.getErrorId());
    errors = processAdminClient.getErrors(CONTAINER_ID, false, 0, 10);
    errors = filterErrorsByProcessId(errors, PROCESS_ID_TIMER);
    assertNotNull(errors);
    assertEquals(0, errors.size());
    errorInstance = processAdminClient.getError(CONTAINER_ID, errorInstance.getErrorId());
    assertNotNull(errorInstance);
    assertNotNull(errorInstance.getErrorId());
    assertTrue(errorInstance.isAcknowledged());
    assertNotNull(errorInstance.getAcknowledgedAt());
    assertEquals(USER_YODA, errorInstance.getAcknowledgedBy());
}
Also used : HashMap(java.util.HashMap) KieServicesException(org.kie.server.api.exception.KieServicesException) ExecutionErrorInstance(org.kie.server.api.model.admin.ExecutionErrorInstance) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 25 with KieServicesException

use of org.kie.server.api.exception.KieServicesException in project droolsjbpm-integration by kiegroup.

the class ProcessInstanceAdminServiceIntegrationTest method testErrorHandlingFailedToSignal.

@Test
@Category({ UnstableOnJenkinsPrBuilder.class })
public void testErrorHandlingFailedToSignal() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("nullAccepted", false);
    Long processInstanceId = null;
    try {
        processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_SIGNAL_PROCESS, parameters);
        List<ExecutionErrorInstance> errors = processAdminClient.getErrorsByProcessInstance(CONTAINER_ID, processInstanceId, false, 0, 10);
        assertNotNull(errors);
        assertEquals(0, errors.size());
        try {
            processClient.signalProcessInstance(CONTAINER_ID, processInstanceId, "Signal1", null);
            fail("Process instance signal fail as it provides null as event");
        } catch (KieServicesException e) {
        // expected
        }
        errors = processAdminClient.getErrorsByProcessInstance(CONTAINER_ID, processInstanceId, false, 0, 10);
        assertNotNull(errors);
        assertEquals(1, errors.size());
        ExecutionErrorInstance errorInstance = errors.get(0);
        assertNotNull(errorInstance.getErrorId());
        assertNull(errorInstance.getError());
        assertNotNull(errorInstance.getProcessInstanceId());
        assertNotNull(errorInstance.getActivityId());
        assertNotNull(errorInstance.getErrorDate());
        assertEquals(CONTAINER_ID, errorInstance.getContainerId());
        assertEquals(PROCESS_ID_SIGNAL_PROCESS, errorInstance.getProcessId());
        assertEquals("Signal 1 data", errorInstance.getActivityName());
        assertFalse(errorInstance.isAcknowledged());
        assertNull(errorInstance.getAcknowledgedAt());
        assertNull(errorInstance.getAcknowledgedBy());
        errors = processAdminClient.getErrorsByProcessInstanceAndNode(CONTAINER_ID, processInstanceId, "Signal 1 data", false, 0, 10);
        assertNotNull(errors);
        assertEquals(1, errors.size());
        ExecutionErrorInstance errorInstance2 = errors.get(0);
        assertEquals(errorInstance.getErrorId(), errorInstance2.getErrorId());
        processAdminClient.acknowledgeError(CONTAINER_ID, errorInstance.getErrorId());
        errors = processAdminClient.getErrorsByProcessInstance(CONTAINER_ID, processInstanceId, false, 0, 10);
        assertNotNull(errors);
        assertEquals(0, errors.size());
        errorInstance = processAdminClient.getError(CONTAINER_ID, errorInstance.getErrorId());
        assertNotNull(errorInstance);
        assertNotNull(errorInstance.getErrorId());
        assertTrue(errorInstance.isAcknowledged());
        assertNotNull(errorInstance.getAcknowledgedAt());
        assertEquals(USER_YODA, errorInstance.getAcknowledgedBy());
    } catch (KieServicesException e) {
        logger.error("Unexpected error", e);
        fail(e.getMessage());
    } finally {
        if (processInstanceId != null) {
            processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        }
    }
}
Also used : HashMap(java.util.HashMap) KieServicesException(org.kie.server.api.exception.KieServicesException) ExecutionErrorInstance(org.kie.server.api.model.admin.ExecutionErrorInstance) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Aggregations

KieServicesException (org.kie.server.api.exception.KieServicesException)28 Test (org.junit.Test)19 HashMap (java.util.HashMap)14 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)9 TaskSummary (org.kie.server.api.model.instance.TaskSummary)8 ArrayList (java.util.ArrayList)6 ExecutionErrorInstance (org.kie.server.api.model.admin.ExecutionErrorInstance)5 MigrationReportInstance (org.kie.server.api.model.admin.MigrationReportInstance)4 Map (java.util.Map)3 JMSException (javax.jms.JMSException)3 KieServicesHttpException (org.kie.server.api.exception.KieServicesHttpException)3 ServiceResponse (org.kie.server.api.model.ServiceResponse)3 ServiceResponsesList (org.kie.server.api.model.ServiceResponsesList)3 MessageConsumer (javax.jms.MessageConsumer)2 TextMessage (javax.jms.TextMessage)2 Category (org.junit.experimental.categories.Category)2 QueryDefinition (org.kie.server.api.model.definition.QueryDefinition)2 DocumentInstance (org.kie.server.api.model.instance.DocumentInstance)2 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)2 SolverInstance (org.kie.server.api.model.instance.SolverInstance)2