Search in sources :

Example 16 with TaskEventImpl

use of io.zeebe.client.event.impl.TaskEventImpl in project zeebe by zeebe-io.

the class CompleteTaskTest method shouldThrowExceptionOnRejection.

@Test
public void shouldThrowExceptionOnRejection() {
    // given
    final TaskEventImpl baseEvent = Events.exampleTask();
    brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "COMPLETE").respondWith().key(r -> r.key()).event().allOf((r) -> r.getCommand()).put("state", "COMPLETE_REJECTED").done().register();
    final String updatedPayload = "{\"fruit\":\"cherry\"}";
    // then
    exception.expect(ClientCommandRejectedException.class);
    exception.expectMessage("Command for event with key 79 was rejected by broker (COMPLETE_REJECTED)");
    // when
    clientRule.tasks().complete(baseEvent).payload(updatedPayload).execute();
}
Also used : TasksClient(io.zeebe.client.TasksClient) TaskEvent(io.zeebe.client.event.TaskEvent) Events(io.zeebe.client.util.Events) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Assertions.entry(org.assertj.core.api.Assertions.entry) StandardCharsets(java.nio.charset.StandardCharsets) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) RuleChain(org.junit.rules.RuleChain) Rule(org.junit.Rule) ClientRule(io.zeebe.client.util.ClientRule) ByteArrayInputStream(java.io.ByteArrayInputStream) EventType(io.zeebe.protocol.clientapi.EventType) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) ExpectedException(org.junit.rules.ExpectedException) MsgPackConverter(io.zeebe.client.impl.data.MsgPackConverter) Before(org.junit.Before) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) Test(org.junit.Test)

Example 17 with TaskEventImpl

use of io.zeebe.client.event.impl.TaskEventImpl in project zeebe by zeebe-io.

the class CompleteTaskTest method shouldClearPayload.

@Test
public void shouldClearPayload() {
    // given
    final TaskEventImpl baseEvent = Events.exampleTask();
    brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "COMPLETE").respondWith().key(123).event().allOf((r) -> r.getCommand()).put("state", "COMPLETED").done().register();
    // when
    clientRule.tasks().complete(baseEvent).withoutPayload().execute();
    // then
    final ExecuteCommandRequest request = brokerRule.getReceivedCommandRequests().get(0);
    assertThat(request.getCommand()).doesNotContainKey("payload");
}
Also used : TasksClient(io.zeebe.client.TasksClient) TaskEvent(io.zeebe.client.event.TaskEvent) Events(io.zeebe.client.util.Events) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Assertions.entry(org.assertj.core.api.Assertions.entry) StandardCharsets(java.nio.charset.StandardCharsets) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) RuleChain(org.junit.rules.RuleChain) Rule(org.junit.Rule) ClientRule(io.zeebe.client.util.ClientRule) ByteArrayInputStream(java.io.ByteArrayInputStream) EventType(io.zeebe.protocol.clientapi.EventType) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) ExpectedException(org.junit.rules.ExpectedException) MsgPackConverter(io.zeebe.client.impl.data.MsgPackConverter) Before(org.junit.Before) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) Test(org.junit.Test)

Example 18 with TaskEventImpl

use of io.zeebe.client.event.impl.TaskEventImpl in project zeebe by zeebe-io.

the class CompleteTaskTest method shouldSetPayloadAsStream.

@Test
public void shouldSetPayloadAsStream() {
    // given
    final TaskEventImpl baseEvent = Events.exampleTask();
    brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "COMPLETE").respondWith().key(123).event().allOf((r) -> r.getCommand()).put("state", "COMPLETED").done().register();
    final String updatedPayload = "{\"fruit\":\"cherry\"}";
    final ByteArrayInputStream inStream = new ByteArrayInputStream(updatedPayload.getBytes(StandardCharsets.UTF_8));
    // when
    clientRule.tasks().complete(baseEvent).payload(inStream).execute();
    // then
    final ExecuteCommandRequest request = brokerRule.getReceivedCommandRequests().get(0);
    assertThat(request.getCommand()).contains(entry("payload", converter.convertToMsgPack(updatedPayload)));
}
Also used : TasksClient(io.zeebe.client.TasksClient) TaskEvent(io.zeebe.client.event.TaskEvent) Events(io.zeebe.client.util.Events) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Assertions.entry(org.assertj.core.api.Assertions.entry) StandardCharsets(java.nio.charset.StandardCharsets) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) RuleChain(org.junit.rules.RuleChain) Rule(org.junit.Rule) ClientRule(io.zeebe.client.util.ClientRule) ByteArrayInputStream(java.io.ByteArrayInputStream) EventType(io.zeebe.protocol.clientapi.EventType) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) ExpectedException(org.junit.rules.ExpectedException) MsgPackConverter(io.zeebe.client.impl.data.MsgPackConverter) Before(org.junit.Before) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) Test(org.junit.Test)

Example 19 with TaskEventImpl

use of io.zeebe.client.event.impl.TaskEventImpl in project zeebe by zeebe-io.

the class FailTaskTest method shouldThrowExceptionOnRejection.

@Test
public void shouldThrowExceptionOnRejection() {
    // given
    final TaskEventImpl baseEvent = Events.exampleTask();
    brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "FAIL").respondWith().key((r) -> r.key()).event().allOf((r) -> r.getCommand()).put("state", "FAIL_REJECTED").done().register();
    // then
    exception.expect(ClientCommandRejectedException.class);
    exception.expectMessage("Command for event with key 79 was rejected by broker (FAIL_REJECTED)");
    // when
    clientRule.tasks().fail(baseEvent).retries(5).execute();
}
Also used : TasksClient(io.zeebe.client.TasksClient) TaskEvent(io.zeebe.client.event.TaskEvent) Events(io.zeebe.client.util.Events) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Assertions.entry(org.assertj.core.api.Assertions.entry) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) RuleChain(org.junit.rules.RuleChain) Rule(org.junit.Rule) ClientRule(io.zeebe.client.util.ClientRule) EventType(io.zeebe.protocol.clientapi.EventType) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) ExpectedException(org.junit.rules.ExpectedException) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) Test(org.junit.Test)

Aggregations

TaskEventImpl (io.zeebe.client.event.impl.TaskEventImpl)19 Test (org.junit.Test)17 TaskEvent (io.zeebe.client.event.TaskEvent)14 ExpectedException (org.junit.rules.ExpectedException)13 ClientCommandRejectedException (io.zeebe.client.cmd.ClientCommandRejectedException)12 Events (io.zeebe.client.util.Events)12 EventType (io.zeebe.protocol.clientapi.EventType)12 StubBrokerRule (io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 Rule (org.junit.Rule)12 TasksClient (io.zeebe.client.TasksClient)8 MsgPackConverter (io.zeebe.client.impl.data.MsgPackConverter)8 ClientRule (io.zeebe.client.util.ClientRule)8 ExecuteCommandRequest (io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest)8 Assertions.entry (org.assertj.core.api.Assertions.entry)8 RuleChain (org.junit.rules.RuleChain)8 Before (org.junit.Before)7 ClientException (io.zeebe.client.cmd.ClientException)5 ZeebeClientImpl (io.zeebe.client.impl.ZeebeClientImpl)4 ControlMessageType (io.zeebe.protocol.clientapi.ControlMessageType)4