use of io.automatiko.engine.services.io.ClassPathResource in project automatiko-engine by automatiko-io.
the class CallbackStateWorkflowsTest method testCallbackStateWorkflow.
@Test
public void testCallbackStateWorkflow() throws Exception {
ServerlessProcess process = ServerlessProcess.from(new ClassPathResource("callback-state/simple-callback.json")).get(0);
assertThat(process).isNotNull();
ServerlessProcessInstance pi = (ServerlessProcessInstance) process.createInstance();
pi.start();
assertThat(pi.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
assertThat(pi.variables().toMap()).hasSize(1).containsKey("count").extracting("count").isEqualTo(new IntNode(10));
JsonNode data = new ObjectMapper().readTree("{\n" + " \"name\": \"john\"\n" + "}");
pi.send(Sig.of("Message-CarBidEvent", data));
assertThat(pi.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(pi.variables().toMap()).hasSize(2).containsKey("count").extracting("count").isEqualTo(new IntNode(11));
}
use of io.automatiko.engine.services.io.ClassPathResource in project automatiko-engine by automatiko-io.
the class InjectStateWorkflowsTest method testMultipleInjectStateWithAnnotationsWorkflow.
@Test
public void testMultipleInjectStateWithAnnotationsWorkflow() throws Exception {
ServerlessProcess process = ServerlessProcess.from(new ClassPathResource("inject-state/helloworld-multiple-with-annotations.json")).get(0);
assertThat(process).isNotNull();
JsonNode data = new ObjectMapper().readTree("{\n" + " \"name\": \"john\"\n" + "}");
ServerlessProcessInstance pi = (ServerlessProcessInstance) process.createInstance(ServerlessModel.from(data));
pi.start();
assertThat(pi.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(pi.variables().toMap()).hasSize(2).containsKey("result").extracting("result").isEqualTo(new TextNode("Goodbye World!"));
assertThat(pi.tags().values()).hasSize(4).contains("a", "b", "c", "john");
}
use of io.automatiko.engine.services.io.ClassPathResource in project automatiko-engine by automatiko-io.
the class OperationStateWorkflowsTest method testRestOperationStateWorkflow.
@Test
public void testRestOperationStateWorkflow() 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", "test");
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("examples/greeting.json")).get(0);
assertThat(process).isNotNull();
JsonNode data = new ObjectMapper().readTree("{\n" + " \"person\": {\"name\" : \"john\"}\n" + "}");
ServerlessProcessInstance pi = (ServerlessProcessInstance) process.createInstance(ServerlessModel.from(data));
pi.start();
assertThat(pi.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(pi.variables().toMap()).hasSize(2).containsKey("greeting").extracting("greeting").isEqualTo(new TextNode("test"));
}
use of io.automatiko.engine.services.io.ClassPathResource in project automatiko-engine by automatiko-io.
the class OperationStateWorkflowsTest method testSingleInjectStateWorkflowWithConstants.
@Test
public void testSingleInjectStateWorkflowWithConstants() throws Exception {
ServerlessProcess process = ServerlessProcess.from(new ClassPathResource("operation-state/helloworld-const.json")).get(0);
assertThat(process).isNotNull();
ServerlessProcessInstance pi = (ServerlessProcessInstance) process.createInstance();
pi.start();
assertThat(pi.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
Thread.sleep(5000);
assertThat(pi.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(pi.variables().toMap()).hasSize(2).containsKey("result").extracting("result").isEqualTo(new TextNode("pas"));
}
use of io.automatiko.engine.services.io.ClassPathResource in project automatiko-engine by automatiko-io.
the class SwitchStateWorkflowsTest method testSwitchWithDataConditions.
@Test
public void testSwitchWithDataConditions() 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/data-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_COMPLETED);
assertThat(pi.variables().toMap()).hasSize(2).containsKey("status").extracting("status").isEqualTo(new TextNode("accepted"));
data = new ObjectMapper().readTree("{\"applicant\" : {\"name\":\"Mary\", \"age\":10}}");
pi = (ServerlessProcessInstance) process.createInstance(ServerlessModel.from(data));
pi.start();
assertThat(pi.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(pi.variables().toMap()).hasSize(2).containsKey("status").extracting("status").isEqualTo(new TextNode("rejected"));
}
Aggregations