Search in sources :

Example 6 with ClassPathResource

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());
}
Also used : BpmnProcess(io.automatiko.engine.workflow.bpmn2.BpmnProcess) Model(io.automatiko.engine.api.Model) WorkItem(io.automatiko.engine.api.workflow.WorkItem) ClassPathResource(io.automatiko.engine.services.io.ClassPathResource) BpmnVariables(io.automatiko.engine.workflow.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 7 with ClassPathResource

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));
}
Also used : BpmnProcess(io.automatiko.engine.workflow.bpmn2.BpmnProcess) BpmnProcessCompiler(io.automatiko.engine.workflow.bpmn2.BpmnProcessCompiler) SvgBpmnProcessImageGenerator(io.automatiko.engine.codegen.process.image.SvgBpmnProcessImageGenerator) ClassPathResource(io.automatiko.engine.services.io.ClassPathResource)

Example 8 with ClassPathResource

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"));
}
Also used : ProcessConfig(io.automatiko.engine.api.workflow.ProcessConfig) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) WorkItem(io.automatiko.engine.api.runtime.process.WorkItem) DefaultWorkItemHandlerConfig(io.automatiko.engine.workflow.DefaultWorkItemHandlerConfig) ClassPathResource(io.automatiko.engine.services.io.ClassPathResource) WorkItemHandler(io.automatiko.engine.api.runtime.process.WorkItemHandler) WorkItemManager(io.automatiko.engine.api.runtime.process.WorkItemManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 9 with ClassPathResource

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"));
}
Also used : ProcessConfig(io.automatiko.engine.api.workflow.ProcessConfig) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) WorkItem(io.automatiko.engine.api.runtime.process.WorkItem) DefaultWorkItemHandlerConfig(io.automatiko.engine.workflow.DefaultWorkItemHandlerConfig) ClassPathResource(io.automatiko.engine.services.io.ClassPathResource) WorkItemHandler(io.automatiko.engine.api.runtime.process.WorkItemHandler) WorkItemManager(io.automatiko.engine.api.runtime.process.WorkItemManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 10 with ClassPathResource

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!"));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ClassPathResource(io.automatiko.engine.services.io.ClassPathResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Aggregations

ClassPathResource (io.automatiko.engine.services.io.ClassPathResource)18 Test (org.junit.jupiter.api.Test)16 TextNode (com.fasterxml.jackson.databind.node.TextNode)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 BpmnProcess (io.automatiko.engine.workflow.bpmn2.BpmnProcess)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 WorkItem (io.automatiko.engine.api.runtime.process.WorkItem)5 WorkItemHandler (io.automatiko.engine.api.runtime.process.WorkItemHandler)5 WorkItemManager (io.automatiko.engine.api.runtime.process.WorkItemManager)5 ProcessConfig (io.automatiko.engine.api.workflow.ProcessConfig)5 DefaultWorkItemHandlerConfig (io.automatiko.engine.workflow.DefaultWorkItemHandlerConfig)5 BpmnVariables (io.automatiko.engine.workflow.bpmn2.BpmnVariables)4 Model (io.automatiko.engine.api.Model)3 IntNode (com.fasterxml.jackson.databind.node.IntNode)2 WorkItem (io.automatiko.engine.api.workflow.WorkItem)2 Address (io.automatiko.engine.addons.persistence.data.Address)1 Person (io.automatiko.engine.addons.persistence.data.Person)1 SvgBpmnProcessImageGenerator (io.automatiko.engine.codegen.process.image.SvgBpmnProcessImageGenerator)1 BpmnProcessCompiler (io.automatiko.engine.workflow.bpmn2.BpmnProcessCompiler)1