Search in sources :

Example 11 with NodeLeftCountDownProcessEventListener

use of io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener in project automatiko-engine by automatiko-io.

the class EmbeddedSubProcessTest method testEmbeddedSubprocessServiceProcessTaskWithRetry.

@Test
@Timeout(unit = TimeUnit.SECONDS, value = 10)
public void testEmbeddedSubprocessServiceProcessTaskWithRetry() throws Exception {
    Application app = generateCodeProcessesOnly("subprocess/EmbeddedSubprocessWihErrorRetry.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("Error happened", 1);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("subprocessRetry");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("name", "john");
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    listener.waitTillCompleted();
    assertThat(processInstance.startDate()).isNotNull();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(2).containsKeys("name", "ErrorData");
    assertThat(result.toMap().get("name")).isNotNull().isEqualTo("john");
    assertThat(result.toMap().get("ErrorData")).isNotNull().isInstanceOf(WorkItemExecutionError.class);
    assertThat(((WorkItemExecutionError) result.toMap().get("ErrorData")).getErrorCode()).isEqualTo("500");
}
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) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 12 with NodeLeftCountDownProcessEventListener

use of io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener in project automatiko-engine by automatiko-io.

the class EventSubProcessTest method testEventErrorSubProcessDefaultHander.

@Test
public void testEventErrorSubProcessDefaultHander() throws Exception {
    Application app = generateCodeProcessesOnly("event-subprocess/EventSubprocessErrorDefault.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("end-sub", 1);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("EventSubprocessError_1");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("name", "john");
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    listener.waitTillCompleted(5000);
    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 13 with NodeLeftCountDownProcessEventListener

use of io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener in project automatiko-engine by automatiko-io.

the class EventSubProcessTest method testEventTimerCycleISOSubProcess.

@Test
public void testEventTimerCycleISOSubProcess() throws Exception {
    Application app = generateCodeProcessesOnly("event-subprocess/EventSubprocessTimerCycle.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("start-sub", 2);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("EventSubprocessTimer_1");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    boolean completed = listener.waitTillCompleted(5000);
    assertThat(completed).isTrue();
    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 14 with NodeLeftCountDownProcessEventListener

use of io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener in project automatiko-engine by automatiko-io.

the class ServiceTaskTest method testBasicServiceProcessTaskWithRetryDefaultLimit.

@Test
@Timeout(unit = TimeUnit.SECONDS, value = 10)
public void testBasicServiceProcessTaskWithRetryDefaultLimit() throws Exception {
    Application app = generateCodeProcessesOnly("servicetask/ServiceProcessRetryDefLimit.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("Print error", 1);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("ServiceProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("s", "john");
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    listener.waitTillCompleted();
    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("john");
}
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) Timeout(org.junit.jupiter.api.Timeout)

Example 15 with NodeLeftCountDownProcessEventListener

use of io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener in project automatiko-engine by automatiko-io.

the class ServiceTaskTest method testBasicServiceProcessTaskWithRetryAbort.

@Test
@Timeout(unit = TimeUnit.SECONDS, value = 10000)
public void testBasicServiceProcessTaskWithRetryAbort() throws Exception {
    Application app = generateCodeProcessesOnly("servicetask/ServiceProcessRetry.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("EndProcess", 1);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("ServiceProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("s", "john");
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    listener.waitTillCompleted(1500);
    processInstance.abort();
    assertThat(processInstance.startDate()).isNotNull();
    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) Timeout(org.junit.jupiter.api.Timeout)

Aggregations

Application (io.automatiko.engine.api.Application)26 DefaultProcessEventListenerConfig (io.automatiko.engine.workflow.DefaultProcessEventListenerConfig)26 NodeLeftCountDownProcessEventListener (io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener)26 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)25 Test (org.junit.jupiter.api.Test)25 Model (io.automatiko.engine.api.Model)23 HashMap (java.util.HashMap)22 Timeout (org.junit.jupiter.api.Timeout)7 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)4 OffsetDateTime (java.time.OffsetDateTime)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 WorkItem (io.automatiko.engine.api.workflow.WorkItem)1 WorkItemExecutionError (io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1