use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest in project zeebe by camunda.
the class SetVariablesTest method shouldCommandWithVariablesAsMap.
@Test
public void shouldCommandWithVariablesAsMap() {
// given
final Map<String, Object> variablesMap = Collections.singletonMap("key", "val");
// when
client.newSetVariablesCommand(123).variables(variablesMap).send().join();
// then
final SetVariablesRequest request = gatewayService.getLastRequest();
assertThat(fromJsonAsMap(request.getVariables())).containsOnly(entry("key", "val"));
}
use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest in project zeebe by camunda.
the class SetVariablesTest method shouldCommandWithVariablesAsStream.
@Test
public void shouldCommandWithVariablesAsStream() {
// given
final String variables = "{\"key\": \"val\"}";
final InputStream variablesStream = new ByteArrayInputStream(StringUtil.getBytes(variables));
// when
client.newSetVariablesCommand(123).variables(variablesStream).send().join();
// then
final SetVariablesRequest request = gatewayService.getLastRequest();
assertThat(fromJsonAsMap(request.getVariables())).containsOnly(entry("key", "val"));
}
use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest 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();
}
use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest in project zeebe by zeebe-io.
the class SetVariablesTest method shouldMapRequestAndResponse.
@Test
public void shouldMapRequestAndResponse() {
// given
final SetVariablesStub stub = new SetVariablesStub();
stub.registerWith(brokerClient);
final String variables = JsonUtil.toJson(Collections.singletonMap("key", "value"));
final int partitionId = 1;
final long elementInstanceKey = Protocol.encodePartitionId(partitionId, 1);
final SetVariablesRequest request = SetVariablesRequest.newBuilder().setElementInstanceKey(elementInstanceKey).setVariables(variables).build();
// when
final SetVariablesResponse response = client.setVariables(request);
// then
assertThat(response).isNotNull();
assertThat(response.getKey()).isEqualTo(stub.getKey());
final BrokerSetVariablesRequest brokerRequest = brokerClient.getSingleBrokerRequest();
assertThat(brokerRequest.getKey()).isEqualTo(-1);
assertThat(brokerRequest.getIntent()).isEqualTo(VariableDocumentIntent.UPDATE);
assertThat(brokerRequest.getValueType()).isEqualTo(ValueType.VARIABLE_DOCUMENT);
assertThat(brokerRequest.getPartitionId()).isEqualTo(partitionId);
final VariableDocumentRecord brokerRequestValue = brokerRequest.getRequestWriter();
MsgPackUtil.assertEqualityExcluding(brokerRequestValue.getVariablesBuffer(), variables);
assertThat(brokerRequestValue.getScopeKey()).isEqualTo(elementInstanceKey);
}
use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest 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();
}
Aggregations