use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class TaskVariableLocalRestResourceInteractionTest method testPostSingleLocalFileVariableWithMimeType.
@Test
public void testPostSingleLocalFileVariableWithMimeType() throws Exception {
byte[] value = "some text".getBytes();
String base64 = Base64.encodeBase64String(value);
String variableKey = "aVariableKey";
String filename = "test.txt";
String mimetype = MediaType.TEXT_PLAIN;
given().pathParam("id", EXAMPLE_TASK_ID).pathParam("varId", variableKey).multiPart("data", filename, value, mimetype).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).setVariableLocal(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(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 VariableInstanceRestServiceInteractionTest method testGetBinaryDataForNullFileVariable.
@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);
}
use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class ProcessEngineRestServiceTest method testHistoryServiceEngineAccess_HistoricDetailBinaryFile.
@Ignore
@Test
public void testHistoryServiceEngineAccess_HistoricDetailBinaryFile() {
HistoricDetailQuery query = mock(HistoricDetailQuery.class);
HistoricVariableUpdate instance = mock(HistoricVariableUpdate.class);
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();
when(instance.getTypedValue()).thenReturn(variableValue);
when(query.singleResult()).thenReturn(instance);
when(mockHistoryService.createHistoricDetailQuery()).thenReturn(query);
given().pathParam("name", EXAMPLE_ENGINE_NAME).then().expect().statusCode(Status.OK.getStatusCode()).body(is(equalTo(new String(byteContent)))).and().header("Content-Disposition", "attachment; filename=" + filename).contentType(CoreMatchers.<String>either(equalTo(ContentType.TEXT.toString() + ";charset=UTF-8")).or(equalTo(ContentType.TEXT.toString() + " ;charset=UTF-8"))).when().get(HISTORY_BINARY_DETAIL_URL);
verify(mockHistoryService).createHistoricDetailQuery();
verifyZeroInteractions(processEngine);
}
use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class CaseExecutionRestServiceInteractionTest method testPostSingleLocalFileVariableOnlyFilename.
@Test
public void testPostSingleLocalFileVariableOnlyFilename() throws Exception {
String variableKey = "aVariableKey";
String filename = "test.txt";
given().pathParam("id", MockProvider.EXAMPLE_CASE_EXECUTION_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_CASE_EXECUTION_LOCAL_BINARY_VARIABLE_URL);
ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
verify(caseServiceMock).withCaseExecution(MockProvider.EXAMPLE_CASE_EXECUTION_ID);
verify(caseExecutionCommandBuilderMock).setVariableLocal(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));
}
use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class CaseInstanceRestServiceInteractionTest method testGetFileVariableDownloadWithTypeAndEncoding.
@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(caseServiceMock.getVariableTyped(eq(MockProvider.EXAMPLE_CASE_INSTANCE_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue);
Response response = given().pathParam("id", MockProvider.EXAMPLE_CASE_INSTANCE_ID).pathParam("varId", variableKey).then().expect().statusCode(Status.OK.getStatusCode()).body(is(equalTo(new String(byteContent)))).when().get(SINGLE_CASE_INSTANCE_BINARY_VARIABLE_URL);
String contentType = response.contentType().replaceAll(" ", "");
assertThat(contentType, is(ContentType.TEXT + ";charset=" + encoding));
}
Aggregations