use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class FileValueSerializerTest method testWriteMimetypeAndFilenameValue.
@Test
public void testWriteMimetypeAndFilenameValue() {
String filename = "test.txt";
String mimeType = "text/json";
FileValue fileValue = Variables.fileValue(filename).mimeType(mimeType).create();
ValueFields valueFields = new MockValueFields();
serializer.writeValue(fileValue, valueFields);
assertThat(valueFields.getByteArrayValue(), is(nullValue()));
assertThat(valueFields.getTextValue(), is(filename));
assertThat(valueFields.getTextValue2(), is(mimeType + SEPARATOR));
}
use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class ArchiveInvoiceService method execute.
public void execute(DelegateExecution execution) throws Exception {
Boolean shouldFail = (Boolean) execution.getVariable("shouldFail");
FileValue invoiceDocumentVar = execution.getVariableTyped("invoiceDocument");
if (shouldFail != null && shouldFail) {
throw new ProcessEngineException("Could not archive invoice...");
} else {
LOGGER.info("\n\n ... Now archiving invoice " + execution.getVariable("invoiceNumber") + ", filename: " + invoiceDocumentVar.getFilename() + " \n\n");
}
}
use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class HistoricVariableInstanceTest method testDisableBinaryFetchingForFileValues.
@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
HistoricVariableInstance fileVariableInstance = historyService.createHistoricVariableInstanceQuery().singleResult();
// then the binary value is accessible
assertNotNull(fileVariableInstance.getValue());
// when disabling binary fetching
fileVariableInstance = historyService.createHistoricVariableInstanceQuery().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 FullHistoryTest 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
HistoricVariableUpdate fileVariableInstance = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().singleResult();
// then the binary value is accessible
assertNotNull(fileVariableInstance.getValue());
// when disabling binary fetching
fileVariableInstance = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().disableBinaryFetching().singleResult();
// then the byte value is not fetched
assertNotNull(fileVariableInstance);
assertEquals("fileVar", fileVariableInstance.getVariableName());
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 ProcessEngineRestServiceTest method testHistoryServiceEngineAccess_HistoricVariableInstanceBinaryFile.
@Ignore
@Test
public void testHistoryServiceEngineAccess_HistoricVariableInstanceBinaryFile() {
HistoricVariableInstanceQuery query = mock(HistoricVariableInstanceQuery.class);
HistoricVariableInstance instance = mock(HistoricVariableInstance.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.createHistoricVariableInstanceQuery()).thenReturn(query);
given().pathParam("name", EXAMPLE_ENGINE_NAME).pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID).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_VARIABLE_INSTANCE_URL);
verify(mockHistoryService).createHistoricVariableInstanceQuery();
verifyZeroInteractions(processEngine);
}
Aggregations