Search in sources :

Example 6 with ProcessInstanceDataEvent

use of io.automatiko.engine.services.event.ProcessInstanceDataEvent in project automatiko-engine by automatiko-io.

the class VerificationTest method testProcessParallelSuccessful.

@Test
public void testProcessParallelSuccessful() throws InterruptedException {
    String addPayload = "{}";
    given().contentType(ContentType.JSON).accept(ContentType.JSON).body(addPayload).when().post("/parallel").then().statusCode(200).body("id", notNullValue());
    long elapsed = 3000;
    while (elapsed >= 0) {
        elapsed -= 1000;
        Thread.sleep(1000);
        int size = given().accept(ContentType.JSON).when().get("/parallel").then().statusCode(200).extract().path("$.size()");
        if (size == 0) {
            break;
        }
    }
    List<DataEvent<?>> received = publisher.events();
    assertEquals(5, received.size());
    ProcessInstanceDataEvent piEvent = (ProcessInstanceDataEvent) received.stream().filter(pi -> ((ProcessInstanceDataEvent) pi).getData().getState().equals(ProcessInstance.STATE_COMPLETED)).findFirst().get();
    assertEquals("fallback name", piEvent.getData().getVariables().get("errorInfo"));
    given().accept(ContentType.JSON).when().get("/parallel").then().statusCode(200).body("$.size()", is(0));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) BeforeEach(org.junit.jupiter.api.BeforeEach) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) ContentType(io.restassured.http.ContentType) DataEvent(io.automatiko.engine.api.event.DataEvent) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Inject(javax.inject.Inject) Test(org.junit.jupiter.api.Test) List(java.util.List) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) RestAssured.given(io.restassured.RestAssured.given) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) DataEvent(io.automatiko.engine.api.event.DataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 7 with ProcessInstanceDataEvent

use of io.automatiko.engine.services.event.ProcessInstanceDataEvent in project automatiko-engine by automatiko-io.

the class GraphQLProcessSubscriptionEventPublisher method process.

@Override
public void process(DataEvent<?> event) {
    if (processId == null || mapper == null) {
        return;
    }
    if (event instanceof ProcessInstanceDataEvent) {
        ProcessInstanceDataEvent piEvent = (ProcessInstanceDataEvent) event;
        ProcessInstance<?> instance = piEvent.getData().sourceInstance();
        if (instance.process().id().equals(processId)) {
            if (instance.status() == ProcessInstance.STATE_COMPLETED) {
                completedProcessor.onNext(mapper.apply(instance), piEvent.getData().getVisibleTo());
            } else if (instance.status() == ProcessInstance.STATE_ABORTED) {
                abortedProcessor.onNext(mapper.apply(instance), piEvent.getData().getVisibleTo());
            } else if (instance.status() == ProcessInstance.STATE_ERROR) {
                inErrorProcessor.onNext(mapper.apply(instance), piEvent.getData().getVisibleTo());
            } else {
                changedProcessor.onNext(mapper.apply(instance), piEvent.getData().getVisibleTo());
            }
        }
    }
}
Also used : ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent)

Example 8 with ProcessInstanceDataEvent

use of io.automatiko.engine.services.event.ProcessInstanceDataEvent in project automatiko-engine by automatiko-io.

the class PublishEventTest method assertProcessInstanceEvent.

/*
     * Helper methods
     */
protected ProcessInstanceEventBody assertProcessInstanceEvent(DataEvent<?> event, String processId, String processName, Integer state) {
    assertThat(event).isInstanceOf(ProcessInstanceDataEvent.class);
    ProcessInstanceEventBody body = ((ProcessInstanceDataEvent) event).getData();
    assertThat(body).isNotNull();
    assertThat(body.getId()).isNotNull();
    assertThat(body.getStartDate()).isNotNull();
    if (state == ProcessInstance.STATE_ACTIVE || state == ProcessInstance.STATE_ERROR) {
        assertThat(body.getEndDate()).isNull();
    } else {
        assertThat(body.getEndDate()).isNotNull();
    }
    assertThat(body.getParentInstanceId()).isNull();
    assertThat(body.getRootInstanceId()).isNull();
    assertThat(body.getProcessId()).isEqualTo(processId);
    assertThat(body.getProcessName()).isEqualTo(processName);
    assertThat(body.getState()).isEqualTo(state);
    assertThat(event.getSource()).isEqualTo("http://myhost/" + processId);
    assertThat(event.getTime()).doesNotContain("[");
    return body;
}
Also used : ProcessInstanceEventBody(io.automatiko.engine.services.event.impl.ProcessInstanceEventBody) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent)

Example 9 with ProcessInstanceDataEvent

use of io.automatiko.engine.services.event.ProcessInstanceDataEvent in project automatiko-engine by automatiko-io.

the class MockEventPublisher method waitForNodeEntered.

public boolean waitForNodeEntered(String nodeName, long elapsed) throws InterruptedException {
    boolean found = false;
    while (elapsed >= 0) {
        elapsed -= 1000;
        Thread.sleep(1000);
        for (DataEvent<?> event : events) {
            ProcessInstanceDataEvent piEvent = (ProcessInstanceDataEvent) event;
            found = piEvent.getData().getNodeInstances().stream().anyMatch(ni -> ni.getNodeName().equals(nodeName) && ni.getLeaveTime() == null);
            if (found) {
                break;
            }
        }
        if (found) {
            break;
        }
    }
    return found;
}
Also used : List(java.util.List) EventPublisher(io.automatiko.engine.api.event.EventPublisher) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) NodeInstanceEventBody(io.automatiko.engine.services.event.impl.NodeInstanceEventBody) IfBuildProfile(io.quarkus.arc.profile.IfBuildProfile) Collection(java.util.Collection) ApplicationScoped(javax.enterprise.context.ApplicationScoped) DataEvent(io.automatiko.engine.api.event.DataEvent) ArrayList(java.util.ArrayList) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent)

Example 10 with ProcessInstanceDataEvent

use of io.automatiko.engine.services.event.ProcessInstanceDataEvent in project automatiko-engine by automatiko-io.

the class MockEventPublisher method waitForNodeCompleted.

public boolean waitForNodeCompleted(String nodeName, long elapsed) throws InterruptedException {
    boolean found = false;
    while (elapsed >= 0) {
        elapsed -= 1000;
        Thread.sleep(1000);
        for (DataEvent<?> event : events) {
            ProcessInstanceDataEvent piEvent = (ProcessInstanceDataEvent) event;
            found = piEvent.getData().getNodeInstances().stream().map(ni -> log(ni)).anyMatch(ni -> ni.getNodeName().equals(nodeName) && ni.getLeaveTime() != null);
            if (found) {
                break;
            }
        }
        if (found) {
            break;
        }
    }
    return found;
}
Also used : List(java.util.List) EventPublisher(io.automatiko.engine.api.event.EventPublisher) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) NodeInstanceEventBody(io.automatiko.engine.services.event.impl.NodeInstanceEventBody) IfBuildProfile(io.quarkus.arc.profile.IfBuildProfile) Collection(java.util.Collection) ApplicationScoped(javax.enterprise.context.ApplicationScoped) DataEvent(io.automatiko.engine.api.event.DataEvent) ArrayList(java.util.ArrayList) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent)

Aggregations

ProcessInstanceDataEvent (io.automatiko.engine.services.event.ProcessInstanceDataEvent)14 DataEvent (io.automatiko.engine.api.event.DataEvent)9 List (java.util.List)9 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)6 QuarkusTest (io.quarkus.test.junit.QuarkusTest)5 RestAssured.given (io.restassured.RestAssured.given)5 ContentType (io.restassured.http.ContentType)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)5 Test (org.junit.jupiter.api.Test)5 UserTaskInstanceDataEvent (io.automatiko.engine.services.event.UserTaskInstanceDataEvent)4 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 Inject (javax.inject.Inject)4 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)4 CoreMatchers.is (org.hamcrest.CoreMatchers.is)4 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)4 CoreMatchers.nullValue (org.hamcrest.CoreMatchers.nullValue)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 EventPublisher (io.automatiko.engine.api.event.EventPublisher)3 NodeInstanceEventBody (io.automatiko.engine.services.event.impl.NodeInstanceEventBody)3