Search in sources :

Example 1 with SetVariablesResponse

use of io.camunda.zeebe.client.api.response.SetVariablesResponse in project zeebe-process-test by camunda.

the class EngineClientTest method shouldUpdateVariablesOnProcessInstance.

@Test
void shouldUpdateVariablesOnProcessInstance() {
    // given
    zeebeClient.newDeployCommand().addProcessModel(Bpmn.createExecutableProcess("simpleProcess").startEvent().serviceTask("task", task -> task.zeebeJobType("jobType")).endEvent().done(), "simpleProcess.bpmn").send().join();
    final ProcessInstanceEvent processInstance = zeebeClient.newCreateInstanceCommand().bpmnProcessId("simpleProcess").latestVersion().variables(Map.of("test", 1)).send().join();
    // when
    final SetVariablesResponse variablesResponse = zeebeClient.newSetVariablesCommand(processInstance.getProcessInstanceKey()).variables(Map.of("test123", 234)).local(true).send().join();
    // then
    assertThat(variablesResponse).isNotNull();
    assertThat(variablesResponse.getKey()).isPositive();
}
Also used : PartitionBrokerRole(io.camunda.zeebe.client.api.response.PartitionBrokerRole) TimerIntent(io.camunda.zeebe.protocol.record.intent.TimerIntent) BeforeEach(org.junit.jupiter.api.BeforeEach) RecordType(io.camunda.zeebe.protocol.record.RecordType) ClientException(io.camunda.zeebe.client.api.command.ClientException) ProcessInstanceIntent(io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JobRecordValue(io.camunda.zeebe.protocol.record.value.JobRecordValue) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) TimerRecordValue(io.camunda.zeebe.protocol.record.value.TimerRecordValue) ZeebeTestEngine(io.camunda.zeebe.process.test.api.ZeebeTestEngine) DeploymentEvent(io.camunda.zeebe.client.api.response.DeploymentEvent) Record(io.camunda.zeebe.protocol.record.Record) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PartitionInfo(io.camunda.zeebe.client.api.response.PartitionInfo) Duration(java.time.Duration) Map(java.util.Map) ActivatedJob(io.camunda.zeebe.client.api.response.ActivatedJob) Process(io.camunda.zeebe.client.api.response.Process) ProcessInstanceResult(io.camunda.zeebe.client.api.response.ProcessInstanceResult) StreamSupport(java.util.stream.StreamSupport) PartitionBrokerHealth(io.camunda.zeebe.client.api.response.PartitionBrokerHealth) VersionUtil(io.camunda.zeebe.util.VersionUtil) Topology(io.camunda.zeebe.client.api.response.Topology) ProcessInstanceEvent(io.camunda.zeebe.client.api.response.ProcessInstanceEvent) ZeebeFuture(io.camunda.zeebe.client.api.ZeebeFuture) BrokerInfo(io.camunda.zeebe.client.api.response.BrokerInfo) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) SetVariablesResponse(io.camunda.zeebe.client.api.response.SetVariablesResponse) Optional(java.util.Optional) ActivateJobsResponse(io.camunda.zeebe.client.api.response.ActivateJobsResponse) Awaitility(org.awaitility.Awaitility) RecordStream(io.camunda.zeebe.process.test.filters.RecordStream) JobIntent(io.camunda.zeebe.protocol.record.intent.JobIntent) ProcessInstanceEvent(io.camunda.zeebe.client.api.response.ProcessInstanceEvent) SetVariablesResponse(io.camunda.zeebe.client.api.response.SetVariablesResponse) Test(org.junit.jupiter.api.Test)

Example 2 with SetVariablesResponse

use of io.camunda.zeebe.client.api.response.SetVariablesResponse in project zeebe by camunda.

the class SetVariablesTest method shouldSetVariables.

@Test
public void shouldSetVariables() {
    // given
    final long processInstanceKey = CLIENT_RULE.createProcessInstance(processDefinitionKey);
    // when
    final SetVariablesResponse response = CLIENT_RULE.getClient().newSetVariablesCommand(processInstanceKey).variables(Map.of("foo", "bar")).send().join();
    // then
    ZeebeAssertHelper.assertVariableDocumentUpdated((variableDocument) -> assertThat(variableDocument.getVariables()).containsOnly(entry("foo", "bar")));
    final Record<VariableDocumentRecordValue> record = RecordingExporter.variableDocumentRecords(VariableDocumentIntent.UPDATED).getFirst();
    assertThat(response.getKey()).isEqualTo(record.getKey());
}
Also used : VariableDocumentRecordValue(io.camunda.zeebe.protocol.record.value.VariableDocumentRecordValue) SetVariablesResponse(io.camunda.zeebe.client.api.response.SetVariablesResponse) Test(org.junit.Test)

Example 3 with SetVariablesResponse

use of io.camunda.zeebe.client.api.response.SetVariablesResponse in project zeebe by camunda.

the class SetVariablesTest method shouldCommandWithVariablesAsString.

@Test
public void shouldCommandWithVariablesAsString() {
    // given
    gatewayService.onSetVariablesRequest(345);
    final String variables = "{\"key\": \"val\"}";
    // when
    final SetVariablesResponse response = client.newSetVariablesCommand(123).variables(variables).send().join();
    // then
    assertThat(response).isNotNull();
    assertThat(response.getKey()).isEqualTo(345);
    final SetVariablesRequest request = gatewayService.getLastRequest();
    assertThat(request.getElementInstanceKey()).isEqualTo(123);
    assertThat(fromJsonAsMap(request.getVariables())).containsOnly(entry("key", "val"));
    rule.verifyDefaultRequestTimeout();
}
Also used : SetVariablesRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest) SetVariablesResponse(io.camunda.zeebe.client.api.response.SetVariablesResponse) ClientTest(io.camunda.zeebe.client.util.ClientTest) Test(org.junit.Test)

Example 4 with SetVariablesResponse

use of io.camunda.zeebe.client.api.response.SetVariablesResponse in project zeebe by zeebe-io.

the class SetVariablesTest method shouldCommandWithVariablesAsString.

@Test
public void shouldCommandWithVariablesAsString() {
    // given
    gatewayService.onSetVariablesRequest(345);
    final String variables = "{\"key\": \"val\"}";
    // when
    final SetVariablesResponse response = client.newSetVariablesCommand(123).variables(variables).send().join();
    // then
    assertThat(response).isNotNull();
    assertThat(response.getKey()).isEqualTo(345);
    final SetVariablesRequest request = gatewayService.getLastRequest();
    assertThat(request.getElementInstanceKey()).isEqualTo(123);
    assertThat(fromJsonAsMap(request.getVariables())).containsOnly(entry("key", "val"));
    rule.verifyDefaultRequestTimeout();
}
Also used : SetVariablesRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest) SetVariablesResponse(io.camunda.zeebe.client.api.response.SetVariablesResponse) ClientTest(io.camunda.zeebe.client.util.ClientTest) Test(org.junit.Test)

Example 5 with SetVariablesResponse

use of io.camunda.zeebe.client.api.response.SetVariablesResponse in project zeebe by camunda-cloud.

the class SetVariablesCommandImpl method send.

@Override
public ZeebeFuture<SetVariablesResponse> send() {
    final SetVariablesRequest request = builder.build();
    final RetriableClientFutureImpl<SetVariablesResponse, GatewayOuterClass.SetVariablesResponse> future = new RetriableClientFutureImpl<>(SetVariablesResponseImpl::new, retryPredicate, streamObserver -> send(request, streamObserver));
    send(request, future);
    return future;
}
Also used : SetVariablesResponseImpl(io.camunda.zeebe.client.impl.response.SetVariablesResponseImpl) RetriableClientFutureImpl(io.camunda.zeebe.client.impl.RetriableClientFutureImpl) SetVariablesRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest) SetVariablesResponse(io.camunda.zeebe.client.api.response.SetVariablesResponse)

Aggregations

SetVariablesResponse (io.camunda.zeebe.client.api.response.SetVariablesResponse)11 SetVariablesRequest (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest)6 Test (org.junit.Test)6 RetriableClientFutureImpl (io.camunda.zeebe.client.impl.RetriableClientFutureImpl)3 SetVariablesResponseImpl (io.camunda.zeebe.client.impl.response.SetVariablesResponseImpl)3 ClientTest (io.camunda.zeebe.client.util.ClientTest)3 VariableDocumentRecordValue (io.camunda.zeebe.protocol.record.value.VariableDocumentRecordValue)3 ZeebeClient (io.camunda.zeebe.client.ZeebeClient)2 ZeebeFuture (io.camunda.zeebe.client.api.ZeebeFuture)2 ClientException (io.camunda.zeebe.client.api.command.ClientException)2 ActivateJobsResponse (io.camunda.zeebe.client.api.response.ActivateJobsResponse)2 ActivatedJob (io.camunda.zeebe.client.api.response.ActivatedJob)2 BrokerInfo (io.camunda.zeebe.client.api.response.BrokerInfo)2 DeploymentEvent (io.camunda.zeebe.client.api.response.DeploymentEvent)2 PartitionBrokerHealth (io.camunda.zeebe.client.api.response.PartitionBrokerHealth)2 PartitionBrokerRole (io.camunda.zeebe.client.api.response.PartitionBrokerRole)2 PartitionInfo (io.camunda.zeebe.client.api.response.PartitionInfo)2 Process (io.camunda.zeebe.client.api.response.Process)2 ProcessInstanceEvent (io.camunda.zeebe.client.api.response.ProcessInstanceEvent)2 ProcessInstanceResult (io.camunda.zeebe.client.api.response.ProcessInstanceResult)2