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);
}
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();
}
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);
}
}
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;
}
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);
}
Aggregations