Search in sources :

Example 1 with BpmnModelInstance

use of io.camunda.zeebe.model.bpmn.BpmnModelInstance in project zdb by Zelldon.

the class ZeebeTest method shouldOpenAndReadState.

@Test
public void shouldOpenAndReadState() {
    // given
    final ZeebeClient client = ZeebeClient.newClientBuilder().gatewayAddress(zeebeContainer.getExternalGatewayAddress()).usePlaintext().build();
    final BpmnModelInstance process = Bpmn.createExecutableProcess("process").startEvent().endEvent().done();
    final DeploymentEvent deploymentEvent = client.newDeployCommand().addProcessModel(process, "process.bpmn").send().join();
    // when
    final var readonlyTransactionDb = ReadonlyTransactionDb.Companion.openReadonlyDb(ZeebePaths.Companion.getRuntimePath(tempDir, "1"));
    var zeebeState = new ZeebeDbState(readonlyTransactionDb, readonlyTransactionDb.createContext());
    // then
    final var processState = zeebeState.getProcessState();
    final var processes = processState.getProcesses();
    assertThat(processes).hasSize(1);
    final var deployedProcesses = new ArrayList<DeployedProcess>(processes);
    final var deployedProcess = deployedProcesses.get(0);
    assertThat(deployedProcess.getVersion()).isEqualTo(1);
    assertThat(deployedProcess.getBpmnProcessId()).isEqualTo(BufferUtil.wrapString("process"));
    assertThat(deployedProcess.getResourceName()).isEqualTo(BufferUtil.wrapString("process.bpmn"));
    assertThat(deployedProcess.getKey()).isEqualTo(deploymentEvent.getProcesses().get(0).getProcessDefinitionKey());
}
Also used : ZeebeClient(io.camunda.zeebe.client.ZeebeClient) ArrayList(java.util.ArrayList) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) ZeebeDbState(io.camunda.zeebe.engine.state.ZeebeDbState) DeploymentEvent(io.camunda.zeebe.client.api.response.DeploymentEvent) Test(org.junit.jupiter.api.Test)

Example 2 with BpmnModelInstance

use of io.camunda.zeebe.model.bpmn.BpmnModelInstance in project zdb by Zelldon.

the class ZeebeTest method shouldRunProcessInstanceUntilEnd.

/**
 * Just ot verify whether test container works with Zeebe Client.
 */
@Test
public void shouldRunProcessInstanceUntilEnd() {
    // given
    final ZeebeClient client = ZeebeClient.newClientBuilder().gatewayAddress(zeebeContainer.getExternalGatewayAddress()).usePlaintext().build();
    final BpmnModelInstance process = Bpmn.createExecutableProcess("process").startEvent().endEvent().done();
    // when
    final DeploymentEvent deploymentEvent = client.newDeployCommand().addProcessModel(process, "process.bpmn").send().join();
    // then
    final ProcessInstanceResult processInstanceResult = client.newCreateInstanceCommand().bpmnProcessId("process").latestVersion().withResult().send().join();
    assertThat(processInstanceResult.getProcessDefinitionKey()).isEqualTo(deploymentEvent.getProcesses().get(0).getProcessDefinitionKey());
}
Also used : ProcessInstanceResult(io.camunda.zeebe.client.api.response.ProcessInstanceResult) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) DeploymentEvent(io.camunda.zeebe.client.api.response.DeploymentEvent) Test(org.junit.jupiter.api.Test)

Example 3 with BpmnModelInstance

use of io.camunda.zeebe.model.bpmn.BpmnModelInstance in project zeebe-dmn-worker by camunda-community-hub.

the class WorkflowTest method init.

@BeforeAll
public static void init() {
    final var gatewayAddress = ZEEBE_CONTAINER.getExternalGatewayAddress();
    System.setProperty("zeebe.client.broker.gatewayAddress", gatewayAddress);
    ZEEBE_CLIENT = ZeebeClient.newClientBuilder().gatewayAddress(gatewayAddress).usePlaintext().build();
    // given
    final BpmnModelInstance process = Bpmn.createExecutableProcess("process").startEvent().serviceTask("make-decision").zeebeJobType("DMN").zeebeTaskHeader("decisionRef", "decision").endEvent().done();
    ZEEBE_CLIENT.newDeployCommand().addProcessModel(process, "process.bpmn").send().join();
}
Also used : BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 4 with BpmnModelInstance

use of io.camunda.zeebe.model.bpmn.BpmnModelInstance in project zeebe-test-container by camunda-community-hub.

the class TriggerTimerCatchEventTest method shouldTriggerTimerStartEvent.

@Test
@Timeout(value = 5, unit = TimeUnit.MINUTES)
void shouldTriggerTimerStartEvent() {
    // given
    final ZeebeClock clock = ZeebeClock.newDefaultClock(zeebeContainer);
    final BpmnModelInstance process = Bpmn.createExecutableProcess("process").startEvent().intermediateCatchEvent().timerWithDate(TIMER_DATE.toString()).serviceTask("task", b -> b.zeebeJobType(JOB_TYPE)).endEvent().done();
    final List<ActivatedJob> activatedJobs = new CopyOnWriteArrayList<>();
    final Instant brokerTime;
    // when
    final JobHandler handler = (client, job) -> activatedJobs.add(job);
    try (final ZeebeClient client = newZeebeClient(zeebeContainer);
        final JobWorker worker = newJobWorker(handler, client)) {
        client.newDeployCommand().addProcessModel(process, "process.bpmn").send().join();
        client.newCreateInstanceCommand().bpmnProcessId("process").latestVersion().send().join();
        brokerTime = clock.addTime(TIME_OFFSET);
        Awaitility.await("until a job has been activated by the worker").untilAsserted(() -> Assertions.assertThat(activatedJobs).hasSize(1));
    }
    // then
    Assertions.assertThat(activatedJobs).as("the timer event was triggered and a job is now available").hasSize(1);
    Assertions.assertThat(brokerTime).as("the modified time is at least equal to one day from now").isAfterOrEqualTo(TIMER_DATE);
}
Also used : ActivatedJob(io.camunda.zeebe.client.api.response.ActivatedJob) JobHandler(io.camunda.zeebe.client.api.worker.JobHandler) Testcontainers(org.testcontainers.junit.jupiter.Testcontainers) ZeebeContainer(io.zeebe.containers.ZeebeContainer) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) Instant(java.time.Instant) ZeebeClock(io.zeebe.containers.clock.ZeebeClock) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) Duration(java.time.Duration) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) ActivatedJob(io.camunda.zeebe.client.api.response.ActivatedJob) JobHandler(io.camunda.zeebe.client.api.worker.JobHandler) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Assertions(org.assertj.core.api.Assertions) JobWorker(io.camunda.zeebe.client.api.worker.JobWorker) Awaitility(org.awaitility.Awaitility) Timeout(org.junit.jupiter.api.Timeout) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Container(org.testcontainers.junit.jupiter.Container) ZeebeClock(io.zeebe.containers.clock.ZeebeClock) Instant(java.time.Instant) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) JobWorker(io.camunda.zeebe.client.api.worker.JobWorker) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 5 with BpmnModelInstance

use of io.camunda.zeebe.model.bpmn.BpmnModelInstance in project spring-zeebe by camunda-community-hub.

the class JobHandlerTest method testAutoCompleteOnAlreadyCompletedJob.

@Test
public void testAutoCompleteOnAlreadyCompletedJob() {
    BpmnModelInstance bpmnModel = Bpmn.createExecutableProcess("test2").startEvent().serviceTask().zeebeJobType("test2").endEvent().done();
    client.newDeployResourceCommand().addProcessModel(bpmnModel, "test2.bpmn").send().join();
    ProcessInstanceEvent processInstance = startProcessInstance(client, "test2");
    // assertThat(processInstance).isStarted();
    waitForProcessInstanceCompleted(processInstance);
    assertTrue(calledTest2);
}
Also used : BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) ProcessInstanceEvent(io.camunda.zeebe.client.api.response.ProcessInstanceEvent) Test(org.junit.jupiter.api.Test) ZeebeSpringTest(io.camunda.zeebe.spring.test.ZeebeSpringTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

BpmnModelInstance (io.camunda.zeebe.model.bpmn.BpmnModelInstance)442 Test (org.junit.Test)336 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)204 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)184 RecordingExporter (io.camunda.zeebe.test.util.record.RecordingExporter)166 Rule (org.junit.Rule)163 EngineRule (io.camunda.zeebe.engine.util.EngineRule)157 Record (io.camunda.zeebe.protocol.record.Record)142 ProcessInstanceIntent (io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent)139 BpmnElementType (io.camunda.zeebe.protocol.record.value.BpmnElementType)136 List (java.util.List)126 ClassRule (org.junit.ClassRule)124 ProcessInstanceRecordValue (io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue)121 Assertions.tuple (org.assertj.core.api.Assertions.tuple)121 Map (java.util.Map)99 JobIntent (io.camunda.zeebe.protocol.record.intent.JobIntent)97 Duration (java.time.Duration)96 Collectors (java.util.stream.Collectors)90 ProcessBuilder (io.camunda.zeebe.model.bpmn.builder.ProcessBuilder)79 MessageSubscriptionIntent (io.camunda.zeebe.protocol.record.intent.MessageSubscriptionIntent)78