UpdateVariableDocumentProcessor implements CommandProcessor<VariableDocumentRecord> { @Override public boolean onCommand( final TypedRecord<VariableDocumentRecord> command, final CommandControl<VariableDocumentRecord> controller) { final VariableDocumentRecord record = command.getValue(); final ElementInstance scope = elementInstanceState.getInstance(record.getScopeKey()); if (scope == null || scope.isTerminating() || scope.isInFinalState()) { controller.reject( RejectionType.NOT_FOUND, String.format( "Expected to update variables for element with key '%d', but no such element was found", record.getScopeKey())); return true; } final long workflowKey = scope.getValue().getWorkflowKey(); if (mergeDocument(record, workflowKey, controller)) { controller.accept(VariableDocumentIntent.UPDATED, record); } return true; } UpdateVariableDocumentProcessor(
      final ElementInstanceState elementInstanceState, final VariablesState variablesState); @Override boolean onCommand(
      final TypedRecord<VariableDocumentRecord> command,
      final CommandControl<VariableDocumentRecord> controller);  }
@Test public void shouldRejectIfNoScopeFound() { final TypedRecord<VariableDocumentRecord> command = newCommand(VariableDocumentRecord.class); command.getValue().setScopeKey(1); processor.onCommand(command, controller); refuteAccepted(); assertRejected(RejectionType.NOT_FOUND); }
@Test public void shouldRejectOnMsgpackReadError() { final ElementInstance instance = newElementInstance(); final TypedRecord<VariableDocumentRecord> command = newCommand(VariableDocumentRecord.class); final MutableDirectBuffer badDocument = new UnsafeBuffer(asMsgPack("{}")); command .getValue() .setScopeKey(instance.getKey()) .setUpdateSemantics(VariableDocumentUpdateSemantic.PROPAGATE) .setVariables(badDocument); badDocument.putByte(0, (byte) 0); processor.onCommand(command, controller); refuteAccepted(); assertRejected(RejectionType.INVALID_ARGUMENT); }
@Test public void shouldApplyPropagateUpdateOperation() { final DirectBuffer variables = asMsgPack("a", 1); final ElementInstance instance = newElementInstance(); final TypedRecord<VariableDocumentRecord> command = newCommand(VariableDocumentRecord.class); command .getValue() .setScopeKey(instance.getKey()) .setUpdateSemantics(VariableDocumentUpdateSemantic.PROPAGATE) .setVariables(variables); processor.onCommand(command, controller); verify(variablesState, times(1)) .setVariablesFromDocument(instance.getKey(), WORKFLOW_KEY, variables); }
@Test public void shouldApplyLocalUpdateOperation() { final DirectBuffer variables = asMsgPack("a", 1); final ElementInstance instance = newElementInstance(); final TypedRecord<VariableDocumentRecord> command = newCommand(VariableDocumentRecord.class); command .getValue() .setScopeKey(instance.getKey()) .setUpdateSemantics(VariableDocumentUpdateSemantic.LOCAL) .setVariables(variables); processor.onCommand(command, controller); verify(variablesState, times(1)) .setVariablesLocalFromDocument(instance.getKey(), WORKFLOW_KEY, variables); }
@Test public void shouldPublishUpdatedRecord() { final DirectBuffer variables = asMsgPack("a", 1); final ElementInstance instance = newElementInstance(); final TypedRecord<VariableDocumentRecord> command = newCommand(VariableDocumentRecord.class); command .getValue() .setScopeKey(instance.getKey()) .setUpdateSemantics(VariableDocumentUpdateSemantic.PROPAGATE) .setVariables(variables); processor.onCommand(command, controller); refuteRejected(); assertAccepted(VariableDocumentIntent.UPDATED, command.getValue()); }