use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.
the class PublishEventTest method testBasicUserTaskProcessWithTags.
@Test
public void testBasicUserTaskProcessWithTags() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcessTags.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("UserTasksProcess");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
parameters.put("name", "john");
m.fromMap(parameters);
TestEventPublisher publisher = new TestEventPublisher();
app.unitOfWorkManager().eventManager().setService("http://myhost");
app.unitOfWorkManager().eventManager().addPublisher(publisher);
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<DataEvent<?>> events = publisher.extract();
assertThat(events).isNotNull().hasSize(2);
ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
assertThat(body.getTags()).hasSize(2).contains("important", "john");
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "HumanTaskNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
// human task is active
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
// thus null for leave
// time
assertUserTaskInstanceEvent(events.get(1), "First Task", null, "1", "Ready", "UserTasksProcess");
List<WorkItem> workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
assertEquals(1, workItems.size());
assertEquals("FirstTask", workItems.get(0).getName());
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
events = publisher.extract();
assertThat(events).isNotNull().hasSize(3);
body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "HumanTaskNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
// human task is active
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
// thus null for leave
// time
assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Ready", "UserTasksProcess");
assertUserTaskInstanceEvent(events.get(2), "First Task", null, "1", "Completed", "UserTasksProcess");
workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
assertEquals(1, workItems.size());
assertEquals("SecondTask", workItems.get(0).getName());
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
events = publisher.extract();
assertThat(events).isNotNull().hasSize(2);
body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 2);
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "EndNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").allMatch(v -> v != null);
assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Completed", "UserTasksProcess");
}
use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.
the class PublishEventTest method testBasicUserTaskProcessWithSensitiveData.
@Test
public void testBasicUserTaskProcessWithSensitiveData() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcessSensitive.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("UserTasksProcess");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
parameters.put("name", "john");
parameters.put("ssn", "123-456");
m.fromMap(parameters);
TestEventPublisher publisher = new TestEventPublisher();
app.unitOfWorkManager().eventManager().setService("http://myhost");
app.unitOfWorkManager().eventManager().addPublisher(publisher);
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<DataEvent<?>> events = publisher.extract();
assertThat(events).isNotNull().hasSize(2);
ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
assertThat(body.getTags()).hasSize(0);
assertThat(body.getVariables()).hasSize(1).containsEntry("name", "john");
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "HumanTaskNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
// human task is active
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
// thus null for leave
// time
assertUserTaskInstanceEvent(events.get(1), "First Task", null, "1", "Ready", "UserTasksProcess");
List<WorkItem> workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
assertEquals(1, workItems.size());
assertEquals("FirstTask", workItems.get(0).getName());
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
events = publisher.extract();
assertThat(events).isNotNull().hasSize(3);
body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "HumanTaskNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
// human task is active
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
// thus null for leave
// time
assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Ready", "UserTasksProcess");
assertUserTaskInstanceEvent(events.get(2), "First Task", null, "1", "Completed", "UserTasksProcess");
workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
assertEquals(1, workItems.size());
assertEquals("SecondTask", workItems.get(0).getName());
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
events = publisher.extract();
assertThat(events).isNotNull().hasSize(2);
body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 2);
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "EndNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").allMatch(v -> v != null);
assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Completed", "UserTasksProcess");
}
use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.
the class PublishEventTest method testBasicUserTaskProcess.
@Test
public void testBasicUserTaskProcess() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("UserTasksProcess");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
TestEventPublisher publisher = new TestEventPublisher();
app.unitOfWorkManager().eventManager().setService("http://myhost");
app.unitOfWorkManager().eventManager().addPublisher(publisher);
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<DataEvent<?>> events = publisher.extract();
assertThat(events).isNotNull().hasSize(2);
ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "HumanTaskNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
// human task is active
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
// thus null for leave
// time
assertUserTaskInstanceEvent(events.get(1), "First Task", null, "1", "Ready", "UserTasksProcess");
List<WorkItem> workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
assertEquals(1, workItems.size());
assertEquals("FirstTask", workItems.get(0).getName());
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
events = publisher.extract();
assertThat(events).isNotNull().hasSize(3);
body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "HumanTaskNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
// human task is active
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
// thus null for leave
// time
assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Ready", "UserTasksProcess");
assertUserTaskInstanceEvent(events.get(2), "First Task", null, "1", "Completed", "UserTasksProcess");
workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
assertEquals(1, workItems.size());
assertEquals("SecondTask", workItems.get(0).getName());
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
events = publisher.extract();
assertThat(events).isNotNull().hasSize(2);
body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 2);
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "EndNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").allMatch(v -> v != null);
assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Completed", "UserTasksProcess");
}
use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.
the class PublishEventTest method testServiceTaskProcessWithError.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testServiceTaskProcessWithError() throws Exception {
Application app = generateCodeProcessesOnly("servicetask/ServiceProcessDifferentOperations.bpmn2");
assertThat(app).isNotNull();
TestEventPublisher publisher = new TestEventPublisher();
app.unitOfWorkManager().eventManager().setService("http://myhost");
app.unitOfWorkManager().eventManager().addPublisher(publisher);
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
Process<? extends Model> p = app.processes().processById("ServiceProcessDifferentOperations_1_0");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance processInstance = p.createInstance(m);
processInstance.start();
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ERROR);
List<DataEvent<?>> events = publisher.extract();
assertThat(events).isNotNull().hasSize(1);
ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "ServiceProcessDifferentOperations", "Service Process", 5);
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "WorkItemNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
// human task is active
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
// thus null for leave
// time
assertThat(body.getErrors()).hasSize(1);
assertThat(body.getErrors().get(0).getNodeDefinitionId()).isEqualTo("_38E04E27-3CCA-47F9-927B-E37DC4B8CE25");
parameters.put("s", "john");
m.fromMap(parameters);
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
processInstance.updateVariables(m);
uow.end();
events = publisher.extract();
assertThat(events).isNotNull().hasSize(1);
body = assertProcessInstanceEvent(events.get(0), "ServiceProcessDifferentOperations", "Service Process", 5);
assertThat(body.getErrors()).hasSize(1);
assertThat(body.getErrors().get(0).getNodeDefinitionId()).isEqualTo("_38E04E27-3CCA-47F9-927B-E37DC4B8CE25");
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
if (processInstance.errors().isPresent()) {
((ProcessErrors) processInstance.errors().get()).retrigger();
}
uow.end();
events = publisher.extract();
assertThat(events).isNotNull().hasSize(1);
body = assertProcessInstanceEvent(events.get(0), "ServiceProcessDifferentOperations", "Service Process", 2);
assertThat(body.getErrors()).isEmpty();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(1).containsKeys("s");
assertThat(result.toMap().get("s")).isNotNull().isEqualTo("Goodbye Hello john!!");
}
use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowTest method testSimpleIncrementtWorkflow.
@ParameterizedTest
@ValueSource(strings = { "serverless/simple-increment.sw.json" })
public void testSimpleIncrementtWorkflow(String processLocation) throws Exception {
Application app = generateCodeProcessesOnly(processLocation);
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("helloworld_1_0");
Model m = p.createModel();
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).containsKeys("count");
JsonNode dataOut = (JsonNode) result.toMap().get("count");
assertThat(dataOut.intValue()).isEqualTo(11);
}
Aggregations