@Override protected Query<HistoricVariableInstanceQuery, HistoricVariableInstance> baseQueryForBinaryVariable() { return baseQuery().disableCustomObjectDeserialization(); }
@Override protected Query<HistoricVariableInstanceQuery, HistoricVariableInstance> baseQueryForBinaryVariable() { return baseQuery().disableCustomObjectDeserialization(); }
@Override protected Query<HistoricVariableInstanceQuery, HistoricVariableInstance> baseQueryForVariable(boolean deserializeObjectValue) { HistoricVariableInstanceQuery query = baseQuery().disableBinaryFetching(); if (!deserializeObjectValue) { query.disableCustomObjectDeserialization(); } return query; }
@Override protected Query<HistoricVariableInstanceQuery, HistoricVariableInstance> baseQueryForVariable(boolean deserializeObjectValue) { HistoricVariableInstanceQuery query = baseQuery().disableBinaryFetching(); if (!deserializeObjectValue) { query.disableCustomObjectDeserialization(); } return query; }
@Override public List<HistoricVariableInstanceDto> queryHistoricVariableInstances(HistoricVariableInstanceQueryDto queryDto, Integer firstResult, Integer maxResults, boolean deserializeObjectValues) { queryDto.setObjectMapper(objectMapper); HistoricVariableInstanceQuery query = queryDto.toQuery(processEngine); query.disableBinaryFetching(); if (!deserializeObjectValues) { query.disableCustomObjectDeserialization(); } List<HistoricVariableInstance> matchingHistoricVariableInstances; if (firstResult != null || maxResults != null) { matchingHistoricVariableInstances = executePaginatedQuery(query, firstResult, maxResults); } else { matchingHistoricVariableInstances = query.list(); } List<HistoricVariableInstanceDto> historicVariableInstanceDtoResults = new ArrayList<HistoricVariableInstanceDto>(); for (HistoricVariableInstance historicVariableInstance : matchingHistoricVariableInstances) { HistoricVariableInstanceDto resultHistoricVariableInstance = HistoricVariableInstanceDto.fromHistoricVariableInstance(historicVariableInstance); historicVariableInstanceDtoResults.add(resultHistoricVariableInstance); } return historicVariableInstanceDtoResults; }
@Override public List<HistoricVariableInstanceDto> queryHistoricVariableInstances(HistoricVariableInstanceQueryDto queryDto, Integer firstResult, Integer maxResults, boolean deserializeObjectValues) { queryDto.setObjectMapper(objectMapper); HistoricVariableInstanceQuery query = queryDto.toQuery(processEngine); query.disableBinaryFetching(); if (!deserializeObjectValues) { query.disableCustomObjectDeserialization(); } List<HistoricVariableInstance> matchingHistoricVariableInstances; if (firstResult != null || maxResults != null) { matchingHistoricVariableInstances = executePaginatedQuery(query, firstResult, maxResults); } else { matchingHistoricVariableInstances = query.list(); } List<HistoricVariableInstanceDto> historicVariableInstanceDtoResults = new ArrayList<HistoricVariableInstanceDto>(); for (HistoricVariableInstance historicVariableInstance : matchingHistoricVariableInstances) { HistoricVariableInstanceDto resultHistoricVariableInstance = HistoricVariableInstanceDto.fromHistoricVariableInstance(historicVariableInstance); historicVariableInstanceDtoResults.add(resultHistoricVariableInstance); } return historicVariableInstanceDtoResults; }
@Test public void testNoParametersQuery() { expect() .statusCode(Status.OK.getStatusCode()) .when() .get(HISTORIC_VARIABLE_INSTANCE_RESOURCE_URL); verify(mockedQuery).list(); verify(mockedQuery).disableBinaryFetching(); verify(mockedQuery, never()).disableCustomObjectDeserialization(); verifyNoMoreInteractions(mockedQuery); }
@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("Historic variable instance with Id 'nonExistingId' does not exist.")) .when().get(VARIABLE_INSTANCE_BINARY_DATA_URL); verify(variableInstanceQueryMock, never()).disableBinaryFetching(); }
@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("Historic variable instance with Id 'nonExistingId' does not exist.")) .when().get(VARIABLE_INSTANCE_URL); verify(variableInstanceQueryMock, times(1)).disableBinaryFetching(); }
@Test public void testNoParametersQueryDisableObjectDeserialization() { given() .queryParam("deserializeValues", false) .expect() .statusCode(Status.OK.getStatusCode()) .when() .get(HISTORIC_VARIABLE_INSTANCE_RESOURCE_URL); verify(mockedQuery).list(); verify(mockedQuery).disableBinaryFetching(); verify(mockedQuery).disableCustomObjectDeserialization(); verifyNoMoreInteractions(mockedQuery); }
@Test public void testBinaryDataForNonBinaryVariable() { HistoricVariableInstance variableInstanceMock = MockProvider.createMockHistoricVariableInstance(); 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 "+variableInstanceMock.getId()+" is not a binary value")) .when().get(VARIABLE_INSTANCE_BINARY_DATA_URL); verify(variableInstanceQueryMock, never()).disableBinaryFetching(); }
@Test public void testNoParametersQueryAsPost() { given() .contentType(POST_JSON_CONTENT_TYPE) .body(EMPTY_JSON_OBJECT) .expect() .statusCode(Status.OK.getStatusCode()) .when() .post(HISTORIC_VARIABLE_INSTANCE_RESOURCE_URL); verify(mockedQuery).list(); verify(mockedQuery).disableBinaryFetching(); verify(mockedQuery, never()).disableCustomObjectDeserialization(); verifyNoMoreInteractions(mockedQuery); }
@Test public void testGetSingleVariableInstanceForBinaryVariable() { MockHistoricVariableInstanceBuilder builder = MockProvider.mockHistoricVariableInstance(); HistoricVariableInstance 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 testNoParametersQueryAsPostDisableObjectDeserialization() { given() .queryParam("deserializeValues", false) .contentType(POST_JSON_CONTENT_TYPE) .body(EMPTY_JSON_OBJECT) .expect() .statusCode(Status.OK.getStatusCode()) .when() .post(HISTORIC_VARIABLE_INSTANCE_RESOURCE_URL); verify(mockedQuery).list(); verify(mockedQuery).disableBinaryFetching(); verify(mockedQuery).disableCustomObjectDeserialization(); verifyNoMoreInteractions(mockedQuery); }
@Test public void testBinaryDataForBinaryVariable() { final byte[] byteContent = "some bytes".getBytes(); HistoricVariableInstance variableInstanceMock = MockProvider.mockHistoricVariableInstance() .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(); }
@Test public void testGetBinaryDataForFileVariable() { String filename = "test.txt"; byte[] byteContent = "test".getBytes(); String encoding = "UTF-8"; FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(ContentType.TEXT.toString()).encoding(encoding).create(); HistoricVariableInstance variableInstanceMock = MockProvider.mockHistoricVariableInstance().typedValue(variableValue).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()) .and() .body(is(equalTo(new String(byteContent)))) .header("Content-Disposition", "attachment; filename="+filename) .when().get(VARIABLE_INSTANCE_BINARY_DATA_URL); //due to some problems with wildfly we gotta check this separately String contentType = response.getContentType(); assertThat(contentType, is(either(CoreMatchers.<Object>equalTo(ContentType.TEXT.toString() + "; charset=UTF-8")).or(CoreMatchers.<Object>equalTo(ContentType.TEXT.toString() + ";charset=UTF-8")))); verify(variableInstanceQueryMock, never()).disableBinaryFetching(); }
@Test public void testGetBinaryDataForNullFileVariable() { String filename = "test.txt"; byte[] byteContent = null; FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(ContentType.TEXT.toString()).create(); HistoricVariableInstance variableInstanceMock = MockProvider.mockHistoricVariableInstance() .typedValue(variableValue) .build(); 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.OK.getStatusCode()) .and().contentType(ContentType.TEXT) .and().body(is(equalTo(new String()))) .when().get(VARIABLE_INSTANCE_BINARY_DATA_URL); }
@Test public void testSerializableVariableInstanceRetrieval() { MockHistoricVariableInstanceBuilder builder = MockProvider.mockHistoricVariableInstance() .typedValue(MockObjectValue.fromObjectValue(Variables .objectValue("a serialized value") .serializationDataFormat(Variables.SerializationDataFormats.JAVA) .create()) .objectTypeName(String.class.getName())); List<HistoricVariableInstance> mockInstances = new ArrayList<HistoricVariableInstance>(); mockInstances.add(builder.build()); mockedQuery = setUpMockHistoricVariableInstanceQuery(mockInstances); given() .then().expect().statusCode(Status.OK.getStatusCode()) .and() .body("[0].type", equalTo(VariableTypeHelper.toExpectedValueTypeName(ValueType.OBJECT))) .body("[0].value", equalTo("a serialized value")) .body("[0].valueInfo." + SerializableValueType.VALUE_INFO_OBJECT_TYPE_NAME, equalTo(String.class.getName())) .body("[0].valueInfo." + SerializableValueType.VALUE_INFO_SERIALIZATION_DATA_FORMAT, equalTo(Variables.SerializationDataFormats.JAVA.getName())) .when().get(HISTORIC_VARIABLE_INSTANCE_RESOURCE_URL); // should not resolve custom objects but existing API requires it // verify(mockedQuery).disableCustomObjectDeserialization(); verify(mockedQuery, never()).disableCustomObjectDeserialization(); }
when(variableInstanceQueryMock.disableCustomObjectDeserialization()).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.singleResult()).thenReturn(variableInstanceMock);
@Test @OperateOnDeployment("clientDeployment") public void testVariableDeserializationOnProcessApplicationRestart() { // given ProcessInstance pi = runtimeService.startProcessInstanceByKey("testDeserializeVariable"); // when Assert.assertNull(runtimeService.createProcessInstanceQuery().processInstanceId(pi.getId()).singleResult()); runtimeService.restartProcessInstances(pi.getProcessDefinitionId()) .startAfterActivity("servicetask1") .processInstanceIds(pi.getId()) .execute(); // then // Since the variable retrieval is done outside the Process Application Context as well, // custom object deserialization is disabled and a null check is performed List<HistoricVariableInstance> variableInstances = historyService.createHistoricVariableInstanceQuery().disableCustomObjectDeserialization().list(); for (HistoricVariableInstance variable : variableInstances) { if (variable.getProcessInstanceId() != pi.getId() && variable instanceof HistoricVariableInstanceEntity) { Assert.assertNotNull(((HistoricVariableInstanceEntity) variable).getByteArrayValue()); } } } }