Search in sources :

Example 1 with ProcessInstanceDataEvent

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

the class PublishEventTest method assertProcessInstanceEventWithParentId.

protected ProcessInstanceEventBody assertProcessInstanceEventWithParentId(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) {
        assertThat(body.getEndDate()).isNull();
    } else {
        assertThat(body.getEndDate()).isNotNull();
    }
    assertThat(body.getParentInstanceId()).isNotNull();
    assertThat(body.getRootInstanceId()).isNotNull();
    assertThat(body.getProcessId()).isEqualTo(processId);
    assertThat(body.getProcessName()).isEqualTo(processName);
    assertThat(body.getState()).isEqualTo(state);
    return body;
}
Also used : ProcessInstanceEventBody(io.automatiko.engine.services.event.impl.ProcessInstanceEventBody) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent)

Example 2 with ProcessInstanceDataEvent

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

the class PublishEventTest method testProcessWithMilestoneEvents.

@Test
public void testProcessWithMilestoneEvents() throws Exception {
    Application app = generateCodeProcessesOnly("cases/milestones/SimpleMilestone.bpmn");
    assertThat(app).isNotNull();
    TestEventPublisher publisher = new TestEventPublisher();
    app.unitOfWorkManager().eventManager().setService("http://myhost");
    app.unitOfWorkManager().eventManager().addPublisher(publisher);
    UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    Process<? extends Model> p = app.processes().processById("TestCase.SimpleMilestone_1_0");
    ProcessInstance<?> processInstance = p.createInstance(p.createModel());
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    uow.end();
    List<DataEvent<?>> events = publisher.extract();
    assertThat(events).isNotNull().hasSize(1);
    DataEvent<?> event = events.get(0);
    assertThat(event).isInstanceOf(ProcessInstanceDataEvent.class);
    ProcessInstanceDataEvent processDataEvent = (ProcessInstanceDataEvent) event;
    assertThat(processDataEvent.getSource()).isEqualTo("http://myhost/SimpleMilestone");
    Set<MilestoneEventBody> milestones = ((ProcessInstanceDataEvent) event).getData().getMilestones();
    assertThat(milestones).hasSize(2).extracting(e -> e.getName(), e -> e.getStatus()).containsExactlyInAnyOrder(tuple("AutoStartMilestone", Status.COMPLETED.name()), tuple("SimpleMilestone", Status.COMPLETED.name()));
}
Also used : AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) UserTaskInstanceEventBody(io.automatiko.engine.services.event.impl.UserTaskInstanceEventBody) MilestoneEventBody(io.automatiko.engine.services.event.impl.MilestoneEventBody) SecurityPolicy(io.automatiko.engine.api.auth.SecurityPolicy) ProcessInstanceEventBody(io.automatiko.engine.services.event.impl.ProcessInstanceEventBody) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ProcessErrors(io.automatiko.engine.api.workflow.ProcessErrors) HashMap(java.util.HashMap) DataEvent(io.automatiko.engine.api.event.DataEvent) ArrayList(java.util.ArrayList) Application(io.automatiko.engine.api.Application) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) Map(java.util.Map) StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) Process(io.automatiko.engine.api.workflow.Process) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EventPublisher(io.automatiko.engine.api.event.EventPublisher) Model(io.automatiko.engine.api.Model) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Collection(java.util.Collection) Status(io.automatiko.engine.api.workflow.flexible.ItemDescription.Status) Set(java.util.Set) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) Test(org.junit.jupiter.api.Test) List(java.util.List) WorkItem(io.automatiko.engine.api.workflow.WorkItem) UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) MilestoneEventBody(io.automatiko.engine.services.event.impl.MilestoneEventBody) DataEvent(io.automatiko.engine.api.event.DataEvent) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 3 with ProcessInstanceDataEvent

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

the class VerificationTest method testProcessParentsSuccessful.

@Test
public void testProcessParentsSuccessful() {
    String addPayload = "{\"name\" : \"john\"}";
    given().contentType(ContentType.JSON).accept(ContentType.JSON).body(addPayload).when().post("/parents").then().statusCode(200).body("id", notNullValue(), "name", equalTo("john"));
    List<DataEvent<?>> received = publisher.events();
    assertEquals(4, received.size());
    ProcessInstanceDataEvent piEvent = (ProcessInstanceDataEvent) received.stream().filter(pi -> ((ProcessInstanceDataEvent) pi).getData().getState().equals(ProcessInstance.STATE_COMPLETED) && ((ProcessInstanceDataEvent) pi).getData().getProcessId().equals("parents")).findFirst().get();
    assertEquals("Here is async name", piEvent.getData().getVariables().get("name"));
    given().accept(ContentType.JSON).when().get("/parents").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 4 with ProcessInstanceDataEvent

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

the class VerificationTest method testProcessAsyncCallSuccessful.

@Test
public void testProcessAsyncCallSuccessful() {
    String addPayload = "{\"name\" : \"john\"}";
    given().contentType(ContentType.JSON).accept(ContentType.JSON).body(addPayload).when().post("/async").then().statusCode(200).body("id", notNullValue(), "name", equalTo("john"));
    List<DataEvent<?>> received = publisher.events();
    assertEquals(2, received.size());
    ProcessInstanceDataEvent piEvent = (ProcessInstanceDataEvent) received.stream().filter(pi -> ((ProcessInstanceDataEvent) pi).getData().getState().equals(ProcessInstance.STATE_COMPLETED)).findFirst().get();
    assertEquals("Here is async name", piEvent.getData().getVariables().get("name"));
    given().accept(ContentType.JSON).when().get("/async").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 5 with ProcessInstanceDataEvent

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

the class VerificationTest method testProcessParentsFailure.

@Test
public void testProcessParentsFailure() {
    String addPayload = "{\"name\" : null}";
    given().contentType(ContentType.JSON).accept(ContentType.JSON).body(addPayload).when().post("/parents").then().statusCode(200).body("id", notNullValue(), "name", nullValue());
    List<DataEvent<?>> received = publisher.events();
    assertEquals(4, received.size());
    ProcessInstanceDataEvent piEvent = (ProcessInstanceDataEvent) received.stream().filter(pi -> ((ProcessInstanceDataEvent) pi).getData().getState().equals(ProcessInstance.STATE_COMPLETED) && ((ProcessInstanceDataEvent) pi).getData().getProcessId().equals("parents")).findFirst().get();
    assertEquals(null, piEvent.getData().getVariables().get("name"));
    given().accept(ContentType.JSON).when().get("/parents").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)

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