use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class HistoricDetailRestServiceInteractionTest method testBinaryDataForFileVariable.
@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();
}
use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class TaskVariableRestResourceInteractionTest method testGetNullFileVariable.
@Test
public void testGetNullFileVariable() {
String variableKey = "aVariableKey";
String filename = "test.txt";
String mimeType = "text/plain";
FileValue variableValue = Variables.fileValue(filename).mimeType(mimeType).create();
when(taskServiceMock.getVariableTyped(eq(MockProvider.EXAMPLE_TASK_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue);
given().pathParam("id", MockProvider.EXAMPLE_TASK_ID).pathParam("varId", variableKey).then().expect().statusCode(Status.OK.getStatusCode()).contentType(ContentType.TEXT.toString()).and().body(is(equalTo(""))).when().get(SINGLE_TASK_SINGLE_BINARY_VARIABLE_URL);
}
use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class TaskVariableRestResourceInteractionTest method testGetFileVariableDownloadWithoutType.
@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(taskServiceMock.getVariableTyped(eq(EXAMPLE_TASK_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue);
given().pathParam("id", EXAMPLE_TASK_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_TASK_SINGLE_BINARY_VARIABLE_URL);
}
use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class TaskVariableRestResourceInteractionTest method testPostSingleFileVariableWithEncodingAndMimeType.
@Test
public void testPostSingleFileVariableWithEncodingAndMimeType() throws Exception {
byte[] value = "some text".getBytes();
String variableKey = "aVariableKey";
String encoding = "utf-8";
String filename = "test.txt";
String mimetype = MediaType.TEXT_PLAIN;
given().pathParam("id", EXAMPLE_TASK_ID).pathParam("varId", variableKey).multiPart("data", filename, value, mimetype + "; encoding=" + encoding).multiPart("valueType", "File", "text/plain").header("accept", MediaType.APPLICATION_JSON).expect().statusCode(Status.NO_CONTENT.getStatusCode()).when().post(SINGLE_TASK_SINGLE_BINARY_VARIABLE_URL);
ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
verify(taskServiceMock).setVariable(eq(MockProvider.EXAMPLE_TASK_ID), eq(variableKey), captor.capture());
FileValue captured = captor.getValue();
assertThat(captured.getEncoding(), is(encoding));
assertThat(captured.getFilename(), is(filename));
assertThat(captured.getMimeType(), is(mimetype));
assertThat(IoUtil.readInputStream(captured.getValue(), null), is(value));
}
use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class TaskVariableRestResourceInteractionTest method testPostSingleFileVariableOnlyFilename.
@Test
public void testPostSingleFileVariableOnlyFilename() throws Exception {
String variableKey = "aVariableKey";
String filename = "test.txt";
given().pathParam("id", EXAMPLE_TASK_ID).pathParam("varId", variableKey).multiPart("data", filename, new byte[0]).multiPart("valueType", "File", "text/plain").header("accept", MediaType.APPLICATION_JSON).expect().statusCode(Status.NO_CONTENT.getStatusCode()).when().post(SINGLE_TASK_SINGLE_BINARY_VARIABLE_URL);
ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
verify(taskServiceMock).setVariable(eq(MockProvider.EXAMPLE_TASK_ID), eq(variableKey), captor.capture());
FileValue captured = captor.getValue();
assertThat(captured.getEncoding(), is(nullValue()));
assertThat(captured.getFilename(), is(filename));
assertThat(captured.getMimeType(), is(MediaType.APPLICATION_OCTET_STREAM));
assertThat(captured.getValue().available(), is(0));
}
Aggregations