@Override public VariableMap getVariablesLocal(String executionId) { return getVariablesLocalTyped(executionId); }
@Override public VariableMap getVariablesLocal(String executionId, Collection<String> variableNames) { return getVariablesLocalTyped(executionId, variableNames, true); }
@Override public VariableMap getVariablesLocalTyped(String executionId) { return getVariablesLocalTyped(executionId, true); }
@Override public VariableMap getVariablesLocal(String executionId) { return getVariablesLocalTyped(executionId); }
@Override public VariableMap getVariablesLocalTyped(String executionId) { return getVariablesLocalTyped(executionId, true); }
@Override public VariableMap getVariablesLocal(String executionId, Collection<String> variableNames) { return getVariablesLocalTyped(executionId, variableNames, true); }
@Before public void setUpRuntimeData() { runtimeServiceMock = mock(RuntimeServiceImpl.class); when(runtimeServiceMock.getVariablesLocalTyped(MockProvider.EXAMPLE_EXECUTION_ID, true)).thenReturn(EXAMPLE_VARIABLES); mockEventSubscriptionQuery(); when(processEngine.getRuntimeService()).thenReturn(runtimeServiceMock); }
@Test public void testGetLocalVariablesForNonExistingExecution() { when(runtimeServiceMock.getVariablesLocalTyped(anyString(), eq(true))).thenThrow(new ProcessEngineException("expected exception")); given().pathParam("id", "aNonExistingExecutionId") .then().expect().statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).contentType(ContentType.JSON) .body("type", equalTo(ProcessEngineException.class.getSimpleName())) .body("message", equalTo("expected exception")) .when().get(EXECUTION_LOCAL_VARIABLES_URL); }
@Test public void testGetLocalVariablesThrowsAuthorizationException() { String message = "expected exception"; doThrow(new AuthorizationException(message)).when(runtimeServiceMock).getVariablesLocalTyped(anyString(), anyBoolean()); given() .pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID) .then().expect() .statusCode(Status.FORBIDDEN.getStatusCode()) .contentType(ContentType.JSON) .body("type", equalTo(AuthorizationException.class.getSimpleName())) .body("message", equalTo(message)) .when() .get(EXECUTION_LOCAL_VARIABLES_URL); }
@Override public VariableMap getVariablesLocal(String executionId, Collection<String> variableNames) { return getVariablesLocalTyped(executionId, variableNames, true); }
@Override public VariableMap getVariablesLocal(String executionId) { return getVariablesLocalTyped(executionId); }
@Override public VariableMap getVariablesLocalTyped(String executionId) { return getVariablesLocalTyped(executionId, true); }
@Test public void testGetLocalObjectVariables() { // given String variableKey = "aVariableId"; List<String> payload = Arrays.asList("a", "b"); ObjectValue variableValue = MockObjectValue .fromObjectValue(Variables .objectValue(payload) .serializationDataFormat("application/json") .create()) .objectTypeName(ArrayList.class.getName()) .serializedValue("a serialized value"); // this should differ from the serialized json when(runtimeServiceMock.getVariablesLocalTyped(eq(MockProvider.EXAMPLE_EXECUTION_ID), anyBoolean())) .thenReturn(Variables.createVariables().putValueTyped(variableKey, variableValue)); // when given().pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID) .then().expect().statusCode(Status.OK.getStatusCode()) .body(variableKey + ".value", equalTo(payload)) .body(variableKey + ".type", equalTo("Object")) .body(variableKey + ".valueInfo." + SerializableValueType.VALUE_INFO_SERIALIZATION_DATA_FORMAT, equalTo("application/json")) .body(variableKey + ".valueInfo." + SerializableValueType.VALUE_INFO_OBJECT_TYPE_NAME, equalTo(ArrayList.class.getName())) .when().get(EXECUTION_LOCAL_VARIABLES_URL); // then verify(runtimeServiceMock).getVariablesLocalTyped(MockProvider.EXAMPLE_EXECUTION_ID, true); }
@Test public void testGetLocalObjectVariablesSerialized() { // given String variableKey = "aVariableId"; ObjectValue variableValue = Variables .serializedObjectValue("a serialized value") .serializationDataFormat("application/json") .objectTypeName(ArrayList.class.getName()) .create(); when(runtimeServiceMock.getVariablesLocalTyped(eq(MockProvider.EXAMPLE_EXECUTION_ID), anyBoolean())) .thenReturn(Variables.createVariables().putValueTyped(variableKey, variableValue)); // when given() .pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID) .queryParam("deserializeValues", false) .then().expect().statusCode(Status.OK.getStatusCode()) .body(variableKey + ".value", equalTo("a serialized value")) .body(variableKey + ".type", equalTo("Object")) .body(variableKey + ".valueInfo." + SerializableValueType.VALUE_INFO_SERIALIZATION_DATA_FORMAT, equalTo("application/json")) .body(variableKey + ".valueInfo." + SerializableValueType.VALUE_INFO_OBJECT_TYPE_NAME, equalTo(ArrayList.class.getName())) .when().get(EXECUTION_LOCAL_VARIABLES_URL); // then verify(runtimeServiceMock).getVariablesLocalTyped(MockProvider.EXAMPLE_EXECUTION_ID, false); }