Search in sources :

Example 41 with FileValue

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));
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) ValueFields(org.camunda.bpm.engine.impl.variable.serializer.ValueFields) Test(org.junit.Test)

Example 42 with FileValue

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");
    }
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 43 with FileValue

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());
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 44 with FileValue

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());
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 45 with FileValue

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);
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) HistoricVariableInstanceQuery(org.camunda.bpm.engine.history.HistoricVariableInstanceQuery) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) Matchers.anyString(org.mockito.Matchers.anyString) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

FileValue (org.camunda.bpm.engine.variable.value.FileValue)85 Test (org.junit.Test)76 Matchers.containsString (org.hamcrest.Matchers.containsString)44 Matchers.anyString (org.mockito.Matchers.anyString)44 Deployment (org.camunda.bpm.engine.test.Deployment)13 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)10 Response (com.jayway.restassured.response.Response)9 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)7 DataInputStream (java.io.DataInputStream)6 InputStream (java.io.InputStream)6 ValueFields (org.camunda.bpm.engine.impl.variable.serializer.ValueFields)6 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)6 HistoricVariableUpdate (org.camunda.bpm.engine.history.HistoricVariableUpdate)4 AbstractRestServiceTest (org.camunda.bpm.engine.rest.AbstractRestServiceTest)4 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)4 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)4 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)3 MockHistoricVariableUpdateBuilder (org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder)2 MockVariableInstanceBuilder (org.camunda.bpm.engine.rest.helper.MockVariableInstanceBuilder)2 VariableMap (org.camunda.bpm.engine.variable.VariableMap)2