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);
}
Aggregations