Search in sources :

Example 11 with KieServicesException

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

the class ProcessInstanceMigrationIntegrationTest method testUpgradeProcessInstance.

@Test
public void testUpgradeProcessInstance() {
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION);
    try {
        List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertEquals(1, tasks.size());
        TaskSummary task = tasks.get(0);
        assertEquals("Evaluate items?", tasks.get(0).getName());
        assertEquals(CONTAINER_ID, task.getContainerId());
        assertEquals(PROCESS_ID_EVALUATION, task.getProcessId());
        assertEquals(processInstanceId, task.getProcessInstanceId());
        // migrate process instance to evaluation 2 in container 2
        MigrationReportInstance report = processAdminClient.migrateProcessInstance(CONTAINER_ID, processInstanceId, CONTAINER_ID_2, PROCESS_ID_EVALUATION_2);
        assertNotNull(report);
        assertTrue(report.isSuccessful());
        // it stays in the same task
        tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertEquals(1, tasks.size());
        task = tasks.get(0);
        assertEquals("Evaluate items?", task.getName());
        assertEquals(CONTAINER_ID_2, task.getContainerId());
        assertEquals(PROCESS_ID_EVALUATION_2, task.getProcessId());
        assertEquals(processInstanceId, task.getProcessInstanceId());
        taskClient.completeAutoProgress(CONTAINER_ID_2, task.getId(), USER_YODA, null);
        // but next task should be Approve user task
        tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertEquals(1, tasks.size());
        task = tasks.get(0);
        assertEquals("Approve", task.getName());
        assertEquals(CONTAINER_ID_2, task.getContainerId());
        assertEquals(PROCESS_ID_EVALUATION_2, task.getProcessId());
        assertEquals(processInstanceId, task.getProcessInstanceId());
    } finally {
        try {
            processClient.getProcessInstance(CONTAINER_ID_2, processInstanceId);
            processClient.abortProcessInstance(CONTAINER_ID_2, processInstanceId);
        } catch (KieServicesException e) {
            processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        }
    }
}
Also used : MigrationReportInstance(org.kie.server.api.model.admin.MigrationReportInstance) 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 12 with KieServicesException

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

the class ProcessInstanceMigrationIntegrationTest method testUpgradeProcessInstances.

@Test
public void testUpgradeProcessInstances() {
    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());
        }
        // migrate process instance to evaluation 2 in container 2
        List<MigrationReportInstance> reports = processAdminClient.migrateProcessInstances(CONTAINER_ID, ids, CONTAINER_ID_2, PROCESS_ID_EVALUATION_2);
        assertNotNull(reports);
        assertEquals(5, reports.size());
        for (MigrationReportInstance report : reports) {
            assertTrue(report.isSuccessful());
        }
        // it stays in the same task
        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_2, task.getContainerId());
            assertEquals(PROCESS_ID_EVALUATION_2, task.getProcessId());
            taskClient.completeAutoProgress(CONTAINER_ID_2, task.getId(), USER_YODA, null);
        }
        // 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 : 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 13 with KieServicesException

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

the class UserTaskAdminServiceIntegrationTest method testErrorHandling.

@Test
public void testErrorHandling() 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.getErrors(CONTAINER_ID, 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());
        userTaskAdminClient.acknowledgeError(CONTAINER_ID, errorInstance.getErrorId());
        errorInstance = userTaskAdminClient.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) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 14 with KieServicesException

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

the class OptaplannerIntegrationTest method testCreateDuplicitSolver.

@Test
public void testCreateDuplicitSolver() {
    SolverInstance solverInstance = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
    assertNotNull(solverInstance);
    try {
        solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
        fail("A KieServicesException should have been thrown by now.");
    } catch (KieServicesException e) {
        KieServerAssert.assertResultContainsStringRegex(e.getMessage(), ".*Failed to create solver. Solver .* already exists for container .*");
    }
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) KieServicesException(org.kie.server.api.exception.KieServicesException) Test(org.junit.Test)

Example 15 with KieServicesException

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

the class OptaplannerIntegrationTest method testExecuteRunningSolver.

@Test
public void testExecuteRunningSolver() throws Exception {
    SolverInstance solverInstance = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
    assertNotNull(solverInstance);
    assertEquals(SolverInstance.SolverStatus.NOT_SOLVING, solverInstance.getStatus());
    // start solver
    Object planningProblem = loadPlanningProblem(5, 15);
    solverClient.solvePlanningProblem(CONTAINER_1_ID, SOLVER_1_ID, planningProblem);
    // start solver again
    try {
        solverClient.solvePlanningProblem(CONTAINER_1_ID, SOLVER_1_ID, planningProblem);
        fail("A KieServicesException should have been thrown by now.");
    } catch (KieServicesException e) {
        KieServerAssert.assertResultContainsStringRegex(e.getMessage(), ".*Solver .* on container .* is already executing.*");
    }
    solverClient.disposeSolver(CONTAINER_1_ID, SOLVER_1_ID);
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) KieServicesException(org.kie.server.api.exception.KieServicesException) Test(org.junit.Test)

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