use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class VariableInstanceQueryTest method testDisableBinaryFetchingForFileValues.
@Test
@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml")
public void testDisableBinaryFetchingForFileValues() {
// given
String fileName = "text.txt";
String encoding = "crazy-encoding";
String mimeType = "martini/dry";
FileValue fileValue = Variables.fileValue(fileName).file("ABC".getBytes()).encoding(encoding).mimeType(mimeType).create();
runtimeService.startProcessInstanceByKey("oneTaskProcess", Variables.createVariables().putValueTyped("fileVar", fileValue));
// when enabling binary fetching
VariableInstance fileVariableInstance = runtimeService.createVariableInstanceQuery().singleResult();
// then the binary value is accessible
assertNotNull(fileVariableInstance.getValue());
// when disabling binary fetching
fileVariableInstance = runtimeService.createVariableInstanceQuery().disableBinaryFetching().singleResult();
// then the byte value is not fetched
assertNotNull(fileVariableInstance);
assertEquals("fileVar", fileVariableInstance.getName());
assertNull(fileVariableInstance.getValue());
FileValue typedValue = (FileValue) fileVariableInstance.getTypedValue();
assertNull(typedValue.getValue());
// but typed value metadata is accessible
assertEquals(ValueType.FILE, typedValue.getType());
assertEquals(fileName, typedValue.getFilename());
assertEquals(encoding, typedValue.getEncoding());
assertEquals(mimeType, typedValue.getMimeType());
}
use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class ProcessInstanceRestServiceInteractionTest 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(runtimeServiceMock.getVariableTyped(eq(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue);
given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_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_PROCESS_INSTANCE_BINARY_VARIABLE_URL);
}
use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class ProcessInstanceRestServiceInteractionTest 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_PROCESS_INSTANCE_BINARY_VARIABLE_URL);
ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
verify(runtimeServiceMock).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 ProcessInstanceRestServiceInteractionTest method testPostSingleFileVariableWithMimeType.
@Test
public void testPostSingleFileVariableWithMimeType() throws Exception {
byte[] value = "some text".getBytes();
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_PROCESS_INSTANCE_BINARY_VARIABLE_URL);
ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
verify(runtimeServiceMock).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(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 ProcessInstanceRestServiceInteractionTest method testGetFileVariable.
@Test
public void testGetFileVariable() {
String variableKey = "aVariableKey";
final byte[] byteContent = "some bytes".getBytes();
String filename = "test.txt";
String mimeType = "text/plain";
FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(mimeType).create();
when(runtimeServiceMock.getVariableTyped(eq(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey), eq(true))).thenReturn(variableValue);
given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey).then().expect().statusCode(Status.OK.getStatusCode()).contentType(ContentType.JSON.toString()).and().body("valueInfo.mimeType", equalTo(mimeType)).body("valueInfo.filename", equalTo(filename)).body("value", nullValue()).when().get(SINGLE_PROCESS_INSTANCE_VARIABLE_URL);
}
Aggregations