Search in sources :

Example 26 with Application

use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.

the class TimerEventTest method testStartTimerEventTimeCycleCron.

@Test
public void testStartTimerEventTimeCycleCron() throws Exception {
    Application app = generateCodeProcessesOnly("timer/StartTimerCycleCron.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("timer fired", 2);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("defaultPackage.TimerProcess");
    // activate to schedule timers
    p.activate();
    boolean completed = listener.waitTillCompleted(5000);
    assertThat(completed).isTrue();
    Collection<?> instances = p.instances().values(1, 10);
    assertThat(instances).hasSize(2);
    ProcessInstance<?> processInstance = (ProcessInstance<?>) instances.iterator().next();
    assertThat(processInstance).isNotNull();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    // deactivate to cancel timer, so there should be no more timers fired
    p.deactivate();
    // reset the listener to make sure nothing more is triggered
    listener.reset(1);
    completed = listener.waitTillCompleted(3000);
    // same amount of instances should be active as before deactivation
    instances = p.instances().values(1, 10);
    // clean up by aborting all instances
    instances.forEach(i -> ((ProcessInstance<?>) i).abort());
    instances = p.instances().values(1, 10);
    assertThat(instances).hasSize(0);
}
Also used : NodeLeftCountDownProcessEventListener(io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 27 with Application

use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.

the class TimerEventTest method testIntermediateCycleTimerEvent.

@Test
public void testIntermediateCycleTimerEvent() throws Exception {
    Application app = generateCodeProcessesOnly("timer/IntermediateCatchEventTimerCycleISO.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();
    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 28 with Application

use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.

the class TimerEventTest method testBoundaryDurationTimerEventOnSubprocess.

@Test
public void testBoundaryDurationTimerEventOnSubprocess() throws Exception {
    Application app = generateCodeProcessesOnly("timer/TimerBoundaryEventDurationISO.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("TimerBoundaryEvent");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    boolean completed = listener.waitTillCompleted(5000);
    assertThat(completed).isTrue();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
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 29 with Application

use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.

the class TimerEventTest method testBoundaryDateTimerEventOnTask.

@Test
public void testBoundaryDateTimerEventOnTask() throws Exception {
    Application app = generateCodeProcessesOnly("timer/TimerBoundaryEventDateISOOnTask.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("TimerBoundaryEvent");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    OffsetDateTime plusTwoSeconds = OffsetDateTime.now().plusSeconds(2);
    parameters.put("date", plusTwoSeconds.toString());
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    boolean completed = listener.waitTillCompleted(5000);
    assertThat(completed).isTrue();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : NodeLeftCountDownProcessEventListener(io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener) HashMap(java.util.HashMap) OffsetDateTime(java.time.OffsetDateTime) 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 30 with Application

use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.

the class ServiceTaskTest method testServiceProcessDifferentOperationsTaskFromAnotherNode.

@Test
public void testServiceProcessDifferentOperationsTaskFromAnotherNode() throws Exception {
    Application app = generateCodeProcessesOnly("servicetask/ServiceProcessDifferentOperations.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("ServiceProcessDifferentOperations_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.startFrom("_A1EE8114-BF7B-4DAF-ABD7-62EEDCFAEFD4");
    assertThat(processInstance.startDate()).isNotNull();
    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 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)

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