Search in sources :

Example 61 with FileValue

use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.

the class FileValueSerializerTest method testWriteMimetypeFilenameAndBytesValue.

@Test
public void testWriteMimetypeFilenameAndBytesValue() throws UnsupportedEncodingException {
    String filename = "test.txt";
    String mimeType = "text/json";
    InputStream is = this.getClass().getClassLoader().getResourceAsStream("org/camunda/bpm/engine/test/standalone/variables/simpleFile.txt");
    FileValue fileValue = Variables.fileValue(filename).mimeType(mimeType).file(is).create();
    ValueFields valueFields = new MockValueFields();
    serializer.writeValue(fileValue, valueFields);
    assertThat(new String(valueFields.getByteArrayValue(), "UTF-8"), is("text"));
    assertThat(valueFields.getTextValue(), is(filename));
    assertThat(valueFields.getTextValue2(), is(mimeType + SEPARATOR));
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) ValueFields(org.camunda.bpm.engine.impl.variable.serializer.ValueFields) Test(org.junit.Test)

Example 62 with FileValue

use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.

the class TaskQueryTest method testQueryByFileCaseInstanceVariableValueGreaterThanOrEqual.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testQueryByFileCaseInstanceVariableValueGreaterThanOrEqual() {
    FileValue fileValue = createDefaultFileValue();
    String variableName = "aFileValue";
    startDefaultCaseWithVariable(fileValue, variableName);
    TaskQuery query = taskService.createTaskQuery();
    try {
        query.caseInstanceVariableValueGreaterThanOrEquals(variableName, fileValue).list();
        fail();
    } catch (ProcessEngineException e) {
        assertThat(e.getMessage(), containsString("Variables of type File cannot be used to query"));
    }
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) TaskQuery(org.camunda.bpm.engine.task.TaskQuery) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 63 with FileValue

use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.

the class FileValueProcessSerializationTest method testSerializeNullValue.

@Test
@Deployment(resources = ONE_TASK_PROCESS)
public void testSerializeNullValue() {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("oneTaskProcess", Variables.createVariables().putValue("fileVar", Variables.fileValue("test.txt").create()));
    FileValue fileVar = runtimeService.getVariableTyped(pi.getId(), "fileVar");
    assertNull(fileVar.getMimeType());
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 64 with FileValue

use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.

the class FileValueProcessSerializationTest method testSerializeNullMimeTypeAndNullEncoding.

@Test
@Deployment(resources = ONE_TASK_PROCESS)
public void testSerializeNullMimeTypeAndNullEncoding() {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("oneTaskProcess", Variables.createVariables().putValue("fileVar", Variables.fileValue("test.txt").file("ABC".getBytes()).create()));
    FileValue fileVar = runtimeService.getVariableTyped(pi.getId(), "fileVar");
    assertNull(fileVar.getMimeType());
    assertNull(fileVar.getEncoding());
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 65 with FileValue

use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.

the class FileValueProcessSerializationTest method testSerializeFileVariable.

@Test
public void testSerializeFileVariable() {
    BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("process").startEvent().userTask().endEvent().done();
    org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment().addModelInstance("process.bpmn", modelInstance).deploy();
    VariableMap variables = Variables.createVariables();
    String filename = "test.txt";
    String type = "text/plain";
    FileValue fileValue = Variables.fileValue(filename).file("ABC".getBytes()).encoding("UTF-8").mimeType(type).create();
    variables.put("file", fileValue);
    runtimeService.startProcessInstanceByKey("process", variables);
    Task task = taskService.createTaskQuery().singleResult();
    VariableInstance result = runtimeService.createVariableInstanceQuery().processInstanceIdIn(task.getProcessInstanceId()).singleResult();
    FileValue value = (FileValue) result.getTypedValue();
    assertThat(value.getFilename(), is(filename));
    assertThat(value.getMimeType(), is(type));
    assertThat(value.getEncoding(), is("UTF-8"));
    assertThat(value.getEncodingAsCharset(), is(Charset.forName("UTF-8")));
    Scanner scanner = new Scanner(value.getValue());
    assertThat(scanner.nextLine(), is("ABC"));
    // clean up
    repositoryService.deleteDeployment(deployment.getId(), true);
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) Scanner(java.util.Scanner) Task(org.camunda.bpm.engine.task.Task) VariableMap(org.camunda.bpm.engine.variable.VariableMap) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) 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