WorkflowInstance extends ModelObject { public String getStateVariable(String name) { return getStateVariable(name, (String) null); } WorkflowInstance(Builder builder); Map<String, String> getChangedStateVariables(); String getStateVariable(String name); T getStateVariable(String name, Class<T> valueType); @SuppressWarnings("unchecked") T getStateVariable(String name, Class<T> valueType, T defaultValue); String getStateVariable(String name, String defaultValue); final Long id; final Integer executorId; final Long parentWorkflowId; final Long parentActionId; final WorkflowInstanceStatus status; final String type; final Short priority; final String businessKey; final String externalId; final String state; final String stateText; final DateTime nextActivation; final Map<String, String> stateVariables; final Map<String, String> originalStateVariables; final List<WorkflowInstanceAction> actions; final int retries; final DateTime created; final DateTime modified; final DateTime started; final String executorGroup; final Optional<Integer> signal; public Map<Long, List<Long>> childWorkflows; }
@Test public void getTypedStateVariableFailsWithoutObjectMapper() { assertThrows(IllegalStateException.class, () -> { WorkflowInstance instance = new WorkflowInstance.Builder().build(); instance.getStateVariable("key", Long.class); }); }
@Test public void getStateVariableWorks() { WorkflowInstance instance = new WorkflowInstance.Builder().putStateVariable("key", "value").build(); assertThat(instance.getStateVariable("key"), is("value")); }
@Test public void getStateVariableWithDefaultValueWorks() { WorkflowInstance instance = new WorkflowInstance.Builder().build(); assertThat(instance.getStateVariable("key", "defaultValue"), is("defaultValue")); }
@Test public void getTypedStateVariableWorks() { when(mapper.convertFromObject("key", 42L)).thenReturn("42"); when(mapper.convertToObject(Long.class, "key", "42")).thenReturn(42L); WorkflowInstance instance = new WorkflowInstance.Builder(mapper).putStateVariable("key", 42L).build(); assertThat(instance.getStateVariable("key", Long.class), is(42L)); }
@Test public void getTypedStateVariableWithDefaultValueWorks() { WorkflowInstance instance = new WorkflowInstance.Builder(mapper).build(); assertThat(instance.getStateVariable("key", Long.class, 99L), is(99L)); }