Search in sources :

Example 11 with WorkflowDefinition

use of io.zeebe.model.bpmn.instance.WorkflowDefinition in project zeebe by zeebe-io.

the class ExclusiveGatewayTest method shouldEvaluateConditionOnFlow.

@Test
public void shouldEvaluateConditionOnFlow() {
    final WorkflowDefinition workflowDefinition = Bpmn.createExecutableWorkflow("workflow").startEvent().exclusiveGateway().sequenceFlow(s -> s.condition("$.foo < 5")).endEvent("a").sequenceFlow(s -> s.defaultFlow()).endEvent("b").done();
    workflowClient.deploy(clientRule.getDefaultTopic()).addWorkflowModel(workflowDefinition, "workflow.bpmn").execute();
    // when
    workflowClient.create(clientRule.getDefaultTopic()).bpmnProcessId("workflow").payload("{\"foo\":3}").execute();
    waitUntil(() -> eventRecorder.hasWorkflowInstanceEvent(wfInstanceEvent("WORKFLOW_INSTANCE_COMPLETED")));
    final WorkflowInstanceEvent endEvent = eventRecorder.getSingleWorkflowInstanceEvent(wfInstanceEvent("END_EVENT_OCCURRED"));
    assertThat(endEvent.getActivityId()).isEqualTo("a");
}
Also used : WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition)

Example 12 with WorkflowDefinition

use of io.zeebe.model.bpmn.instance.WorkflowDefinition in project zeebe by zeebe-io.

the class ExclusiveGatewayTest method shouldExecuteWorkflowWithLoop.

@Test
public void shouldExecuteWorkflowWithLoop() {
    // given
    final WorkflowDefinition workflowDefinition = Bpmn.createExecutableWorkflow("workflow").startEvent().serviceTask("inc", t -> t.taskType("inc")).exclusiveGateway().sequenceFlow(s -> s.condition("$.count > 5")).endEvent().sequenceFlow("back", s -> s.defaultFlow()).joinWith("inc").done();
    workflowClient.deploy(clientRule.getDefaultTopic()).addWorkflowModel(workflowDefinition, "workflow.bpmn").execute();
    // when
    workflowClient.create(clientRule.getDefaultTopic()).bpmnProcessId("workflow").payload("{\"count\":0}").execute();
    taskClient.newTaskSubscription(clientRule.getDefaultTopic()).lockTime(Duration.ofSeconds(5)).lockOwner("test").taskType("inc").handler((c, task) -> {
        final String payload = task.getPayload();
        final int i = payload.indexOf(":");
        final int count = Integer.valueOf(payload.substring(i + 1, i + 2));
        c.complete(task).payload("{\"count\":" + (count + 1) + "}").execute();
    }).open();
    // then
    waitUntil(() -> eventRecorder.hasWorkflowInstanceEvent(wfInstanceEvent("WORKFLOW_INSTANCE_COMPLETED")));
    final WorkflowInstanceEvent event = eventRecorder.getSingleWorkflowInstanceEvent(wfInstanceEvent("WORKFLOW_INSTANCE_COMPLETED"));
    assertThat(event.getPayload()).isEqualTo("{\"count\":6}");
}
Also used : TasksClient(io.zeebe.client.TasksClient) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) WorkflowsClient(io.zeebe.client.WorkflowsClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.zeebe.model.bpmn.Bpmn) WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) 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) EmbeddedBrokerRule(io.zeebe.broker.it.EmbeddedBrokerRule) org.junit(org.junit) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition) WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition)

Example 13 with WorkflowDefinition

use of io.zeebe.model.bpmn.instance.WorkflowDefinition in project zeebe by zeebe-io.

the class IncidentTopicSubscriptionTest method setUp.

@Before
public void setUp() {
    this.client = clientRule.getClient();
    final WorkflowDefinition workflow = Bpmn.createExecutableWorkflow("process").startEvent("start").serviceTask("task", t -> t.taskType("test").input("$.foo", "$.foo")).endEvent("end").done();
    clientRule.workflows().deploy(clientRule.getDefaultTopic()).addWorkflowModel(workflow, "workflow.bpmn").execute();
}
Also used : WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition)

Example 14 with WorkflowDefinition

use of io.zeebe.model.bpmn.instance.WorkflowDefinition in project zeebe by zeebe-io.

the class WorkflowInstanceTopicSubscriptionTest method setUp.

@Before
public void setUp() {
    this.client = clientRule.getClient();
    final WorkflowDefinition workflow = Bpmn.createExecutableWorkflow("process").startEvent("a").endEvent("b").done();
    clientRule.workflows().deploy(clientRule.getDefaultTopic()).addWorkflowModel(workflow, "workflow.bpmn").execute();
}
Also used : WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition)

Example 15 with WorkflowDefinition

use of io.zeebe.model.bpmn.instance.WorkflowDefinition in project zeebe by zeebe-io.

the class CreateDeploymentTest method shouldDeployMultipleResources.

@SuppressWarnings("unchecked")
@Test
public void shouldDeployMultipleResources() {
    // given
    stubDeploymentRequest();
    final WorkflowDefinition definition1 = Bpmn.createExecutableWorkflow("model1").startEvent().done();
    final WorkflowDefinition definition2 = Bpmn.createExecutableWorkflow("model2").startEvent().done();
    // when
    clientRule.workflows().deploy(clientRule.getDefaultTopicName()).addWorkflowModel(definition1, "model1.bpmn").addWorkflowModel(definition2, "model2.bpmn").execute();
    // then
    assertThat(brokerRule.getReceivedCommandRequests()).hasSize(1);
    final ExecuteCommandRequest commandRequest = brokerRule.getReceivedCommandRequests().get(0);
    final List<Map<String, Object>> resources = (List<Map<String, Object>>) commandRequest.getCommand().get("resources");
    assertThat(resources).hasSize(2);
    assertThat(resources).extracting("resourceName").contains("model1.bpmn", "model2.bpmn");
    assertThat(resources).extracting("resourceType").contains("BPMN_XML", "BPMN_XML");
    assertThat(resources).extracting("resource").contains(Bpmn.convertToString(definition1).getBytes(UTF_8), Bpmn.convertToString(definition2).getBytes(UTF_8));
}
Also used : ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition)

Aggregations

WorkflowDefinition (io.zeebe.model.bpmn.instance.WorkflowDefinition)27 Bpmn (io.zeebe.model.bpmn.Bpmn)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 RuleChain (org.junit.rules.RuleChain)8 EmbeddedBrokerRule (io.zeebe.broker.test.EmbeddedBrokerRule)7 EventType (io.zeebe.protocol.clientapi.EventType)7 ResourceType (io.zeebe.broker.workflow.data.ResourceType)6 Protocol (io.zeebe.protocol.Protocol)6 ExecuteCommandResponse (io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse)6 File (java.io.File)6 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)6 Files (org.assertj.core.util.Files)6 Test (org.junit.Test)6 org.junit (org.junit)5 WorkflowInstanceEvent (io.zeebe.broker.workflow.data.WorkflowInstanceEvent)4 TestTopicClient.taskEvents (io.zeebe.test.broker.protocol.clientapi.TestTopicClient.taskEvents)4 TestTopicClient.workflowInstanceEvents (io.zeebe.test.broker.protocol.clientapi.TestTopicClient.workflowInstanceEvents)4 MsgPackUtil.asMsgPack (io.zeebe.test.util.MsgPackUtil.asMsgPack)4 WorkflowInstanceEvent (io.zeebe.client.event.WorkflowInstanceEvent)3 io.zeebe.test.broker.protocol.clientapi (io.zeebe.test.broker.protocol.clientapi)3