private void assertThatUpdateHasAllImportantInformation(HistoricVariableUpdate variableUpdate) { assertThat(variableUpdate, notNullValue()); assertThat(variableUpdate.getId(), notNullValue()); assertThat(variableUpdate.getProcessDefinitionKey(), is("process")); assertThat(variableUpdate.getProcessDefinitionId(), notNullValue()); assertThat(variableUpdate.getVariableName(), is("stringVar")); assertThat(variableUpdate.getValue().toString(), is("foo")); assertThat(variableUpdate.getTypeName(), is("string")); assertThat(variableUpdate.getTime(), notNullValue()); }
@Test public void testBinaryDataForNonBinaryVariable() { HistoricVariableUpdate detailMock = MockProvider.createMockHistoricVariableUpdate(); when(historicDetailQueryMock.detailId(detailMock.getId())).thenReturn(historicDetailQueryMock); when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock); when(historicDetailQueryMock.singleResult()).thenReturn(detailMock); given().pathParam("id", MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_ID) .then().expect() .statusCode(Status.BAD_REQUEST.getStatusCode()) .body(containsString("Value of variable with id aHistoricVariableUpdateId is not a binary value")) .when().get(VARIABLE_INSTANCE_BINARY_DATA_URL); verify(historicDetailQueryMock, never()).disableBinaryFetching(); }
public HistoricVariableUpdate build() { HistoricVariableUpdate mockVariable = mock(HistoricVariableUpdate.class); when(mockVariable.getId()).thenReturn(id); when(mockVariable.getVariableName()).thenReturn(name); when(mockVariable.getVariableInstanceId()).thenReturn(variableInstanceId);
@Test public void testBinaryDataForBinaryVariable() { final byte[] byteContent = "some bytes".getBytes(); MockHistoricVariableUpdateBuilder builder = MockProvider.mockHistoricVariableUpdate(); HistoricVariableUpdate detailMock = builder .typedValue(Variables.byteArrayValue(byteContent)) .build(); when(historicDetailQueryMock.detailId(detailMock.getId())).thenReturn(historicDetailQueryMock); when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock); when(historicDetailQueryMock.singleResult()).thenReturn(detailMock); Response response = given().pathParam("id", MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_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(historicDetailQueryMock, never()).disableBinaryFetching(); }
@Test public void testBinaryDataForFileVariable() { 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(); MockHistoricVariableUpdateBuilder builder = MockProvider.mockHistoricVariableUpdate(); HistoricVariableUpdate detailMock = builder .typedValue(variableValue) .build(); when(historicDetailQueryMock.detailId(detailMock.getId())).thenReturn(historicDetailQueryMock); when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock); when(historicDetailQueryMock.singleResult()).thenReturn(detailMock); Response response = given().pathParam("id", MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_ID) .then().expect() .statusCode(Status.OK.getStatusCode()) . body(is(equalTo(new String(byteContent)))) .and() .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(historicDetailQueryMock, 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(); MockHistoricVariableUpdateBuilder builder = MockProvider.mockHistoricVariableUpdate(); HistoricVariableUpdate detailMock = builder .typedValue(variableValue) .build(); when(historicDetailQueryMock.detailId(detailMock.getId())).thenReturn(historicDetailQueryMock); when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock); when(historicDetailQueryMock.singleResult()).thenReturn(detailMock); given().pathParam("id", MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_ID) .then().expect().statusCode(Status.OK.getStatusCode()) .and() .contentType(ContentType.TEXT) .and() .body(is(equalTo(new String()))) .when() .get(VARIABLE_INSTANCE_BINARY_DATA_URL); } }
.build(); when(historicDetailQueryMock.detailId(detailMock.getId())).thenReturn(historicDetailQueryMock); when(historicDetailQueryMock.disableBinaryFetching()).thenReturn(historicDetailQueryMock); when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock);
when(historicDetailQueryMock.detailId(detailMock.getId())).thenReturn(historicDetailQueryMock); when(historicDetailQueryMock.disableBinaryFetching()).thenReturn(historicDetailQueryMock); when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock);
HistoricVariableUpdate variableInstanceMock = builder.build(); when(historicDetailQueryMock.detailId(variableInstanceMock.getId())).thenReturn(historicDetailQueryMock); when(historicDetailQueryMock.disableBinaryFetching()).thenReturn(historicDetailQueryMock); when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock);
HistoricVariableUpdate variableInstanceMock = builder.build(); when(historicDetailQueryMock.detailId(variableInstanceMock.getId())).thenReturn(historicDetailQueryMock); when(historicDetailQueryMock.disableBinaryFetching()).thenReturn(historicDetailQueryMock); when(historicDetailQueryMock.singleResult()).thenReturn(variableInstanceMock);
private void assertThatUpdateHasAllImportantInformation(HistoricVariableUpdate variableUpdate) { assertThat(variableUpdate, notNullValue()); assertThat(variableUpdate.getId(), notNullValue()); assertThat(variableUpdate.getProcessDefinitionKey(), is("process")); assertThat(variableUpdate.getProcessDefinitionId(), notNullValue()); assertThat(variableUpdate.getVariableName(), is("stringVar")); assertThat(variableUpdate.getValue().toString(), is("foo")); assertThat(variableUpdate.getTypeName(), is("string")); assertThat(variableUpdate.getTime(), notNullValue()); }