Search in sources :

Example 1 with VariableInstance

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

the class RuntimeDataServiceIntegrationTest method testGetVariableInstance.

@Test
public void testGetVariableInstance() 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<VariableInstance> currentState = queryClient.findVariablesCurrentState(processInstanceId);
        assertNotNull(currentState);
        assertEquals(3, currentState.size());
        for (VariableInstance variableInstance : currentState) {
            if ("personData".equals(variableInstance.getVariableName())) {
                assertNotNull(variableInstance);
                assertEquals(processInstanceId, variableInstance.getProcessInstanceId());
                KieServerAssert.assertNullOrEmpty(variableInstance.getOldValue());
                assertEquals("Person{name='john'}", variableInstance.getValue());
                assertEquals("personData", variableInstance.getVariableName());
            } else if ("stringData".equals(variableInstance.getVariableName())) {
                assertNotNull(variableInstance);
                assertEquals(processInstanceId, variableInstance.getProcessInstanceId());
                KieServerAssert.assertNullOrEmpty(variableInstance.getOldValue());
                assertEquals("waiting for signal", variableInstance.getValue());
                assertEquals("stringData", variableInstance.getVariableName());
            } else if ("initiator".equals(variableInstance.getVariableName())) {
                assertNotNull(variableInstance);
                assertEquals(processInstanceId, variableInstance.getProcessInstanceId());
                assertEquals(TestConfig.getUsername(), variableInstance.getValue());
                KieServerAssert.assertNullOrEmpty(variableInstance.getOldValue());
            } else {
                fail("Got unexpected variable " + variableInstance.getVariableName());
            }
        }
        List<VariableInstance> varHistory = queryClient.findVariableHistory(processInstanceId, "stringData", 0, 10);
        assertNotNull(varHistory);
        assertEquals(1, varHistory.size());
        VariableInstance variableInstance = varHistory.get(0);
        assertNotNull(variableInstance);
        assertEquals(processInstanceId, variableInstance.getProcessInstanceId());
        KieServerAssert.assertNullOrEmpty(variableInstance.getOldValue());
        assertEquals("waiting for signal", variableInstance.getValue());
        assertEquals("stringData", variableInstance.getVariableName());
        processClient.setProcessVariable(CONTAINER_ID, processInstanceId, "stringData", "updated value");
        currentState = queryClient.findVariablesCurrentState(processInstanceId);
        assertNotNull(currentState);
        assertEquals(3, currentState.size());
        for (VariableInstance variable : currentState) {
            if ("personData".equals(variable.getVariableName())) {
                assertNotNull(variable);
                assertEquals(processInstanceId, variable.getProcessInstanceId());
                KieServerAssert.assertNullOrEmpty(variable.getOldValue());
                assertEquals("Person{name='john'}", variable.getValue());
                assertEquals("personData", variable.getVariableName());
            } else if ("stringData".equals(variable.getVariableName())) {
                assertNotNull(variable);
                assertEquals(processInstanceId, variable.getProcessInstanceId());
                assertEquals("waiting for signal", variable.getOldValue());
                assertEquals("updated value", variable.getValue());
                assertEquals("stringData", variable.getVariableName());
            } else if ("initiator".equals(variable.getVariableName())) {
                assertNotNull(variable);
                assertEquals(processInstanceId, variable.getProcessInstanceId());
                assertEquals(TestConfig.getUsername(), variable.getValue());
                KieServerAssert.assertNullOrEmpty(variable.getOldValue());
            } else {
                fail("Got unexpected variable " + variable.getVariableName());
            }
        }
        varHistory = queryClient.findVariableHistory(processInstanceId, "stringData", 0, 10);
        assertNotNull(varHistory);
        assertEquals(2, varHistory.size());
        variableInstance = varHistory.get(0);
        assertNotNull(variableInstance);
        assertEquals(processInstanceId, variableInstance.getProcessInstanceId());
        assertEquals("waiting for signal", variableInstance.getOldValue());
        assertEquals("updated value", variableInstance.getValue());
        assertEquals("stringData", variableInstance.getVariableName());
        variableInstance = varHistory.get(1);
        assertNotNull(variableInstance);
        assertEquals(processInstanceId, variableInstance.getProcessInstanceId());
        KieServerAssert.assertNullOrEmpty(variableInstance.getOldValue());
        assertEquals("waiting for signal", variableInstance.getValue());
        assertEquals("stringData", variableInstance.getVariableName());
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
    }
}
Also used : HashMap(java.util.HashMap) VariableInstance(org.kie.server.api.model.instance.VariableInstance) Test(org.junit.Test)

Example 2 with VariableInstance

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

the class ProcessServiceIntegrationTest method testFindVariableInstances.

@Test
public void testFindVariableInstances() {
    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<VariableInstance> currentState = processClient.findVariablesCurrentState(CONTAINER_ID, processInstanceId);
        assertNotNull(currentState);
        assertEquals(3, currentState.size());
        for (VariableInstance variableInstance : currentState) {
            if ("personData".equals(variableInstance.getVariableName())) {
                assertVariableInstance(variableInstance, processInstanceId, "personData", "Person{name='john'}");
            } else if ("stringData".equals(variableInstance.getVariableName())) {
                assertVariableInstance(variableInstance, processInstanceId, "stringData", "waiting for signal");
            } else if ("initiator".equals(variableInstance.getVariableName())) {
                assertVariableInstance(variableInstance, processInstanceId, "initiator", TestConfig.getUsername());
            } else {
                fail("Got unexpected variable " + variableInstance.getVariableName());
            }
        }
        List<VariableInstance> varHistory = processClient.findVariableHistory(CONTAINER_ID, processInstanceId, "stringData", 0, 10);
        assertNotNull(varHistory);
        assertEquals(1, varHistory.size());
        VariableInstance variableInstance = varHistory.get(0);
        assertVariableInstance(variableInstance, processInstanceId, "stringData", "waiting for signal");
        processClient.setProcessVariable(CONTAINER_ID, processInstanceId, "stringData", "updated value");
        currentState = processClient.findVariablesCurrentState(CONTAINER_ID, processInstanceId);
        assertNotNull(currentState);
        assertEquals(3, currentState.size());
        for (VariableInstance variable : currentState) {
            if ("personData".equals(variable.getVariableName())) {
                assertVariableInstance(variable, processInstanceId, "personData", "Person{name='john'}");
            } else if ("stringData".equals(variable.getVariableName())) {
                assertVariableInstance(variable, processInstanceId, "stringData", "updated value", "waiting for signal");
            } else if ("initiator".equals(variable.getVariableName())) {
                assertVariableInstance(variable, processInstanceId, "initiator", TestConfig.getUsername());
            } else {
                fail("Got unexpected variable " + variable.getVariableName());
            }
        }
        varHistory = processClient.findVariableHistory(CONTAINER_ID, processInstanceId, "stringData", 0, 10);
        assertNotNull(varHistory);
        assertEquals(2, varHistory.size());
        variableInstance = varHistory.get(0);
        assertVariableInstance(variableInstance, processInstanceId, "stringData", "updated value", "waiting for signal");
        variableInstance = varHistory.get(1);
        assertVariableInstance(variableInstance, processInstanceId, "stringData", "waiting for signal");
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
    }
}
Also used : HashMap(java.util.HashMap) VariableInstance(org.kie.server.api.model.instance.VariableInstance) Test(org.junit.Test)

Example 3 with VariableInstance

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

the class AbstractRemoteIntegrationTest method getProcessVariables.

protected HashMap<String, String> getProcessVariables(String containerId, long processInstanceId) {
    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("containerId", containerId);
    parameters.put("processInstanceId", processInstanceId);
    final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
    executionServerCommand.setClient("process");
    executionServerCommand.setOperation("findVariablesCurrentState");
    executionServerCommand.setParameters(parameters);
    final Object response = runOnExecutionServer(executionServerCommand);
    Assertions.assertThat(response).isNotNull();
    Assertions.assertThat(response).isInstanceOf(List.class);
    final List<VariableInstance> variableInstances = (List<VariableInstance>) response;
    final HashMap<String, String> variablesMap = new HashMap<>();
    for (VariableInstance variable : variableInstances) {
        variablesMap.put(variable.getVariableName(), variable.getValue());
    }
    return variablesMap;
}
Also used : HashMap(java.util.HashMap) List(java.util.List) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) VariableInstance(org.kie.server.api.model.instance.VariableInstance)

Example 4 with VariableInstance

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

the class ConvertUtils method convertToVariablesList.

public static VariableInstanceList convertToVariablesList(Collection<VariableDesc> variables) {
    if (variables == null) {
        return new VariableInstanceList(new VariableInstance[0]);
    }
    List<VariableInstance> processes = new ArrayList<VariableInstance>(variables.size());
    for (VariableDesc vi : variables) {
        VariableInstance nodeInstance = convertToVariable(vi);
        processes.add(nodeInstance);
    }
    return new VariableInstanceList(processes);
}
Also used : VariableDesc(org.jbpm.services.api.model.VariableDesc) ArrayList(java.util.ArrayList) VariableInstanceList(org.kie.server.api.model.instance.VariableInstanceList) VariableInstance(org.kie.server.api.model.instance.VariableInstance)

Example 5 with VariableInstance

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

the class DecisionTasksIntegrationTest method testProcessWithBusinessRuleTask.

@Test
public void testProcessWithBusinessRuleTask() throws Exception {
    Long processInstanceId = null;
    try {
        Object john = createPersonInstance(PERSON_JOHN);
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("person", john);
        processInstanceId = processClient.startProcess(CONTAINER_ID, RULE_PROCESS_ID, parameters);
        assertNotNull(processInstanceId);
        assertTrue(processInstanceId.longValue() > 0);
        ProcessInstance processInstance = queryClient.findProcessInstanceById(processInstanceId);
        assertNotNull(processInstance);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.getState().intValue());
        List<VariableInstance> variables = queryClient.findVariablesCurrentState(processInstanceId);
        assertNotNull(variables);
        assertEquals(2, variables.size());
        Map<String, String> mappedVars = variables.stream().collect(Collectors.toMap(VariableInstance::getVariableName, VariableInstance::getValue));
        assertEquals("Person{name='john' age='35'}", mappedVars.get("person"));
        processInstanceId = null;
    } finally {
        if (processInstanceId != null) {
            processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        }
    }
}
Also used : HashMap(java.util.HashMap) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) VariableInstance(org.kie.server.api.model.instance.VariableInstance) Test(org.junit.Test)

Aggregations

VariableInstance (org.kie.server.api.model.instance.VariableInstance)6 HashMap (java.util.HashMap)5 Test (org.junit.Test)4 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 VariableDesc (org.jbpm.services.api.model.VariableDesc)1 ExecutionServerCommand (org.kie.camel.container.api.ExecutionServerCommand)1 VariableInstanceList (org.kie.server.api.model.instance.VariableInstanceList)1