@Override protected Query<VariableInstanceQuery, VariableInstance> baseQueryForBinaryVariable() { return baseQuery().disableCustomObjectDeserialization(); }
@Override protected Query<VariableInstanceQuery, VariableInstance> baseQueryForBinaryVariable() { return baseQuery().disableCustomObjectDeserialization(); }
@Override protected Query<VariableInstanceQuery, VariableInstance> baseQueryForVariable(boolean deserializeObjectValue) { VariableInstanceQuery baseQuery = baseQuery(); // do not fetch byte arrays baseQuery.disableBinaryFetching(); if (!deserializeObjectValue) { baseQuery.disableCustomObjectDeserialization(); } return baseQuery; }
@Override protected Query<VariableInstanceQuery, VariableInstance> baseQueryForVariable(boolean deserializeObjectValue) { VariableInstanceQuery baseQuery = baseQuery(); // do not fetch byte arrays baseQuery.disableBinaryFetching(); if (!deserializeObjectValue) { baseQuery.disableCustomObjectDeserialization(); } return baseQuery; }
protected List<VariableInstance> queryVariablesInstancesByVariableScopeIds(Collection<String> variableNames, Collection<String> variableScopeIds) { IdentityService identityService = processEngine.getIdentityService(); Authentication currentAuthentication = identityService.getCurrentAuthentication(); try { identityService.clearAuthentication(); return getProcessEngine().getRuntimeService() .createVariableInstanceQuery() .disableBinaryFetching() .disableCustomObjectDeserialization() .variableNameIn(variableNames.toArray(new String[variableNames.size()])) .variableScopeIdIn(variableScopeIds.toArray(new String[variableScopeIds.size()])) .list(); } finally { identityService.setAuthentication(currentAuthentication); } }
protected List<VariableInstance> queryVariablesInstancesByVariableScopeIds(Collection<String> variableNames, Collection<String> variableScopeIds) { IdentityService identityService = processEngine.getIdentityService(); Authentication currentAuthentication = identityService.getCurrentAuthentication(); try { identityService.clearAuthentication(); return getProcessEngine().getRuntimeService() .createVariableInstanceQuery() .disableBinaryFetching() .disableCustomObjectDeserialization() .variableNameIn(variableNames.toArray(new String[variableNames.size()])) .variableScopeIdIn(variableScopeIds.toArray(new String[variableScopeIds.size()])) .list(); } finally { identityService.setAuthentication(currentAuthentication); } }
@Test public void testGetBinaryDataForNonExistingVariableInstance() { String nonExistingId = "nonExistingId"; when(variableInstanceQueryMock.variableId(nonExistingId)).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.disableCustomObjectDeserialization()).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.singleResult()).thenReturn(null); given().pathParam("id", nonExistingId) .then().expect().statusCode(Status.NOT_FOUND.getStatusCode()) .body(containsString("Variable instance with Id 'nonExistingId' does not exist.")) .when().get(VARIABLE_INSTANCE_BINARY_DATA_URL); verify(variableInstanceQueryMock, never()).disableBinaryFetching(); verify(variableInstanceQueryMock).disableCustomObjectDeserialization(); }
@Test public void testNoParametersQuery() { expect().statusCode(Status.OK.getStatusCode()).when().get(VARIABLE_INSTANCE_QUERY_URL); verify(mockedQuery).list(); verify(mockedQuery).disableBinaryFetching(); verify(mockedQuery, never()).disableCustomObjectDeserialization(); verifyNoMoreInteractions(mockedQuery); }
@Test public void testGetNonExistingVariableInstance() { String nonExistingId = "nonExistingId"; when(variableInstanceQueryMock.variableId(nonExistingId)).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.disableBinaryFetching()).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.disableCustomObjectDeserialization()).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.singleResult()).thenReturn(null); given().pathParam("id", nonExistingId) .then().expect().statusCode(Status.NOT_FOUND.getStatusCode()) .body(containsString("Variable instance with Id 'nonExistingId' does not exist.")) .when().get(VARIABLE_INSTANCE_URL); verify(variableInstanceQueryMock, times(1)).disableBinaryFetching(); }
@Test public void testBinaryDataForNonBinaryVariable() { VariableInstance variableInstanceMock = MockProvider.createMockVariableInstance(); when(variableInstanceQueryMock.variableId(variableInstanceMock.getId())).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.disableCustomObjectDeserialization()).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.singleResult()).thenReturn(variableInstanceMock); given().pathParam("id", MockProvider.EXAMPLE_VARIABLE_INSTANCE_ID) .then().expect() .statusCode(Status.BAD_REQUEST.getStatusCode()) .body(containsString("Value of variable with id aVariableInstanceId is not a binary value")) .when().get(VARIABLE_INSTANCE_BINARY_DATA_URL); verify(variableInstanceQueryMock, never()).disableBinaryFetching(); verify(variableInstanceQueryMock).disableCustomObjectDeserialization(); }
@Test public void testNoParametersQueryAsPost() { given().contentType(POST_JSON_CONTENT_TYPE).body(EMPTY_JSON_OBJECT) .expect().statusCode(Status.OK.getStatusCode()) .when().post(VARIABLE_INSTANCE_QUERY_URL); verify(mockedQuery).list(); verify(mockedQuery).disableBinaryFetching(); verify(mockedQuery, never()).disableCustomObjectDeserialization(); verifyNoMoreInteractions(mockedQuery); }
@Test public void testNoParametersQueryDisableObjectDeserialization() { given() .queryParam("deserializeValues", false) .expect() .statusCode(Status.OK.getStatusCode()) .when() .get(VARIABLE_INSTANCE_QUERY_URL); verify(mockedQuery).list(); verify(mockedQuery).disableBinaryFetching(); verify(mockedQuery).disableCustomObjectDeserialization(); verifyNoMoreInteractions(mockedQuery); }
/** * If parameter "maxResults" is missing, we expect Integer.MAX_VALUE as default. */ @Test public void testMissingMaxResultsParameter() { int firstResult = 10; given().queryParam("firstResult", firstResult) .then().expect().statusCode(Status.OK.getStatusCode()) .when().get(VARIABLE_INSTANCE_QUERY_URL); verify(mockedQuery).listPage(firstResult, Integer.MAX_VALUE); verify(mockedQuery).disableBinaryFetching(); // requirement to not break existing API; should be: // verify(variableInstanceQueryMock).disableCustomObjectDeserialization(); verify(mockedQuery, never()).disableCustomObjectDeserialization(); }
@Test public void testSuccessfulPagination() { int firstResult = 0; int maxResults = 10; given().queryParam("firstResult", firstResult).queryParam("maxResults", maxResults) .then().expect().statusCode(Status.OK.getStatusCode()) .when().get(VARIABLE_INSTANCE_QUERY_URL); verify(mockedQuery).listPage(firstResult, maxResults); verify(mockedQuery).disableBinaryFetching(); // requirement to not break existing API; should be: // verify(variableInstanceQueryMock).disableCustomObjectDeserialization(); verify(mockedQuery, never()).disableCustomObjectDeserialization(); }
/** * If parameter "firstResult" is missing, we expect 0 as default. */ @Test public void testMissingFirstResultParameter() { int maxResults = 10; given().queryParam("maxResults", maxResults) .then().expect().statusCode(Status.OK.getStatusCode()) .when().get(VARIABLE_INSTANCE_QUERY_URL); verify(mockedQuery).listPage(0, maxResults); verify(mockedQuery).disableBinaryFetching(); // requirement to not break existing API; should be: // verify(variableInstanceQueryMock).disableCustomObjectDeserialization(); verify(mockedQuery, never()).disableCustomObjectDeserialization(); }
@Test public void testBinaryDataForBinaryVariable() { final byte[] byteContent = "some bytes".getBytes(); VariableInstance variableInstanceMock = MockProvider.mockVariableInstance() .typedValue(Variables.byteArrayValue(byteContent)) .build(); when(variableInstanceQueryMock.variableId(variableInstanceMock.getId())).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.disableCustomObjectDeserialization()).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.singleResult()).thenReturn(variableInstanceMock); Response response = given().pathParam("id", MockProvider.EXAMPLE_VARIABLE_INSTANCE_ID) .then().expect() .statusCode(Status.OK.getStatusCode()) .contentType(ContentType.BINARY.toString()) .when().get(VARIABLE_INSTANCE_BINARY_DATA_URL); byte[] responseBytes = response.getBody().asByteArray(); Assert.assertEquals(new String(byteContent), new String(responseBytes)); verify(variableInstanceQueryMock, never()).disableBinaryFetching(); verify(variableInstanceQueryMock).disableCustomObjectDeserialization(); }
@Test public void testNoParametersQueryAsPostDisableObjectDeserialization() { given() .queryParam("deserializeValues", false) .contentType(POST_JSON_CONTENT_TYPE) .body(EMPTY_JSON_OBJECT) .expect() .statusCode(Status.OK.getStatusCode()) .when() .post(VARIABLE_INSTANCE_QUERY_URL); verify(mockedQuery).list(); verify(mockedQuery).disableBinaryFetching(); verify(mockedQuery).disableCustomObjectDeserialization(); verifyNoMoreInteractions(mockedQuery); }
@Test public void testMultipleVariableParameters() { String variableName1 = "varName"; String variableValue1 = "varValue"; String variableParameter1 = variableName1 + "_eq_" + variableValue1; String variableName2 = "anotherVarName"; String variableValue2 = "anotherVarValue"; String variableParameter2 = variableName2 + "_neq_" + variableValue2; String queryValue = variableParameter1 + "," + variableParameter2; given().queryParam("variableValues", queryValue) .then().expect().statusCode(Status.OK.getStatusCode()) .when().get(VARIABLE_INSTANCE_QUERY_URL); verify(mockedQuery).variableValueEquals(variableName1, variableValue1); verify(mockedQuery).variableValueNotEquals(variableName2, variableValue2); verify(mockedQuery).disableBinaryFetching(); // requirement to not break existing API; should be: // verify(variableInstanceQueryMock).disableCustomObjectDeserialization(); verify(mockedQuery, never()).disableCustomObjectDeserialization(); }
@Test public void testGetSingleVariableInstanceForBinaryVariable() { MockVariableInstanceBuilder builder = MockProvider.mockVariableInstance(); VariableInstance variableInstanceMock = builder .typedValue(Variables.byteArrayValue(null)) .build(); when(variableInstanceQueryMock.variableId(variableInstanceMock.getId())).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.disableBinaryFetching()).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.disableCustomObjectDeserialization()).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.singleResult()).thenReturn(variableInstanceMock); given().pathParam("id", MockProvider.EXAMPLE_VARIABLE_INSTANCE_ID) .then().expect().statusCode(Status.OK.getStatusCode()) .and() .body("type", equalTo(VariableTypeHelper.toExpectedValueTypeName(ValueType.BYTES))) .body("value", nullValue()) .when().get(VARIABLE_INSTANCE_URL); verify(variableInstanceQueryMock, times(1)).disableBinaryFetching(); }
@Test public void testGetBinaryDataForNullFileVariable() { String filename = "test.txt"; byte[] byteContent = null; FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(ContentType.TEXT.toString()).create(); MockVariableInstanceBuilder builder = MockProvider.mockVariableInstance(); VariableInstance variableInstanceMock = builder .typedValue(variableValue) .build(); when(variableInstanceQueryMock.variableId(variableInstanceMock.getId())).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.disableBinaryFetching()).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.disableCustomObjectDeserialization()).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.singleResult()).thenReturn(variableInstanceMock); given().pathParam("id", MockProvider.EXAMPLE_VARIABLE_INSTANCE_ID) .then().expect().statusCode(Status.OK.getStatusCode()) .and() .contentType(ContentType.TEXT) .and() .body(is(equalTo(new String()))) .when().get(VARIABLE_INSTANCE_BINARY_DATA_URL); }