Search in sources :

Example 11 with ClassPathResource

use of io.automatiko.engine.services.io.ClassPathResource in project automatiko-engine by automatiko-io.

the class InjectStateWorkflowsTest method testMultipleInjectStateWorkflow.

@Test
public void testMultipleInjectStateWorkflow() throws Exception {
    ServerlessProcess process = ServerlessProcess.from(new ClassPathResource("inject-state/helloworld-multiple.json")).get(0);
    assertThat(process).isNotNull();
    ServerlessProcessInstance pi = (ServerlessProcessInstance) process.createInstance();
    pi.start();
    assertThat(pi.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    assertThat(pi.variables().toMap()).hasSize(1).containsKey("result").extracting("result").isEqualTo(new TextNode("Goodbye World!"));
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode) ClassPathResource(io.automatiko.engine.services.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 12 with ClassPathResource

use of io.automatiko.engine.services.io.ClassPathResource in project automatiko-engine by automatiko-io.

the class OperationStateWorkflowsTest method testExpressionOperationStateWorkflow.

@Test
public void testExpressionOperationStateWorkflow() throws Exception {
    ServerlessProcess process = ServerlessProcess.from(new ClassPathResource("operation-state/simple-increment.json")).get(0);
    assertThat(process).isNotNull();
    ServerlessProcessInstance pi = (ServerlessProcessInstance) process.createInstance();
    pi.start();
    assertThat(pi.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    assertThat(pi.variables().toMap()).hasSize(1).containsKey("count").extracting("count").isEqualTo(new IntNode(12));
}
Also used : IntNode(com.fasterxml.jackson.databind.node.IntNode) ClassPathResource(io.automatiko.engine.services.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 13 with ClassPathResource

use of io.automatiko.engine.services.io.ClassPathResource in project automatiko-engine by automatiko-io.

the class SleepStateWorkflowsTest method testSleepStateWorkflow.

@Test
public void testSleepStateWorkflow() throws Exception {
    ServerlessProcess process = ServerlessProcess.from(new ClassPathResource("sleep-state/helloworld-sleep.json")).get(0);
    assertThat(process).isNotNull();
    ServerlessProcessInstance pi = (ServerlessProcessInstance) process.createInstance();
    pi.start();
    Thread.sleep(3000);
    assertThat(pi.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    assertThat(pi.variables().toMap()).hasSize(1).containsKey("result").extracting("result").isEqualTo(new TextNode("Goodbye World!"));
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode) ClassPathResource(io.automatiko.engine.services.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 14 with ClassPathResource

use of io.automatiko.engine.services.io.ClassPathResource in project automatiko-engine by automatiko-io.

the class SwitchStateWorkflowsTest method testSwitchWithEventConditions.

@Test
public void testSwitchWithEventConditions() throws Exception {
    ProcessConfig processConfig = ServerlessProcess.processConfig();
    ((DefaultWorkItemHandlerConfig) processConfig.workItemHandlers()).register("Service Task", new WorkItemHandler() {

        @Override
        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
            ObjectMapper mapper = new ObjectMapper();
            ObjectNode data = mapper.createObjectNode();
            if ("emailStart".equals(workItem.getParameter("Operation"))) {
                data.put("status", "accepted");
                manager.completeWorkItem(workItem.getId(), Collections.singletonMap(JsonVariableScope.WORKFLOWDATA_KEY, data));
            } else if ("emailRejection".equals(workItem.getParameter("Operation"))) {
                data.put("status", "rejected");
                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("switch-state/event-condition.json")).get(0);
    assertThat(process).isNotNull();
    JsonNode data = new ObjectMapper().readTree("{\"applicant\" : {\"name\":\"John\", \"age\":20}}");
    ServerlessProcessInstance pi = (ServerlessProcessInstance) process.createInstance(ServerlessModel.from(data));
    pi.start();
    assertThat(pi.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    pi.send(Sig.of("Message-visaApprovedEvent", data));
    assertThat(pi.variables().toMap()).hasSize(2).containsKey("status").extracting("status").isEqualTo(new TextNode("accepted"));
    assertThat(pi.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    data = new ObjectMapper().readTree("{\"applicant\" : {\"name\":\"Mary\", \"age\":10}}");
    pi = (ServerlessProcessInstance) process.createInstance(ServerlessModel.from(data));
    pi.start();
    assertThat(pi.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    pi.send(Sig.of("Message-visaRejectedEvent", data));
    assertThat(pi.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    assertThat(pi.variables().toMap()).hasSize(2).containsKey("status").extracting("status").isEqualTo(new TextNode("rejected"));
}
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 15 with ClassPathResource

use of io.automatiko.engine.services.io.ClassPathResource in project automatiko-engine by automatiko-io.

the class FileSystemProcessInstancesTest method testComplexVariableFlow.

@Test
public void testComplexVariableFlow() {
    BpmnProcess process = (BpmnProcess) BpmnProcess.from(new ClassPathResource("BPMN2-PersonUserTask.bpmn2")).get(0);
    process.setProcessInstancesFactory(new FileSystemProcessInstancesFactory());
    process.configure();
    Person person = new Person("John", 30);
    Address mainAddress = new Address("first", "Brisbane", "00000", "Australia", true);
    Address secondaryAddress = new Address("second", "Syndey", "11111", "Australia", false);
    person.addAddress(mainAddress);
    person.addAddress(secondaryAddress);
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("person", person)));
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
    assertThat(processInstance.description()).isEqualTo("User Task");
    assertThat(process.instances().values(1, 10)).hasSize(1);
    FileSystemProcessInstances fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
    verify(fileSystemBasedStorage, times(2)).create(any(), any());
    verify(fileSystemBasedStorage, times(1)).setMetadata(any(), eq(FileSystemProcessInstances.PI_DESCRIPTION), eq("User Task"));
    verify(fileSystemBasedStorage, times(1)).setMetadata(any(), eq(FileSystemProcessInstances.PI_STATUS), eq("1"));
    Person testVar = (Person) processInstance.variables().get("person");
    assertThat(testVar).isEqualTo(person);
    assertThat(processInstance.description()).isEqualTo("User Task");
    WorkItem workItem = processInstance.workItems(securityPolicy).get(0);
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameters().get("ActorId")).isEqualTo("john");
    processInstance.completeWorkItem(workItem.getId(), null, securityPolicy);
    assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
    fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
    verify(fileSystemBasedStorage, times(2)).remove(any(), any());
}
Also used : BpmnProcess(io.automatiko.engine.workflow.bpmn2.BpmnProcess) Address(io.automatiko.engine.addons.persistence.data.Address) Person(io.automatiko.engine.addons.persistence.data.Person) 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)

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