Search in sources :

Example 1 with Process

use of org.jbpm.process.core.Process in project kogito-runtimes by kiegroup.

the class RestWorkItemHandlerTest method init.

@BeforeEach
public void init() {
    WebClient webClient = mock(WebClient.class);
    ObjectMapper mapper = new ObjectMapper();
    when(webClient.request(any(HttpMethod.class), eq(8080), eq("localhost"), anyString())).thenReturn(request);
    when(request.sendJsonAndAwait(any())).thenReturn(response);
    when(request.sendAndAwait()).thenReturn(response);
    when(response.bodyAsJson(ObjectNode.class)).thenReturn(ObjectMapperFactory.get().createObjectNode().put("num", 1));
    workItem = new KogitoWorkItemImpl();
    workItem.setId("2");
    parameters = workItem.getParameters();
    parameters.put(RestWorkItemHandler.HOST, "localhost");
    parameters.put(RestWorkItemHandler.PORT, 8080);
    parameters.put(RestWorkItemHandler.URL, "/results/sum");
    parameters.put(RestWorkItemHandler.CONTENT_DATA, workflowData);
    Process process = mock(Process.class);
    ProcessInstance processInstance = mock(ProcessInstance.class);
    workItem.setProcessInstance(processInstance);
    workflowData = mapper.createObjectNode().put("id", 26).put("name", "pepe");
    when(processInstance.getProcess()).thenReturn(process);
    when(processInstance.getVariables()).thenReturn(Collections.singletonMap(DEFAULT_WORKFLOW_VAR, workflowData));
    Variable variable = new Variable();
    variable.setName(DEFAULT_WORKFLOW_VAR);
    variable.setType(new ObjectDataType(ObjectNode.class.getName()));
    variable.setValue(workflowData);
    when(process.getDefaultContext(VariableScope.VARIABLE_SCOPE)).thenReturn(variableScope);
    when(variableScope.findVariable(DEFAULT_WORKFLOW_VAR)).thenReturn(variable);
    when(node.getIoSpecification()).thenReturn(ioSpecification);
    workItem.setNodeInstance(nodeInstance);
    when(nodeInstance.getNode()).thenReturn(node);
    Map<String, String> outputMapping = Collections.singletonMap(RestWorkItemHandler.RESULT, DEFAULT_WORKFLOW_VAR);
    when(ioSpecification.getOutputMappingBySources()).thenReturn(outputMapping);
    handler = new RestWorkItemHandler(webClient);
}
Also used : Variable(org.jbpm.process.core.context.variable.Variable) Process(org.jbpm.process.core.Process) ProcessInstance(org.jbpm.process.instance.ProcessInstance) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) KogitoWorkItemImpl(org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebClient(io.vertx.mutiny.ext.web.client.WebClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpMethod(io.vertx.core.http.HttpMethod) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HttpMethod (io.vertx.core.http.HttpMethod)1 WebClient (io.vertx.mutiny.ext.web.client.WebClient)1 Process (org.jbpm.process.core.Process)1 Variable (org.jbpm.process.core.context.variable.Variable)1 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)1 ProcessInstance (org.jbpm.process.instance.ProcessInstance)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 KogitoWorkItemImpl (org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1