Search in sources :

Example 26 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class CreateDeploymentTest method shouldWriteWorkflowEvent.

@Test
public void shouldWriteWorkflowEvent() {
    // when
    final long deploymentKey = apiRule.topic().deploy(ClientApiRule.DEFAULT_TOPIC_NAME, WORKFLOW);
    // then
    final SubscribedEvent workflowEvent = apiRule.topic().receiveSingleEvent(workflowEvents("CREATED"));
    assertThat(workflowEvent.key()).isGreaterThanOrEqualTo(0L).isNotEqualTo(deploymentKey);
    assertThat(workflowEvent.event()).containsEntry(PROP_WORKFLOW_BPMN_PROCESS_ID, "process").containsEntry(PROP_WORKFLOW_VERSION, 1).containsEntry("deploymentKey", deploymentKey).containsEntry("bpmnXml", bpmnXml(WORKFLOW));
}
Also used : SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 27 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class IncidentTest method shouldCreateIncidentForOutputMappingFailure.

@Test
public void shouldCreateIncidentForOutputMappingFailure() {
    // given
    testClient.deploy(WORKFLOW_OUTPUT_MAPPING);
    // when
    final long workflowInstanceKey = testClient.createWorkflowInstance("process");
    testClient.completeTaskOfType("test", MSGPACK_PAYLOAD);
    // then
    final SubscribedEvent failureEvent = testClient.receiveSingleEvent(workflowInstanceEvents("ACTIVITY_COMPLETING"));
    final SubscribedEvent incidentEvent = testClient.receiveSingleEvent(incidentEvents("CREATED"));
    assertThat(incidentEvent.key()).isGreaterThan(0);
    assertThat(incidentEvent.event()).containsEntry("errorType", ErrorType.IO_MAPPING_ERROR.name()).containsEntry("errorMessage", "No data found for query $.foo.").containsEntry("failureEventPosition", failureEvent.position()).containsEntry("bpmnProcessId", "process").containsEntry("workflowInstanceKey", workflowInstanceKey).containsEntry("activityId", "failingTask").containsEntry("activityInstanceKey", failureEvent.key()).containsEntry("taskKey", -1);
}
Also used : SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 28 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class IncidentTest method shouldResolveIncidentAfterPreviousResolvingFailed.

@Test
public void shouldResolveIncidentAfterPreviousResolvingFailed() throws Exception {
    // given
    testClient.deploy(WORKFLOW_INPUT_MAPPING);
    final long workflowInstanceKey = testClient.createWorkflowInstance("process");
    final SubscribedEvent failureEvent = testClient.receiveSingleEvent(workflowInstanceEvents("ACTIVITY_READY"));
    final SubscribedEvent incidentEvent = testClient.receiveSingleEvent(incidentEvents("CREATED"));
    updatePayload(workflowInstanceKey, failureEvent.key(), MsgPackHelper.EMTPY_OBJECT);
    testClient.receiveSingleEvent(incidentEvents("RESOLVE_FAILED"));
    // when
    updatePayload(workflowInstanceKey, failureEvent.key(), PAYLOAD);
    // then
    final SubscribedEvent incidentResolvedEvent = testClient.receiveSingleEvent(incidentEvents("RESOLVED"));
    assertThat(incidentResolvedEvent.key()).isEqualTo(incidentEvent.key());
    assertThat(incidentResolvedEvent.event()).containsEntry("errorType", ErrorType.IO_MAPPING_ERROR.name()).containsEntry("errorMessage", "No data found for query $.foo.").containsEntry("bpmnProcessId", "process").containsEntry("workflowInstanceKey", workflowInstanceKey).containsEntry("activityId", "failingTask");
}
Also used : SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 29 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class IncidentTest method shouldResolveIncidentForInvalidResultOnInputMapping.

@Test
public void shouldResolveIncidentForInvalidResultOnInputMapping() throws Throwable {
    // given
    testClient.deploy(Bpmn.createExecutableWorkflow("process").startEvent().serviceTask("service", t -> t.taskType("external").input("$.string", "$")).done());
    // when
    final long workflowInstanceKey = testClient.createWorkflowInstance("process", MSGPACK_PAYLOAD);
    // then incident is created
    final SubscribedEvent failureEvent = testClient.receiveSingleEvent(workflowInstanceEvents("ACTIVITY_READY"));
    final SubscribedEvent incidentEvent = testClient.receiveSingleEvent(incidentEvents("CREATED"));
    // when
    updatePayload(workflowInstanceKey, failureEvent, "{'string':{'obj':'test'}}");
    // then
    final SubscribedEvent followUpEvent = testClient.receiveSingleEvent(workflowInstanceEvents("ACTIVITY_ACTIVATED"));
    final byte[] result = (byte[]) followUpEvent.event().get(PROP_PAYLOAD);
    assertThat(MSGPACK_MAPPER.readTree(result)).isEqualTo(JSON_MAPPER.readTree("{'obj':'test'}"));
    final SubscribedEvent incidentResolvedEvent = testClient.receiveSingleEvent(incidentEvents("RESOLVED"));
    assertThat(incidentResolvedEvent.key()).isEqualTo(incidentEvent.key());
    assertThat(incidentResolvedEvent.event()).containsEntry("errorType", ErrorType.IO_MAPPING_ERROR.name()).containsEntry("errorMessage", "Processing failed, since mapping will result in a non map object (json object).").containsEntry("bpmnProcessId", "process").containsEntry("workflowInstanceKey", workflowInstanceKey).containsEntry("activityId", "service").containsEntry("activityInstanceKey", followUpEvent.key()).containsEntry("taskKey", -1);
}
Also used : SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 30 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class IncidentTest method shouldCreateIncidentForInvalidResultOnOutputMapping.

@Test
public void shouldCreateIncidentForInvalidResultOnOutputMapping() throws Throwable {
    // given
    testClient.deploy(Bpmn.createExecutableWorkflow("process").startEvent().serviceTask("failingTask", t -> t.taskType("external").input("$.jsonObject", "$").output("$.testAttr", "$")).done());
    testClient.createWorkflowInstance("process", MSGPACK_PAYLOAD);
    // when
    testClient.completeTaskOfType("external", MSGPACK_MAPPER.writeValueAsBytes(JSON_MAPPER.readTree("{'testAttr':'test'}")));
    testClient.receiveSingleEvent(workflowInstanceEvents("ACTIVITY_ACTIVATED"));
    // then incident is created
    final SubscribedEvent incidentEvent = testClient.receiveSingleEvent(incidentEvents("CREATE"));
    assertThat(incidentEvent.key()).isGreaterThan(0);
    assertThat(incidentEvent.event()).containsEntry("errorType", ErrorType.IO_MAPPING_ERROR.name()).containsEntry("errorMessage", "Processing failed, since mapping will result in a non map object (json object).");
}
Also used : SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Aggregations

SubscribedEvent (io.zeebe.test.broker.protocol.clientapi.SubscribedEvent)57 Test (org.junit.Test)55 ExecuteCommandResponse (io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse)28 EmbeddedBrokerRule (io.zeebe.broker.test.EmbeddedBrokerRule)13 ClientApiRule (io.zeebe.test.broker.protocol.clientapi.ClientApiRule)13 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 Rule (org.junit.Rule)13 RuleChain (org.junit.rules.RuleChain)13 IOException (java.io.IOException)11 EventType (io.zeebe.protocol.clientapi.EventType)10 TestTopicClient (io.zeebe.test.broker.protocol.clientapi.TestTopicClient)10 HashMap (java.util.HashMap)10 Before (org.junit.Before)10 Bpmn (io.zeebe.model.bpmn.Bpmn)9 WorkflowDefinition (io.zeebe.model.bpmn.instance.WorkflowDefinition)9 TestTopicClient.taskEvents (io.zeebe.test.broker.protocol.clientapi.TestTopicClient.taskEvents)8 List (java.util.List)7 Map (java.util.Map)7 ErrorType (io.zeebe.broker.incident.data.ErrorType)6 JSON_MAPPER (io.zeebe.broker.test.MsgPackUtil.JSON_MAPPER)6