Search in sources :

Example 96 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class TimerRollbackRegressionIntegrationTest method disposeContainers.

@After
public void disposeContainers() {
    String containerId = "timer-rollback-project-" + runtimeStrategy;
    List<ProcessInstance> startedInstances = queryClient.findProcessInstancesByContainerId(containerId, null, 0, 10, "log.processInstanceId", false);
    for (ProcessInstance processInstanceId : startedInstances) {
        processClient.abortProcessInstance(containerId, processInstanceId.getId());
    }
    disposeAllContainers();
}
Also used : ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) After(org.junit.After)

Example 97 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class UserTaskEscalationIntegrationTest method testRepeatedEscalationsWhenNotCompleted.

@Test(timeout = 15000)
// Potentially unstable on slow DBs.
@Category(Unstable.class)
public void testRepeatedEscalationsWhenNotCompleted() throws Exception {
    Long processInstanceId;
    processInstanceId = processClient.startProcess(CONTAINER_ID_NOTIFICATION, "repeatedEmailNotificationProcess");
    assertNotNull(processInstanceId);
    assertTrue(processInstanceId > 0);
    List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
    Assertions.assertThat(tasks).hasSize(1);
    taskClient.startTask(CONTAINER_ID_NOTIFICATION, tasks.get(0).getId(), USER_YODA);
    Thread.sleep(6000L);
    // 1 NotCompleted repeated notification
    assertTotalOfEmails(1);
    assertEmails("NotCompleted repeated notification every 5secs", "NotCompleted repeated notification every 5secs", USER_YODA, 1);
    taskClient.completeTask(CONTAINER_ID_NOTIFICATION, tasks.get(0).getId(), USER_YODA, new HashMap<>());
    Thread.sleep(6000L);
    // No new notifications should be received
    assertTotalOfEmails(1);
    assertEmails("NotCompleted repeated notification every 5secs", "NotCompleted repeated notification every 5secs", USER_YODA, 1);
    ProcessInstance processInstance = processClient.getProcessInstance(CONTAINER_ID_NOTIFICATION, processInstanceId);
    assertNotNull(processInstance);
    assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.getState().intValue());
}
Also used : TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 98 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class QueryClientIntegrationTest method testFindProcessInstances.

@Test
public void testFindProcessInstances() {
    final Long processInstanceId = startProcess(CONTAINER_ID, PROCESS_WITH_SIGNAL_ID);
    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("page", "0");
    parameters.put("pageSize", "10");
    final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
    executionServerCommand.setClient("query");
    executionServerCommand.setOperation("findProcessInstances");
    executionServerCommand.setParameters(parameters);
    final Object response = runOnExecutionServer(executionServerCommand);
    Assertions.assertThat(response).isNotNull();
    Assertions.assertThat(response).isInstanceOf(List.class);
    final List<ProcessInstance> processInstances = (List<ProcessInstance>) response;
    Assertions.assertThat(processInstances).isNotEmpty();
    final List<Long> processInstancesIds = processInstances.stream().map(p -> p.getId()).collect(Collectors.toList());
    Assertions.assertThat(processInstancesIds).contains(processInstanceId);
    sendSignalToProcessInstance(CONTAINER_ID, processInstanceId, SIGNAL_NAME);
}
Also used : Arrays(java.util.Arrays) List(java.util.List) QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Map(java.util.Map) Assertions(org.assertj.core.api.Assertions) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) HashMap(java.util.HashMap) Test(org.junit.Test) Collectors(java.util.stream.Collectors) HashMap(java.util.HashMap) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) List(java.util.List) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) Test(org.junit.Test)

Example 99 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class ProcessInstanceAdminServiceIntegrationTest method testUpdateTimer.

@Test(timeout = 60 * 1000)
public void testUpdateTimer() throws Exception {
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("timer", "1h");
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_TIMER, parameters);
    assertNotNull(processInstanceId);
    assertTrue(processInstanceId.longValue() > 0);
    try {
        List<TimerInstance> timers = processAdminClient.getTimerInstances(CONTAINER_ID, processInstanceId);
        assertNotNull(timers);
        assertEquals(1, timers.size());
        TimerInstance timerInstance = timers.get(0);
        assertNotNull(timerInstance);
        assertEquals("timer", timerInstance.getTimerName());
        assertNotNull(timerInstance.getId());
        assertNotNull(timerInstance.getTimerId());
        processAdminClient.updateTimer(CONTAINER_ID, processInstanceId, timerInstance.getId(), 3, 0, 0);
        KieServerSynchronization.waitForProcessInstanceToFinish(processClient, CONTAINER_ID, processInstanceId);
        ProcessInstance pi = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
        assertNotNull(pi);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED, pi.getState().intValue());
    } catch (Exception e) {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        fail(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) TimerInstance(org.kie.server.api.model.admin.TimerInstance) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) KieServicesException(org.kie.server.api.exception.KieServicesException) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 100 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class ProcessInstanceMigrationIntegrationTest method testUpgradeParentInstanceWithMultipleSubprocesses.

@Test
public void testUpgradeParentInstanceWithMultipleSubprocesses() {
    Long processParentInstanceId = processClient.startProcess(CONTAINER_ID, PARENT_WITH_MULTIPLE_SUBPROCESSES_ID);
    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());
    assertProcessInstancesInfo(childrenProcessInstance, "subprocessCallingAnotherSubProcess", "1.0", CONTAINER_ID, SUBPROCESS_CALLING_ANOTHER_SUBPROCESS_ID, processParentInstanceId);
    List<ProcessInstance> childrenSubProcessInstance = processClient.findProcessInstancesByParent(CONTAINER_ID, childrenProcessInstance.get(0).getId(), 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));
    ProcessInstance piMigrate = processClient.getProcessInstance(CONTAINER_ID, processParentInstanceId);
    assertProcessInstanceInfo(piMigrate, "parentWithMultipleSubProcesses", "1.0", CONTAINER_ID, PARENT_WITH_MULTIPLE_SUBPROCESSES_ID);
    logger.info("about to process migration from container {} to {} with process definition {} with id {}", piMigrate.getContainerId(), CONTAINER_ID_2, piMigrate.getProcessId(), processParentInstanceId);
    assertMigrateProcessInstanceWithSubprocess(processParentInstanceId, CONTAINER_ID, CONTAINER_ID_2, spec, 3);
    piMigrate = processClient.getProcessInstance(CONTAINER_ID_2, processParentInstanceId);
    assertNotNull(piMigrate);
    assertProcessInstanceInfo(piMigrate, "parentWithMultipleSubProcesses2", "1.0.1", CONTAINER_ID_2, PARENT_WITH_MULTIPLE_SUBPROCESSES_ID_2);
    childrenProcessInstance = processClient.findProcessInstancesByParent(CONTAINER_ID_2, processParentInstanceId, 0, 10);
    logger.info("children instance from {} fetched", CONTAINER_ID_2);
    assertEquals(1, childrenProcessInstance.size());
    assertProcessInstancesInfo(childrenProcessInstance, "subprocessCallingAnotherSubProcess2", "1.0.1", CONTAINER_ID_2, SUBPROCESS_CALLING_ANOTHER_SUBPROCESS_ID_2, processParentInstanceId);
    childrenSubProcessInstance = processClient.findProcessInstancesByParent(CONTAINER_ID_2, childrenProcessInstance.get(0).getId(), 0, 10);
    logger.info("children instance from {} fetched", CONTAINER_ID_2);
    assertEquals(1, childrenSubProcessInstance.size());
    assertProcessInstancesInfo(childrenSubProcessInstance, "subprocess2", "1.0.1", CONTAINER_ID_2, SUBPROCESS_ID_2, childrenProcessInstance.get(0).getId());
    // it stays in the same task
    tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
    assertAndCompleteTasks(tasks, 1, USER_YODA, CONTAINER_ID_2, SUBPROCESS_ID_2);
    logger.info("migration tested!");
}
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) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Aggregations

ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)125 Test (org.junit.Test)97 HashMap (java.util.HashMap)75 TaskSummary (org.kie.server.api.model.instance.TaskSummary)31 ArrayList (java.util.ArrayList)24 QueryDefinition (org.kie.server.api.model.definition.QueryDefinition)22 KieServicesException (org.kie.server.api.exception.KieServicesException)17 ProcessDefinition (org.kie.server.api.model.definition.ProcessDefinition)11 List (java.util.List)9 QueryServicesClient (org.kie.server.client.QueryServicesClient)9 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)9 Category (org.junit.experimental.categories.Category)7 CorrelationKey (org.kie.internal.process.CorrelationKey)7 CorrelationKeyFactory (org.kie.internal.process.CorrelationKeyFactory)7 ProcessServicesClient (org.kie.server.client.ProcessServicesClient)7 Arrays (java.util.Arrays)6 Map (java.util.Map)6 Assertions (org.assertj.core.api.Assertions)6 After (org.junit.After)6 TaskInstance (org.kie.server.api.model.instance.TaskInstance)6