Search in sources :

Example 16 with WorkflowInstanceEvent

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

the class CreateWorkflowInstanceTest method shouldCreateBpmnProcessByIdAndVersion.

@Test
public void shouldCreateBpmnProcessByIdAndVersion() {
    final WorkflowsClient workflowService = clientRule.workflows();
    // when
    final WorkflowInstanceEvent workflowInstance = workflowService.create(clientRule.getDefaultTopic()).bpmnProcessId("anId").version(1).execute();
    // then instance is created of first workflow version
    assertThat(workflowInstance.getBpmnProcessId()).isEqualTo("anId");
    assertThat(workflowInstance.getVersion()).isEqualTo(1);
    assertThat(workflowInstance.getWorkflowInstanceKey()).isGreaterThan(0);
    waitUntil(() -> eventRecorder.hasWorkflowInstanceEvent(wfInstanceEvent("WORKFLOW_INSTANCE_CREATED")));
}
Also used : WorkflowsClient(io.zeebe.client.WorkflowsClient) WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent)

Example 17 with WorkflowInstanceEvent

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

the class ServiceTaskTest method shouldModifyPayloadInTask.

@Test
public void shouldModifyPayloadInTask() {
    // given
    workflowClient.deploy(clientRule.getDefaultTopic()).addWorkflowModel(Bpmn.createExecutableWorkflow("process").startEvent("start").serviceTask("task", t -> t.taskType("foo").input("$.foo", "$.foo").output("$.foo", "$.foo")).endEvent("end").done(), "workflow.bpmn").execute();
    workflowClient.create(clientRule.getDefaultTopic()).bpmnProcessId("process").payload("{\"foo\":1}").execute();
    // when
    taskClient.newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockOwner("owner").lockTime(Duration.ofMinutes(5)).handler((c, t) -> {
        final String modifiedPayload = t.getPayload().replaceAll("1", "2");
        c.complete(t).payload(modifiedPayload).execute();
    }).open();
    // then
    waitUntil(() -> eventRecorder.hasWorkflowInstanceEvent(wfInstanceEvent("ACTIVITY_COMPLETED")));
    final WorkflowInstanceEvent workflowEvent = eventRecorder.getSingleWorkflowInstanceEvent(wfInstanceEvent("ACTIVITY_COMPLETED"));
    assertThat(workflowEvent.getPayload()).isEqualTo("{\"foo\":2}");
}
Also used : TasksClient(io.zeebe.client.TasksClient) TaskEvent(io.zeebe.client.event.TaskEvent) RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) WorkflowsClient(io.zeebe.client.WorkflowsClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Bpmn(io.zeebe.model.bpmn.Bpmn) TopicEventRecorder.taskEvent(io.zeebe.broker.it.util.TopicEventRecorder.taskEvent) WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) Assertions.entry(org.assertj.core.api.Assertions.entry) TopicEventRecorder(io.zeebe.broker.it.util.TopicEventRecorder) RuleChain(org.junit.rules.RuleChain) ClientRule(io.zeebe.broker.it.ClientRule) TopicEventRecorder.wfInstanceEvent(io.zeebe.broker.it.util.TopicEventRecorder.wfInstanceEvent) Duration(java.time.Duration) Map(java.util.Map) EmbeddedBrokerRule(io.zeebe.broker.it.EmbeddedBrokerRule) org.junit(org.junit) ExpectedException(org.junit.rules.ExpectedException) WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent)

Example 18 with WorkflowInstanceEvent

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

the class ServiceTaskTest method shouldLockServiceTask.

@Test
public void shouldLockServiceTask() {
    // given
    final Map<String, String> taskHeaders = new HashMap<>();
    taskHeaders.put("cust1", "a");
    taskHeaders.put("cust2", "b");
    workflowClient.deploy(clientRule.getDefaultTopic()).addWorkflowModel(Bpmn.createExecutableWorkflow("process").startEvent("start").serviceTask("task", t -> t.taskType("foo").taskHeader("cust1", "a").taskHeader("cust2", "b")).endEvent("end").done(), "workflow.bpmn").execute();
    final WorkflowInstanceEvent workflowInstance = workflowClient.create(clientRule.getDefaultTopic()).bpmnProcessId("process").execute();
    // when
    final RecordingTaskHandler recordingTaskHandler = new RecordingTaskHandler();
    taskClient.newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockOwner("owner").lockTime(Duration.ofMinutes(5)).handler(recordingTaskHandler).open();
    // then
    waitUntil(() -> recordingTaskHandler.getHandledTasks().size() >= 1);
    assertThat(recordingTaskHandler.getHandledTasks()).hasSize(1);
    final WorkflowInstanceEvent activityInstance = eventRecorder.getSingleWorkflowInstanceEvent(e -> "ACTIVITY_ACTIVATED".equals(e.getState()));
    final TaskEvent taskLockedEvent = recordingTaskHandler.getHandledTasks().get(0);
    assertThat(taskLockedEvent.getHeaders()).containsOnly(entry("bpmnProcessId", "process"), entry("workflowDefinitionVersion", 1), entry("workflowKey", workflowInstance.getWorkflowKey()), entry("workflowInstanceKey", workflowInstance.getWorkflowInstanceKey()), entry("activityId", "task"), entry("activityInstanceKey", activityInstance.getMetadata().getKey()));
    assertThat(taskLockedEvent.getCustomHeaders()).containsOnly(entry("cust1", "a"), entry("cust2", "b"));
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) HashMap(java.util.HashMap) WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) TaskEvent(io.zeebe.client.event.TaskEvent)

Example 19 with WorkflowInstanceEvent

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

the class ServiceTaskTest method shouldCreateWorkflowInstanceWithServiceTask.

@Test
public void shouldCreateWorkflowInstanceWithServiceTask() {
    // given
    workflowClient.deploy(clientRule.getDefaultTopic()).addWorkflowModel(Bpmn.createExecutableWorkflow("process").startEvent("start").serviceTask("task", t -> t.taskType("foo")).endEvent("end").done(), "workflow.bpmn").execute();
    // when
    final WorkflowInstanceEvent workflowInstance = workflowClient.create(clientRule.getDefaultTopic()).bpmnProcessId("process").execute();
    // then
    assertThat(workflowInstance.getWorkflowInstanceKey()).isGreaterThan(0);
    waitUntil(() -> eventRecorder.hasWorkflowInstanceEvent(wfInstanceEvent("WORKFLOW_INSTANCE_CREATED")));
}
Also used : WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent)

Example 20 with WorkflowInstanceEvent

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

the class YamlWorkflowTest method shouldCreateWorkflowInstance.

@Test
public void shouldCreateWorkflowInstance() {
    // given
    workflowClient.deploy(clientRule.getDefaultTopic()).addResourceFromClasspath("workflows/simple-workflow.yaml").execute();
    // when
    final WorkflowInstanceEvent workflowInstance = workflowClient.create(clientRule.getDefaultTopic()).bpmnProcessId("yaml-workflow").execute();
    // then
    assertThat(workflowInstance.getWorkflowInstanceKey()).isGreaterThan(0);
    waitUntil(() -> eventRecorder.hasWorkflowInstanceEvent(wfInstanceEvent("WORKFLOW_INSTANCE_CREATED")));
}
Also used : WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent)

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