@Override public <T extends TypedValue> T getVariableLocalTyped(String executionId, String variableName) { return getVariableLocalTyped(executionId, variableName, true); }
@Override public <T extends TypedValue> T getVariableLocalTyped(String executionId, String variableName) { return getVariableLocalTyped(executionId, variableName, true); }
@Test public void testGetSingleLocalVariabledataNotBinary() { when(runtimeServiceMock.getVariableLocalTyped(anyString(), eq(EXAMPLE_VARIABLE_KEY), eq(false))).thenReturn(EXAMPLE_VARIABLE_VALUE); given() .pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID) .pathParam("varId", EXAMPLE_VARIABLE_KEY) .then() .expect() .statusCode(Status.BAD_REQUEST.getStatusCode()) .when() .get(SINGLE_EXECUTION_LOCAL_BINARY_VARIABLE_URL); verify(runtimeServiceMock).getVariableLocalTyped(MockProvider.EXAMPLE_EXECUTION_ID, EXAMPLE_VARIABLE_KEY, false); }
@Test public void testGetSingleLocalVariableDataNonExisting() { when(runtimeServiceMock.getVariableLocalTyped(anyString(), eq("nonExisting"), eq(false))).thenReturn(null); given() .pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID) .pathParam("varId", "nonExisting") .then() .expect() .statusCode(Status.NOT_FOUND.getStatusCode()) .body("type", is(InvalidRequestException.class.getSimpleName())) .body("message", is("execution variable with name " + "nonExisting" + " does not exist")) .when() .get(SINGLE_EXECUTION_LOCAL_BINARY_VARIABLE_URL); verify(runtimeServiceMock).getVariableLocalTyped(MockProvider.EXAMPLE_EXECUTION_ID, "nonExisting", false); }
@Test public void testGetSingleLocalVariableData() { when(runtimeServiceMock.getVariableLocalTyped(anyString(), eq(EXAMPLE_BYTES_VARIABLE_KEY), eq(false))).thenReturn(EXAMPLE_VARIABLE_VALUE_BYTES); given() .pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID) .pathParam("varId", EXAMPLE_BYTES_VARIABLE_KEY) .then() .expect() .statusCode(Status.OK.getStatusCode()) .contentType(MediaType.APPLICATION_OCTET_STREAM) .when() .get(SINGLE_EXECUTION_LOCAL_BINARY_VARIABLE_URL); verify(runtimeServiceMock).getVariableLocalTyped(MockProvider.EXAMPLE_EXECUTION_ID, EXAMPLE_BYTES_VARIABLE_KEY, false); }
@Test public void testGetLocalVariableForNonExistingExecution() { String variableKey = "aVariableKey"; when(runtimeServiceMock.getVariableLocalTyped(eq(MockProvider.EXAMPLE_EXECUTION_ID), eq(variableKey), eq(true))) .thenThrow(new ProcessEngineException("expected exception")); given().pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID).pathParam("varId", variableKey) .then().expect().statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()) .body("type", is(RestException.class.getSimpleName())) .body("message", is("Cannot get execution variable " + variableKey + ": expected exception")) .when().get(SINGLE_EXECUTION_LOCAL_VARIABLE_URL); }
@Test public void testGetSingleLocalVariable() { String variableKey = "aVariableKey"; int variableValue = 123; when(runtimeServiceMock.getVariableLocalTyped(eq(MockProvider.EXAMPLE_EXECUTION_ID), eq(variableKey), anyBoolean())).thenReturn(Variables.integerValue(variableValue)); given().pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID).pathParam("varId", variableKey) .then().expect().statusCode(Status.OK.getStatusCode()) .body("value", is(123)) .body("type", is("Integer")) .when().get(SINGLE_EXECUTION_LOCAL_VARIABLE_URL); }
@Test public void testCannotDownloadVariableOtherThanFile() { String variableKey = "aVariableKey"; BooleanValue variableValue = Variables.booleanValue(true); when(runtimeServiceMock.getVariableLocalTyped(eq(EXAMPLE_TASK_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue); given() .pathParam("id", EXAMPLE_TASK_ID) .pathParam("varId", variableKey) .then().expect() .statusCode(Status.BAD_REQUEST.getStatusCode()) .when().get(SINGLE_EXECUTION_LOCAL_BINARY_VARIABLE_URL); }
@Test public void testGetLocalVariableThrowsAuthorizationException() { String variableKey = "aVariableKey"; String message = "expected exception"; doThrow(new AuthorizationException(message)).when(runtimeServiceMock).getVariableLocalTyped(anyString(), anyString(), anyBoolean()); given() .pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID) .pathParam("varId", variableKey) .then().expect() .statusCode(Status.FORBIDDEN.getStatusCode()) .contentType(ContentType.JSON) .body("type", equalTo(AuthorizationException.class.getSimpleName())) .body("message", equalTo(message)) .when() .get(SINGLE_EXECUTION_LOCAL_VARIABLE_URL); }
@Test public void testGetSingleLocalObjectVariableSerialized() { // given String variableKey = "aVariableId"; ObjectValue variableValue = Variables .serializedObjectValue("a serialized value") .serializationDataFormat("application/json") .objectTypeName(ArrayList.class.getName()) .create(); when(runtimeServiceMock.getVariableLocalTyped(eq(MockProvider.EXAMPLE_EXECUTION_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue); // when given() .pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID) .pathParam("varId", variableKey) .queryParam("deserializeValue", false) .then().expect().statusCode(Status.OK.getStatusCode()) .body("value", equalTo("a serialized value")) .body("type", equalTo("Object")) .body("valueInfo." + SerializableValueType.VALUE_INFO_SERIALIZATION_DATA_FORMAT, equalTo("application/json")) .body("valueInfo." + SerializableValueType.VALUE_INFO_OBJECT_TYPE_NAME, equalTo(ArrayList.class.getName())) .when().get(SINGLE_EXECUTION_LOCAL_VARIABLE_URL); // then verify(runtimeServiceMock).getVariableLocalTyped(MockProvider.EXAMPLE_EXECUTION_ID, variableKey, false); }
@Test public void testGetFileVariableDownloadWithoutType() { String variableKey = "aVariableKey"; final byte[] byteContent = "some bytes".getBytes(); String filename = "test.txt"; FileValue variableValue = Variables.fileValue(filename).file(byteContent).create(); when(runtimeServiceMock.getVariableLocalTyped(eq(MockProvider.EXAMPLE_EXECUTION_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue); given() .pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID) .pathParam("varId", variableKey) .then().expect() .statusCode(Status.OK.getStatusCode()) .contentType(MediaType.APPLICATION_OCTET_STREAM) .and() .body(is(equalTo(new String(byteContent)))) .header("Content-Disposition", containsString(filename)) .when().get(SINGLE_EXECUTION_LOCAL_BINARY_VARIABLE_URL); }
@Override public <T extends TypedValue> T getVariableLocalTyped(String executionId, String variableName) { return getVariableLocalTyped(executionId, variableName, true); }
@Test public void testGetSingleLocalObjectVariable() { // 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.getVariableLocalTyped(eq(MockProvider.EXAMPLE_EXECUTION_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue); // when given().pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID).pathParam("varId", variableKey) .then().expect().statusCode(Status.OK.getStatusCode()) .body("value", equalTo(payload)) .body("type", equalTo("Object")) .body("valueInfo." + SerializableValueType.VALUE_INFO_SERIALIZATION_DATA_FORMAT, equalTo("application/json")) .body("valueInfo." + SerializableValueType.VALUE_INFO_OBJECT_TYPE_NAME, equalTo(ArrayList.class.getName())) .when().get(SINGLE_EXECUTION_LOCAL_VARIABLE_URL); // then verify(runtimeServiceMock).getVariableLocalTyped(MockProvider.EXAMPLE_EXECUTION_ID, variableKey, true); }
@Test public void testGetFileVariableDownloadWithTypeAndEncoding() { String variableKey = "aVariableKey"; final byte[] byteContent = "some bytes".getBytes(); String filename = "test.txt"; String encoding = "UTF-8"; FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(ContentType.TEXT.toString()).encoding(encoding).create(); when(runtimeServiceMock.getVariableLocalTyped(eq(MockProvider.EXAMPLE_EXECUTION_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue); Response response = given() .pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID) .pathParam("varId", variableKey) .then().expect() .statusCode(Status.OK.getStatusCode()) .body(is(equalTo(new String(byteContent)))) .when().get(SINGLE_EXECUTION_LOCAL_BINARY_VARIABLE_URL); String contentType = response.contentType().replaceAll(" ", ""); assertThat(contentType, is(ContentType.TEXT + ";charset=" + encoding)); }
@Test public void testGetFileVariableDownloadWithType() { String variableKey = "aVariableKey"; final byte[] byteContent = "some bytes".getBytes(); String filename = "test.txt"; FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(ContentType.TEXT.toString()).create(); when(runtimeServiceMock.getVariableLocalTyped(eq(MockProvider.EXAMPLE_EXECUTION_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue); given() .pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID) .pathParam("varId", variableKey) .then().expect() .statusCode(Status.OK.getStatusCode()) .contentType(ContentType.TEXT.toString()) .and() .body(is(equalTo(new String(byteContent)))) .when().get(SINGLE_EXECUTION_LOCAL_BINARY_VARIABLE_URL); }
@Test public void testGetNullFileVariable() { String variableKey = "aVariableKey"; String filename = "test.txt"; String mimeType = "text/plain"; FileValue variableValue = Variables.fileValue(filename).mimeType(mimeType).create(); when(runtimeServiceMock.getVariableLocalTyped(eq(MockProvider.EXAMPLE_EXECUTION_ID), eq(variableKey), anyBoolean())) .thenReturn(variableValue); given() .pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID) .pathParam("varId", variableKey) .then().expect() .statusCode(Status.OK.getStatusCode()) .contentType(ContentType.TEXT.toString()) .and() .body(is(equalTo(""))) .when().get(SINGLE_EXECUTION_LOCAL_BINARY_VARIABLE_URL); }
@Test public void testGetFileVariable() { String variableKey = "aVariableKey"; final byte[] byteContent = "some bytes".getBytes(); String filename = "test.txt"; String mimeType = "text/plain"; FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(mimeType).create(); when(runtimeServiceMock.getVariableLocalTyped(eq(MockProvider.EXAMPLE_EXECUTION_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue); given() .pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID) .pathParam("varId", variableKey) .then().expect() .statusCode(Status.OK.getStatusCode()) .contentType(ContentType.JSON.toString()) .and() .body("valueInfo.mimeType", equalTo(mimeType)) .body("valueInfo.filename", equalTo(filename)) .body("value", nullValue()) .when().get(SINGLE_EXECUTION_LOCAL_VARIABLE_URL); }