Search in sources :

Example 36 with Application

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!!");
}
Also used : HashMap(java.util.HashMap) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 37 with Application

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);
}
Also used : Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) EventDescription(io.automatiko.engine.api.workflow.EventDescription) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 38 with Application

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);
}
Also used : StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) AccessDeniedException(io.automatiko.engine.api.auth.AccessDeniedException) HashMap(java.util.HashMap) TrustedIdentityProvider(io.automatiko.engine.api.auth.TrustedIdentityProvider) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 39 with Application

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);
}
Also used : NodeLeftCountDownProcessEventListener(io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener) HashMap(java.util.HashMap) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 40 with Application

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);
}
Also used : StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) AccessDeniedException(io.automatiko.engine.api.auth.AccessDeniedException) HashMap(java.util.HashMap) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Aggregations

Application (io.automatiko.engine.api.Application)157 Model (io.automatiko.engine.api.Model)146 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)143 Test (org.junit.jupiter.api.Test)143 HashMap (java.util.HashMap)126 WorkItem (io.automatiko.engine.api.workflow.WorkItem)46 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)29 DefaultProcessEventListenerConfig (io.automatiko.engine.workflow.DefaultProcessEventListenerConfig)27 NodeLeftCountDownProcessEventListener (io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener)27 ArrayList (java.util.ArrayList)17 List (java.util.List)16 StaticIdentityProvider (io.automatiko.engine.services.identity.StaticIdentityProvider)14 HumanTaskTransition (io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition)14 Process (io.automatiko.engine.api.workflow.Process)13 Map (java.util.Map)12 Person (io.automatiko.engine.codegen.data.Person)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 UnitOfWork (io.automatiko.engine.api.uow.UnitOfWork)9 SecurityPolicy (io.automatiko.engine.api.auth.SecurityPolicy)8