use of io.automatiko.engine.services.io.ClassPathResource in project automatiko-engine by automatiko-io.
the class PredictionAwareHumanTaskLifeCycleTest method testUserTaskWithoutPredictionService.
@Test
public void testUserTaskWithoutPredictionService() {
BpmnProcess process = (BpmnProcess) BpmnProcess.from(config, new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
process.configure();
ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
processInstance.start();
assertEquals(STATE_ACTIVE, processInstance.status());
WorkItem workItem = processInstance.workItems(securityPolicy).get(0);
assertNotNull(workItem);
assertEquals("john", workItem.getParameters().get("ActorId"));
processInstance.completeWorkItem(workItem.getId(), Collections.singletonMap("output", "given value"), securityPolicy);
assertEquals(STATE_COMPLETED, processInstance.status());
Model result = (Model) processInstance.variables();
assertEquals(2, result.toMap().size());
assertEquals("given value", result.toMap().get("s"));
assertEquals(1, trainedTasks.size());
}
use of io.automatiko.engine.services.io.ClassPathResource in project automatiko-engine by automatiko-io.
the class SvgProcessImageGeneratorTest method testGeneration.
public void testGeneration(String processResource) throws IOException {
BpmnProcessCompiler compiler = new BpmnProcessCompiler();
BpmnProcess process = compiler.from(null, new ClassPathResource(processResource)).get(0);
assertThat(process).isNotNull();
SvgBpmnProcessImageGenerator generator = new SvgBpmnProcessImageGenerator((WorkflowProcess) process.process());
String svg = generator.generate();
assertThat(svg).isNotEmpty();
Files.write(Paths.get("target", "test.svg"), svg.getBytes(StandardCharsets.UTF_8));
}
use of io.automatiko.engine.services.io.ClassPathResource in project automatiko-engine by automatiko-io.
the class EventStateWorkflowsTest method testEventStateWorkflow.
@Test
public void testEventStateWorkflow() throws Exception {
ProcessConfig processConfig = ServerlessProcess.processConfig();
((DefaultWorkItemHandlerConfig) processConfig.workItemHandlers()).register("Service Task", new WorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
System.out.println(workItem.getParameters());
ObjectMapper mapper = new ObjectMapper();
ObjectNode data = mapper.createObjectNode();
data.put("greeting", "Hello " + ((TextNode) workItem.getParameter("name")).asText());
manager.completeWorkItem(workItem.getId(), Collections.singletonMap(JsonVariableScope.WORKFLOWDATA_KEY, data));
}
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
}
});
ServerlessProcess process = ServerlessProcess.from(processConfig, new ClassPathResource("event-state/event-state-greeting2.json")).get(0);
assertThat(process).isNotNull();
ServerlessProcessInstance pi = (ServerlessProcessInstance) process.createInstance();
pi.start();
JsonNode data = new ObjectMapper().readTree("{\n" + " \"data\": {\"greet\" : { \"name\" : \"john\"}}\n" + "}");
pi.send(Sig.of("Message-GreetingEvent", data));
assertThat(pi.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(pi.variables().toMap()).hasSize(3).containsKey("greeting").extracting("greeting").isEqualTo(new TextNode("Hello john"));
}
use of io.automatiko.engine.services.io.ClassPathResource in project automatiko-engine by automatiko-io.
the class EventStateWorkflowsTest method testStartWithEventStateWorkflow.
@Test
public void testStartWithEventStateWorkflow() throws Exception {
ProcessConfig processConfig = ServerlessProcess.processConfig();
((DefaultWorkItemHandlerConfig) processConfig.workItemHandlers()).register("Service Task", new WorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
System.out.println(workItem.getParameters());
ObjectMapper mapper = new ObjectMapper();
ObjectNode data = mapper.createObjectNode();
data.put("greeting", "Hello " + ((TextNode) workItem.getParameter("name")).asText());
manager.completeWorkItem(workItem.getId(), Collections.singletonMap(JsonVariableScope.WORKFLOWDATA_KEY, data));
}
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
}
});
ServerlessProcess process = ServerlessProcess.from(processConfig, new ClassPathResource("event-state/event-state-greeting.json")).get(0);
assertThat(process).isNotNull();
JsonNode data = new ObjectMapper().readTree("{\n" + " \"data\": {\"greet\" : { \"name\" : \"john\"}}\n" + "}");
ServerlessProcessInstance pi = (ServerlessProcessInstance) process.createInstance();
pi.start("Message-GreetingEvent", null, data);
assertThat(pi.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(pi.variables().toMap()).hasSize(2).containsKey("greeting").extracting("greeting").isEqualTo(new TextNode("Hello john"));
}
use of io.automatiko.engine.services.io.ClassPathResource in project automatiko-engine by automatiko-io.
the class InjectStateWorkflowsTest method testSingleInjectStateWorkflow.
@Test
public void testSingleInjectStateWorkflow() throws Exception {
ServerlessProcess process = ServerlessProcess.from(new ClassPathResource("examples/helloworld.json")).get(0);
assertThat(process).isNotNull();
JsonNode data = new ObjectMapper().readTree("{\n" + " \"fruits\": [ \"apple\", \"orange\", \"pear\" ],\n" + " \"vegetables\": [\n" + " {\n" + " \"veggieName\": \"potato\",\n" + " \"veggieLike\": true\n" + " },\n" + " {\n" + " \"veggieName\": \"broccoli\",\n" + " \"veggieLike\": false\n" + " }\n" + " ]\n" + "}");
ServerlessProcessInstance pi = (ServerlessProcessInstance) process.createInstance(ServerlessModel.from(data));
pi.start();
assertThat(pi.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(pi.variables().toMap()).hasSize(3).containsKey("result").extracting("result").isEqualTo(new TextNode("Hello World!"));
}
Aggregations