Search in sources :

Example 11 with SubscribedEvent

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

the class IncidentTest method shouldCreateIncidentForInputMappingFailure.

@Test
public void shouldCreateIncidentForInputMappingFailure() {
    // given
    testClient.deploy(WORKFLOW_INPUT_MAPPING);
    // when
    final long workflowInstanceKey = testClient.createWorkflowInstance("process");
    // then
    final SubscribedEvent failureEvent = testClient.receiveSingleEvent(workflowInstanceEvents("ACTIVITY_READY"));
    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 12 with SubscribedEvent

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

the class CompleteTaskTest method shouldCompleteTask.

@Test
public void shouldCompleteTask() {
    // given
    createTask(TASK_TYPE);
    apiRule.openTaskSubscription(TASK_TYPE).await();
    final SubscribedEvent subscribedEvent = receiveSingleSubscribedEvent();
    // when
    final ExecuteCommandResponse response = completeTask(subscribedEvent.key(), subscribedEvent.event());
    // then
    final Map<String, Object> expectedEvent = new HashMap<>(subscribedEvent.event());
    expectedEvent.put("state", "COMPLETED");
    assertThat(response.getEvent()).containsAllEntriesOf(expectedEvent);
}
Also used : ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) HashMap(java.util.HashMap) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 13 with SubscribedEvent

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

the class CompleteTaskTest method shouldRejectCompletionIfPayloadIsInvalid.

@Test
public void shouldRejectCompletionIfPayloadIsInvalid() {
    // given
    createTask(TASK_TYPE);
    apiRule.openTaskSubscription(TASK_TYPE).await();
    final SubscribedEvent subscribedEvent = receiveSingleSubscribedEvent();
    final Map<String, Object> event = subscribedEvent.event();
    // positive fixnum, i.e. no object
    event.put("payload", new byte[] { 1 });
    // when
    final ExecuteCommandResponse response = completeTask(subscribedEvent.key(), event);
    // then
    assertThat(response.getEvent()).containsEntry("state", "COMPLETE_REJECTED");
}
Also used : ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 14 with SubscribedEvent

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

the class TaskLockExpirationTest method shouldNotExpireLockIfTaskCompleted.

@Test
public void shouldNotExpireLockIfTaskCompleted() throws InterruptedException {
    // given
    brokerRule.getClock().pinCurrentTime();
    final Duration lockTime = Duration.ofSeconds(60);
    final String taskType = "taskType";
    createTask(taskType);
    apiRule.openTaskSubscription(apiRule.getDefaultPartitionId(), taskType, lockTime.toMillis()).await();
    // => task is locked
    final SubscribedEvent lockedTask = apiRule.subscribedEvents().findFirst().get();
    completeTask(lockedTask);
    // when
    brokerRule.getClock().addTime(lockTime.plus(Duration.ofSeconds(1)));
    // then
    assertNoMoreTaskReceived();
}
Also used : Duration(java.time.Duration) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 15 with SubscribedEvent

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

the class CreateDeploymentTest method shouldCreateDeploymentWithYamlWorfklow.

@Test
public void shouldCreateDeploymentWithYamlWorfklow() throws Exception {
    // given
    final File yamlFile = new File(getClass().getResource("/workflows/simple-workflow.yaml").toURI());
    final String yamlWorkflow = Files.contentOf(yamlFile, UTF_8);
    // when
    final ExecuteCommandResponse resp = apiRule.topic().deployWithResponse(ClientApiRule.DEFAULT_TOPIC_NAME, yamlWorkflow.getBytes(UTF_8), ResourceType.YAML_WORKFLOW.name(), "simple-workflow.yaml");
    // then
    assertThat(resp.getEvent()).containsEntry(PROP_STATE, "CREATED");
    final SubscribedEvent workflowEvent = apiRule.topic().receiveSingleEvent(workflowEvents("CREATED"));
    assertThat(workflowEvent.event()).containsEntry(PROP_WORKFLOW_BPMN_PROCESS_ID, "yaml-workflow").containsEntry("deploymentKey", resp.key()).containsEntry("bpmnXml", bpmnXml(Bpmn.readFromYamlFile(yamlFile)));
}
Also used : ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) File(java.io.File) 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