Search in sources :

Example 16 with ProcessDefinition

use of org.kie.server.api.model.definition.ProcessDefinition in project droolsjbpm-integration by kiegroup.

the class QueryClientIntegrationTest method testFindProcessesByContainerIdWrongId.

@Test
public void testFindProcessesByContainerIdWrongId() {
    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("containerId", "wrong-container-id");
    parameters.put("page", "0");
    parameters.put("pageSize", "10");
    final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
    executionServerCommand.setClient("query");
    executionServerCommand.setOperation("findProcessesByContainerId");
    executionServerCommand.setParameters(parameters);
    final Object response = runOnExecutionServer(executionServerCommand);
    Assertions.assertThat(response).isNotNull();
    Assertions.assertThat(response).isInstanceOf(List.class);
    final List<ProcessDefinition> processDefinitions = (List<ProcessDefinition>) response;
    Assertions.assertThat(processDefinitions).isEmpty();
}
Also used : HashMap(java.util.HashMap) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) List(java.util.List) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) Test(org.junit.Test)

Example 17 with ProcessDefinition

use of org.kie.server.api.model.definition.ProcessDefinition in project droolsjbpm-integration by kiegroup.

the class QueryClientIntegrationTest method testFindProcessesByContainerId.

@Test
public void testFindProcessesByContainerId() {
    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("containerId", CONTAINER_ID);
    parameters.put("page", "0");
    parameters.put("pageSize", "10");
    final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
    executionServerCommand.setClient("query");
    executionServerCommand.setOperation("findProcessesByContainerId");
    executionServerCommand.setParameters(parameters);
    final Object response = runOnExecutionServer(executionServerCommand);
    Assertions.assertThat(response).isNotNull();
    Assertions.assertThat(response).isInstanceOf(List.class);
    final List<ProcessDefinition> processDefinitions = (List<ProcessDefinition>) response;
    Assertions.assertThat(processDefinitions).isNotEmpty();
    final List<String> processIds = processDefinitions.stream().map(p -> p.getId()).collect(Collectors.toList());
    Assertions.assertThat(processIds).contains(PROCESS_ID);
}
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) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) List(java.util.List) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) Test(org.junit.Test)

Example 18 with ProcessDefinition

use of org.kie.server.api.model.definition.ProcessDefinition in project droolsjbpm-integration by kiegroup.

the class QueryServicesClientImpl method findProcessByContainerIdProcessId.

@Override
public ProcessDefinition findProcessByContainerIdProcessId(String containerId, String processId) {
    ProcessDefinition result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(PROCESS_ID, processId);
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + PROCESS_DEFINITIONS_BY_CONTAINER_ID_DEF_ID_GET_URI, valuesMap), ProcessDefinition.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessesByDeploymentIdProcessId", new Object[] { containerId, processId })));
        ServiceResponse<ProcessDefinition> response = (ServiceResponse<ProcessDefinition>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = response.getResult();
    }
    return result;
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition)

Example 19 with ProcessDefinition

use of org.kie.server.api.model.definition.ProcessDefinition in project droolsjbpm-integration by kiegroup.

the class KieServerTest method testProcessStartAndWorkOnUserTask.

@Test
public void testProcessStartAndWorkOnUserTask() {
    // query for all available process definitions
    QueryServicesClient queryClient = kieServicesClient.getServicesClient(QueryServicesClient.class);
    List<ProcessDefinition> processes = queryClient.findProcesses(0, 10);
    assertEquals(1, processes.size());
    ProcessServicesClient processClient = kieServicesClient.getServicesClient(ProcessServicesClient.class);
    // get details of process definition
    ProcessDefinition definition = processClient.getProcessDefinition(containerId, processId);
    assertNotNull(definition);
    assertEquals(processId, definition.getId());
    // start process instance
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("employee", "john");
    params.put("reason", "test on spring boot");
    Long processInstanceId = processClient.startProcess(containerId, processId, params);
    assertNotNull(processInstanceId);
    UserTaskServicesClient taskClient = kieServicesClient.getServicesClient(UserTaskServicesClient.class);
    // find available tasks
    List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(user, 0, 10);
    assertEquals(1, tasks.size());
    // complete task
    Long taskId = tasks.get(0).getId();
    taskClient.startTask(containerId, taskId, user);
    taskClient.completeTask(containerId, taskId, user, null);
    // find active process instances
    List<ProcessInstance> instances = queryClient.findProcessInstances(0, 10);
    assertEquals(1, instances.size());
    // at the end abort process instance
    processClient.abortProcessInstance(containerId, processInstanceId);
    ProcessInstance processInstance = queryClient.findProcessInstanceById(processInstanceId);
    assertNotNull(processInstance);
    assertEquals(3, processInstance.getState().intValue());
}
Also used : QueryServicesClient(org.kie.server.client.QueryServicesClient) HashMap(java.util.HashMap) UserTaskServicesClient(org.kie.server.client.UserTaskServicesClient) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) ProcessServicesClient(org.kie.server.client.ProcessServicesClient) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 20 with ProcessDefinition

use of org.kie.server.api.model.definition.ProcessDefinition in project droolsjbpm-integration by kiegroup.

the class KeycloakKieServerTest method testProcessStartAndAbort.

@Test
public void testProcessStartAndAbort() {
    setupClient(JOHN, JOHN_PW);
    // query for all available process definitions
    QueryServicesClient queryClient = kieServicesClient.getServicesClient(QueryServicesClient.class);
    List<ProcessDefinition> processes = queryClient.findProcesses(0, 10);
    assertEquals(2, processes.size());
    ProcessServicesClient processClient = kieServicesClient.getServicesClient(ProcessServicesClient.class);
    // get details of process definition
    ProcessDefinition definition = processClient.getProcessDefinition(containerId, processId);
    assertNotNull(definition);
    assertEquals(processId, definition.getId());
    // start process instance
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("employee", "john");
    params.put("reason", "test on spring boot");
    Long processInstanceId = processClient.startProcess(containerId, processId, params);
    assertNotNull(processInstanceId);
    // find active process instances
    List<ProcessInstance> instances = queryClient.findProcessInstances(0, 10);
    assertEquals(1, instances.size());
    // at the end abort process instance
    processClient.abortProcessInstance(containerId, processInstanceId);
    ProcessInstance processInstance = queryClient.findProcessInstanceById(processInstanceId);
    assertNotNull(processInstance);
    assertEquals(3, processInstance.getState().intValue());
}
Also used : QueryServicesClient(org.kie.server.client.QueryServicesClient) HashMap(java.util.HashMap) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) ProcessServicesClient(org.kie.server.client.ProcessServicesClient) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

ProcessDefinition (org.kie.server.api.model.definition.ProcessDefinition)24 Test (org.junit.Test)19 HashMap (java.util.HashMap)16 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)10 QueryServicesClient (org.kie.server.client.QueryServicesClient)8 List (java.util.List)6 ExecutionServerCommand (org.kie.camel.container.api.ExecutionServerCommand)6 ProcessServicesClient (org.kie.server.client.ProcessServicesClient)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 Collectors (java.util.stream.Collectors)4 Arrays (java.util.Arrays)3 Map (java.util.Map)3 Assertions (org.assertj.core.api.Assertions)3 ServiceResponse (org.kie.server.api.model.ServiceResponse)3 QueryDefinition (org.kie.server.api.model.definition.QueryDefinition)3 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)2 ArrayList (java.util.ArrayList)2 CommandScript (org.kie.server.api.commands.CommandScript)2 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)2 KieServerCommand (org.kie.server.api.model.KieServerCommand)2