use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class ExecutionRestServiceInteractionTest 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(runtimeServiceMock.getVariableLocalTyped(eq(MockProvider.EXAMPLE_EXECUTION_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue);
given().pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID).pathParam("varId", variableKey).then().expect().statusCode(Status.OK.getStatusCode()).contentType(ContentType.TEXT.toString()).and().body(is(equalTo(""))).when().get(SINGLE_EXECUTION_LOCAL_BINARY_VARIABLE_URL);
}
use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class ExecutionRestServiceInteractionTest method testPostSingleLocalFileVariableWithMimeType.
@Test
public void testPostSingleLocalFileVariableWithMimeType() {
byte[] value = "some text".getBytes();
String variableKey = "aVariableKey";
String filename = "test.txt";
String mimetype = MediaType.TEXT_PLAIN;
given().pathParam("id", MockProvider.EXAMPLE_EXECUTION_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_EXECUTION_LOCAL_BINARY_VARIABLE_URL);
ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
verify(runtimeServiceMock).setVariableLocal(eq(MockProvider.EXAMPLE_EXECUTION_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 ExecutionRestServiceInteractionTest method testPostSingleLocalFileVariableWithEncodingAndMimeType.
@Test
public void testPostSingleLocalFileVariableWithEncodingAndMimeType() {
byte[] value = "some text".getBytes();
String variableKey = "aVariableKey";
String encoding = "utf-8";
String filename = "test.txt";
String mimetype = MediaType.TEXT_PLAIN;
given().pathParam("id", MockProvider.EXAMPLE_EXECUTION_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_EXECUTION_LOCAL_BINARY_VARIABLE_URL);
ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
verify(runtimeServiceMock).setVariableLocal(eq(MockProvider.EXAMPLE_EXECUTION_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 HistoricVariableInstanceRestServiceInteractionTest 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();
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);
}
use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class FileValueProcessSerializationTest method testSerializeNullMimeType.
@Test
@Deployment(resources = ONE_TASK_PROCESS)
public void testSerializeNullMimeType() {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("oneTaskProcess", Variables.createVariables().putValue("fileVar", Variables.fileValue("test.txt").file("ABC".getBytes()).encoding("UTF-8").create()));
FileValue fileVar = runtimeService.getVariableTyped(pi.getId(), "fileVar");
assertNull(fileVar.getMimeType());
}
Aggregations