Search in sources :

Example 21 with WorkflowInstanceEvent

use of io.zeebe.client.event.WorkflowInstanceEvent in project zeebe by zeebe-io.

the class YamlWorkflowTest method shouldCompleteTaskWithPayload.

@Test
public void shouldCompleteTaskWithPayload() {
    // given
    workflowClient.deploy(clientRule.getDefaultTopic()).addResourceFromClasspath("workflows/workflow-with-mappings.yaml").execute();
    workflowClient.create(clientRule.getDefaultTopic()).bpmnProcessId("workflow-mappings").payload("{\"foo\":1}").execute();
    // when
    final RecordingTaskHandler recordingTaskHandler = new RecordingTaskHandler((c, task) -> c.complete(task).payload("{\"result\":3}").execute());
    taskClient.newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockOwner("owner").lockTime(Duration.ofMinutes(5)).handler(recordingTaskHandler).open();
    // then
    waitUntil(() -> recordingTaskHandler.getHandledTasks().size() >= 1);
    final TaskEvent taskLockedEvent = recordingTaskHandler.getHandledTasks().get(0);
    assertThat(taskLockedEvent.getPayload()).isEqualTo("{\"bar\":1}");
    waitUntil(() -> eventRecorder.hasWorkflowInstanceEvent(wfInstanceEvent("ACTIVITY_COMPLETED")));
    final WorkflowInstanceEvent workflowEvent = eventRecorder.getSingleWorkflowInstanceEvent(wfInstanceEvent("ACTIVITY_COMPLETED"));
    assertThat(workflowEvent.getPayload()).isEqualTo("{\"result\":3}");
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskEvent(io.zeebe.client.event.TaskEvent) WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent)

Example 22 with WorkflowInstanceEvent

use of io.zeebe.client.event.WorkflowInstanceEvent in project zeebe by zeebe-io.

the class CreateWorkflowInstanceTest method shouldCreateWorkflowInstanceByWorkflowKey.

@Test
public void shouldCreateWorkflowInstanceByWorkflowKey() {
    // given
    brokerRule.onWorkflowRequestRespondWith(1L).put("state", "WORKFLOW_INSTANCE_CREATED").put("workflowInstanceKey", 1).put("payload", msgPackConverter.convertToMsgPack("null")).done().register();
    // when
    final WorkflowInstanceEvent workflowInstance = clientRule.workflows().create(clientRule.getDefaultTopicName()).workflowKey(2L).execute();
    // then
    assertThat(workflowInstance).isNotNull();
    assertThat(workflowInstance.getWorkflowKey()).isEqualTo(2L);
}
Also used : WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) Test(org.junit.Test)

Example 23 with WorkflowInstanceEvent

use of io.zeebe.client.event.WorkflowInstanceEvent in project zeebe by zeebe-io.

the class CreateWorkflowInstanceTest method shouldCreateWorkflowInstanceByBpmnProcessId.

@Test
public void shouldCreateWorkflowInstanceByBpmnProcessId() {
    // given
    brokerRule.onWorkflowRequestRespondWith(1L).put("state", "WORKFLOW_INSTANCE_CREATED").put("version", 1).put("workflowInstanceKey", 1).put("payload", msgPackConverter.convertToMsgPack("null")).done().register();
    // when
    final WorkflowInstanceEvent workflowInstance = clientRule.workflows().create(clientRule.getDefaultTopicName()).bpmnProcessId("foo").execute();
    // then
    assertThat(workflowInstance).isNotNull();
    assertThat(workflowInstance.getBpmnProcessId()).isEqualTo("foo");
    assertThat(workflowInstance.getVersion()).isEqualTo(1);
    assertThat(workflowInstance.getWorkflowInstanceKey()).isEqualTo(1);
}
Also used : WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) Test(org.junit.Test)

Example 24 with WorkflowInstanceEvent

use of io.zeebe.client.event.WorkflowInstanceEvent in project zeebe by zeebe-io.

the class CreateWorkflowInstanceTest method shouldCreateWorkflowInstanceWithPayload.

@Test
public void shouldCreateWorkflowInstanceWithPayload() throws Exception {
    // given
    final byte[] payload = getBytes("{ \"bar\" : 4 }");
    brokerRule.onWorkflowRequestRespondWith(1L).put("state", "WORKFLOW_INSTANCE_CREATED").put("version", 1).put("workflowInstanceKey", 1).put("payload", msgPackConverter.convertToMsgPack("{ \"bar\" : 4 }")).done().register();
    // when
    final WorkflowInstanceEvent workflowInstance = clientRule.workflows().create(clientRule.getDefaultTopicName()).bpmnProcessId("foo").payload(new ByteArrayInputStream(payload)).execute();
    // then
    assertThat(workflowInstance).isNotNull();
    assertThat(workflowInstance.getBpmnProcessId()).isEqualTo("foo");
    assertThat(workflowInstance.getVersion()).isEqualTo(1);
    assertThat(workflowInstance.getWorkflowInstanceKey()).isEqualTo(1);
    assertThat(workflowInstance.getPayload()).isEqualTo("{\"bar\":4}");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) Test(org.junit.Test)

Example 25 with WorkflowInstanceEvent

use of io.zeebe.client.event.WorkflowInstanceEvent in project zeebe by zeebe-io.

the class CreateWorkflowInstanceTest method shouldCreateWorkflowInstanceByBpmnProcessIdAndVersion.

@Test
public void shouldCreateWorkflowInstanceByBpmnProcessIdAndVersion() {
    // given
    brokerRule.onWorkflowRequestRespondWith(1L).put("state", "WORKFLOW_INSTANCE_CREATED").put("workflowInstanceKey", 1).put("payload", msgPackConverter.convertToMsgPack("null")).done().register();
    // when
    final WorkflowInstanceEvent workflowInstance = clientRule.workflows().create(clientRule.getDefaultTopicName()).bpmnProcessId("foo").version(2).execute();
    // then
    assertThat(workflowInstance).isNotNull();
    assertThat(workflowInstance.getBpmnProcessId()).isEqualTo("foo");
    assertThat(workflowInstance.getVersion()).isEqualTo(2);
    assertThat(workflowInstance.getWorkflowInstanceKey()).isEqualTo(1);
}
Also used : WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) Test(org.junit.Test)

Aggregations

WorkflowInstanceEvent (io.zeebe.client.event.WorkflowInstanceEvent)31 Test (org.junit.Test)14 ClientRule (io.zeebe.broker.it.ClientRule)7 EmbeddedBrokerRule (io.zeebe.broker.it.EmbeddedBrokerRule)7 TopicEventRecorder (io.zeebe.broker.it.util.TopicEventRecorder)7 Bpmn (io.zeebe.model.bpmn.Bpmn)7 WorkflowDefinition (io.zeebe.model.bpmn.instance.WorkflowDefinition)7 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)7 Duration (java.time.Duration)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 RuleChain (org.junit.rules.RuleChain)7 RecordingTaskHandler (io.zeebe.broker.it.util.RecordingTaskHandler)6 WorkflowsClient (io.zeebe.client.WorkflowsClient)6 TaskEvent (io.zeebe.client.event.TaskEvent)6 ExpectedException (org.junit.rules.ExpectedException)6 TopicEventRecorder.wfInstanceEvent (io.zeebe.broker.it.util.TopicEventRecorder.wfInstanceEvent)5 org.junit (org.junit)5 ClientCommandRejectedException (io.zeebe.client.cmd.ClientCommandRejectedException)4 DeploymentEvent (io.zeebe.client.event.DeploymentEvent)4 TasksClient (io.zeebe.client.TasksClient)3