use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.
the class ServiceTaskTest method testServiceProcessSameOperationsTask.
@Test
public void testServiceProcessSameOperationsTask() throws Exception {
Application app = generateCodeProcessesOnly("servicetask/ServiceProcessSameOperations.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("ServiceProcessSameOperations_1_0");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
parameters.put("s", "john");
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
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("Hello Hello john!!");
}
use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.
the class SignalEventTest method testBoundarySignalEventWithData.
@Test
public void testBoundarySignalEventWithData() throws Exception {
Application app = generateCode(Collections.singletonList("signalevent/BoundarySignalEventOnTask.bpmn2"), Collections.singletonList("ruletask/BusinessRuleTask.drl"));
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("BoundarySignalOnTask");
Model m = p.createModel();
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
Set<EventDescription<?>> eventDescriptions = processInstance.events();
assertThat(eventDescriptions).hasSize(2).extracting("event").contains("MySignal", "workItemCompleted");
assertThat(eventDescriptions).extracting("eventType").contains("signal", "workItem");
assertThat(eventDescriptions).extracting("dataType").hasAtLeastOneElementOfType(GroupedNamedDataType.class);
assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.id());
processInstance.send(Sig.of("MySignal", "test"));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(1).containsKey("x");
assertThat(result.toMap().get("x")).isEqualTo("test");
assertThat(p.instances().values(1, 10)).hasSize(0);
}
use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.
the class AccessPolicyTest method testAssignInitiatorFromIdentity.
@Test
public void testAssignInitiatorFromIdentity() throws Exception {
IdentityProvider.set(securityPolicy.value());
Application app = generateCodeProcessesOnly("access-policy/UserTasksProcessWithAccessPolicy.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);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.initiator()).hasValue("john");
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
// set identity to other user than initiator or any of the assigned human task actors
IdentityProvider.set(new StaticIdentityProvider("mike"));
// not initiator so can't
// update process instance model
assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> processInstance.updateVariables(null));
// abort process instance
assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> processInstance.abort());
// signal process instance
assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> processInstance.send(Sig.of("test")));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
// set identity to one of the assigned human task actors but other than initiator
IdentityProvider.set(new StaticIdentityProvider("mary"));
processInstance.send(Sig.of("test"));
// set identity to trusted identity to verify system actions can go through
IdentityProvider.set(new TrustedIdentityProvider("System<test>"));
processInstance.send(Sig.of("test"));
// go back to initiator as identity that is allowed to perform operations
IdentityProvider.set(securityPolicy.value());
processInstance.abort();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.
the class AccessPolicyTest method testIntermediateCycleTimerEvent.
@Test
public void testIntermediateCycleTimerEvent() throws Exception {
IdentityProvider.set(securityPolicy.value());
Application app = generateCodeProcessesOnly("access-policy/IntermediateCatchEventTimerCycleISOAccessPolicy.bpmn2");
assertThat(app).isNotNull();
NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("timer", 3);
((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
Process<? extends Model> p = app.processes().processById("IntermediateCatchEvent");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.initiator()).hasValue("john");
boolean completed = listener.waitTillCompleted(5000);
assertThat(completed).isTrue();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
processInstance.abort();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.
the class AccessPolicyTest method testAssignInitiatorFromVariable.
@Test
public void testAssignInitiatorFromVariable() throws Exception {
Application app = generateCodeProcessesOnly("access-policy/UserTasksProcessWithAccessPolicyVar.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);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
IdentityProvider.set(securityPolicy.value());
assertThat(processInstance.initiator()).hasValue("john");
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
// set identity to other user than initiator or any of the assigned human task actors
IdentityProvider.set(new StaticIdentityProvider("mike"));
// not initiator so can't
// update process instance model
assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> processInstance.updateVariables(null));
// abort process instance
assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> processInstance.abort());
// signal process instance
assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> processInstance.send(Sig.of("test")));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
// set identity to one of the assigned human task actors but other than initiator
IdentityProvider.set(new StaticIdentityProvider("mary"));
processInstance.send(Sig.of("test"));
// go back to initiator as identity that is allowed to perform operations
IdentityProvider.set(securityPolicy.value());
processInstance.abort();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
Aggregations