Search in sources :

Example 1 with WorkflowInstanceEventImpl

use of io.zeebe.client.workflow.impl.WorkflowInstanceEventImpl in project zeebe by zeebe-io.

the class CancelWorkflowInstanceTest method shouldCancelWorkflowInstance.

@Test
public void shouldCancelWorkflowInstance() {
    // given
    final WorkflowInstanceEventImpl event = Events.exampleWorfklowInstance();
    event.setKey(2L);
    brokerRule.onWorkflowRequestRespondWith(2L).put("state", "WORKFLOW_INSTANCE_CANCELED").done().register();
    // when
    clientRule.workflows().cancel(event).execute();
    // then
    assertThat(brokerRule.getReceivedCommandRequests()).hasSize(1);
    final ExecuteCommandRequest commandRequest = brokerRule.getReceivedCommandRequests().get(0);
    assertThat(commandRequest.getCommand()).containsEntry("state", "CANCEL_WORKFLOW_INSTANCE");
    assertThat(commandRequest.key()).isEqualTo(2L);
}
Also used : ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) WorkflowInstanceEventImpl(io.zeebe.client.workflow.impl.WorkflowInstanceEventImpl) Test(org.junit.Test)

Example 2 with WorkflowInstanceEventImpl

use of io.zeebe.client.workflow.impl.WorkflowInstanceEventImpl in project zeebe by zeebe-io.

the class UpdatePayloadTest method shouldRejectUpdatePayload.

@Test
public void shouldRejectUpdatePayload() {
    // given
    final WorkflowInstanceEventImpl event = Events.exampleWorfklowInstance();
    event.setKey(2L);
    event.setWorkflowInstanceKey(1L);
    brokerRule.onExecuteCommandRequest().respondWith().key(r -> r.key()).event().allOf(r -> r.getCommand()).put("state", "UPDATE_PAYLOAD_REJECTED").done().register();
    // then
    thrown.expect(ClientCommandRejectedException.class);
    thrown.expectMessage("Command for event with key 2 was rejected by broker (UPDATE_PAYLOAD_REJECTED)");
    // when
    workflowTopicClient.updatePayload(event).payload(PAYLOAD).execute();
}
Also used : Events(io.zeebe.client.util.Events) WorkflowsClient(io.zeebe.client.WorkflowsClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) WorkflowInstanceEventImpl(io.zeebe.client.workflow.impl.WorkflowInstanceEventImpl) Test(org.junit.Test) 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) MsgPackConverter(io.zeebe.client.impl.data.MsgPackConverter) Before(org.junit.Before) WorkflowInstanceEventImpl(io.zeebe.client.workflow.impl.WorkflowInstanceEventImpl) Test(org.junit.Test)

Example 3 with WorkflowInstanceEventImpl

use of io.zeebe.client.workflow.impl.WorkflowInstanceEventImpl in project zeebe by zeebe-io.

the class TopicSubscriptionBuilderImpl method dispatchEvent.

protected void dispatchEvent(GeneralEventImpl event) throws Exception {
    final TopicEventType eventType = event.getMetadata().getType();
    if (TopicEventType.TASK == eventType && taskEventHandler != null) {
        final TaskEventImpl taskEvent = msgPackMapper.convert(event.getAsMsgPack(), TaskEventImpl.class);
        taskEvent.updateMetadata(event.getMetadata());
        taskEventHandler.handle(taskEvent);
    } else if (TopicEventType.WORKFLOW_INSTANCE == eventType && wfInstanceEventHandler != null) {
        final WorkflowInstanceEventImpl wfInstanceEvent = msgPackMapper.convert(event.getAsMsgPack(), WorkflowInstanceEventImpl.class);
        wfInstanceEvent.updateMetadata(event.getMetadata());
        wfInstanceEventHandler.handle(wfInstanceEvent);
    } else if (TopicEventType.WORKFLOW == eventType && wfEventHandler != null) {
        final WorkflowEventImpl wfEvent = msgPackMapper.convert(event.getAsMsgPack(), WorkflowEventImpl.class);
        wfEvent.updateMetadata(event.getMetadata());
        wfEventHandler.handle(wfEvent);
    } else if (TopicEventType.INCIDENT == eventType && incidentEventHandler != null) {
        final IncidentEventImpl incidentEvent = msgPackMapper.convert(event.getAsMsgPack(), IncidentEventImpl.class);
        incidentEvent.updateMetadata(event.getMetadata());
        incidentEventHandler.handle(incidentEvent);
    } else if (TopicEventType.RAFT == eventType && raftEventHandler != null) {
        final RaftEventImpl raftEvent = msgPackMapper.convert(event.getAsMsgPack(), RaftEventImpl.class);
        raftEvent.updateMetadata(event.getMetadata());
        raftEventHandler.handle(raftEvent);
    } else if (defaultEventHandler != null) {
        defaultEventHandler.handle(event);
    }
}
Also used : TopicEventType(io.zeebe.client.event.TopicEventType) WorkflowInstanceEventImpl(io.zeebe.client.workflow.impl.WorkflowInstanceEventImpl)

Example 4 with WorkflowInstanceEventImpl

use of io.zeebe.client.workflow.impl.WorkflowInstanceEventImpl in project zeebe by zeebe-io.

the class Events method exampleWorfklowInstance.

public static WorkflowInstanceEventImpl exampleWorfklowInstance() {
    final WorkflowInstanceEventImpl baseEvent = new WorkflowInstanceEventImpl("CREATED", new MsgPackConverter());
    baseEvent.setActivityId("some_activity");
    baseEvent.setBpmnProcessId("some_proceess");
    baseEvent.setKey(89);
    baseEvent.setPayloadAsJson("{\"key\":\"val\"}");
    baseEvent.setPartitionId(StubBrokerRule.TEST_PARTITION_ID);
    baseEvent.setTopicName(ClientApiRule.DEFAULT_TOPIC_NAME);
    baseEvent.setVersion(123);
    baseEvent.setWorkflowInstanceKey(456L);
    baseEvent.setWorkflowKey(789L);
    return baseEvent;
}
Also used : WorkflowInstanceEventImpl(io.zeebe.client.workflow.impl.WorkflowInstanceEventImpl) MsgPackConverter(io.zeebe.client.impl.data.MsgPackConverter)

Example 5 with WorkflowInstanceEventImpl

use of io.zeebe.client.workflow.impl.WorkflowInstanceEventImpl in project zeebe by zeebe-io.

the class UpdatePayloadTest method shouldUpdatePayload.

@Test
public void shouldUpdatePayload() {
    // given
    final WorkflowInstanceEventImpl event = Events.exampleWorfklowInstance();
    event.setKey(2L);
    event.setWorkflowInstanceKey(1L);
    brokerRule.onExecuteCommandRequest().respondWith().key(r -> r.key()).event().put("state", "PAYLOAD_UPDATED").done().register();
    // when
    workflowTopicClient.updatePayload(event).payload(PAYLOAD).execute();
    // then
    assertThat(brokerRule.getReceivedCommandRequests()).hasSize(1);
    final ExecuteCommandRequest request = brokerRule.getReceivedCommandRequests().get(0);
    assertThat(request.eventType()).isEqualTo(EventType.WORKFLOW_INSTANCE_EVENT);
    assertThat(request.key()).isEqualTo(2L);
    assertThat(request.getCommand()).containsEntry("state", "UPDATE_PAYLOAD").containsEntry("workflowInstanceKey", 1).containsEntry("payload", ENCODED_PAYLOAD);
}
Also used : ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) WorkflowInstanceEventImpl(io.zeebe.client.workflow.impl.WorkflowInstanceEventImpl) Test(org.junit.Test)

Aggregations

WorkflowInstanceEventImpl (io.zeebe.client.workflow.impl.WorkflowInstanceEventImpl)6 Test (org.junit.Test)4 ExecuteCommandRequest (io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest)3 MsgPackConverter (io.zeebe.client.impl.data.MsgPackConverter)2 WorkflowsClient (io.zeebe.client.WorkflowsClient)1 ClientCommandRejectedException (io.zeebe.client.cmd.ClientCommandRejectedException)1 TopicEventType (io.zeebe.client.event.TopicEventType)1 ClientRule (io.zeebe.client.util.ClientRule)1 Events (io.zeebe.client.util.Events)1 EventType (io.zeebe.protocol.clientapi.EventType)1 StubBrokerRule (io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 ExpectedException (org.junit.rules.ExpectedException)1 RuleChain (org.junit.rules.RuleChain)1