Search in sources :

Example 56 with FileValue

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

the class FileValueSerializerTest method testReadFileNameEncodingAndByteArray.

@Test
public void testReadFileNameEncodingAndByteArray() throws IOException {
    InputStream is = this.getClass().getClassLoader().getResourceAsStream("org/camunda/bpm/engine/test/standalone/variables/simpleFile.txt");
    byte[] data = new byte[is.available()];
    DataInputStream dataInputStream = new DataInputStream(is);
    dataInputStream.readFully(data);
    dataInputStream.close();
    MockValueFields valueFields = new MockValueFields();
    String filename = "file.txt";
    valueFields.setTextValue(filename);
    valueFields.setByteArrayValue(data);
    String encoding = SEPARATOR + "UTF-8";
    valueFields.setTextValue2(encoding);
    FileValue fileValue = serializer.readValue(valueFields, true);
    assertThat(fileValue.getFilename(), is(filename));
    assertThat(fileValue.getEncoding(), is("UTF-8"));
    assertThat(fileValue.getEncodingAsCharset(), is(Charset.forName("UTF-8")));
    checkStreamFromValue(fileValue, "text");
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 57 with FileValue

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

the class FileValueSerializerTest method testWriteFilenameOnlyValue.

@Test
public void testWriteFilenameOnlyValue() {
    String filename = "test.txt";
    FileValue fileValue = Variables.fileValue(filename).create();
    ValueFields valueFields = new MockValueFields();
    serializer.writeValue(fileValue, valueFields);
    assertThat(valueFields.getByteArrayValue(), is(nullValue()));
    assertThat(valueFields.getTextValue(), is(filename));
    assertThat(valueFields.getTextValue2(), is(nullValue()));
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) ValueFields(org.camunda.bpm.engine.impl.variable.serializer.ValueFields) Test(org.junit.Test)

Example 58 with FileValue

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

the class FileValueSerializerTest method testReadFilenameValue.

@Test
public void testReadFilenameValue() throws IOException {
    MockValueFields valueFields = new MockValueFields();
    String filename = "file.txt";
    valueFields.setTextValue(filename);
    FileValue fileValue = serializer.readValue(valueFields, true);
    assertThat(fileValue.getFilename(), is(filename));
    assertThat(fileValue.getMimeType(), is(nullValue()));
    assertThat(fileValue.getValue(), is(nullValue()));
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) Test(org.junit.Test)

Example 59 with FileValue

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

the class FileValueSerializerTest method testWriteMimetypeFilenameAndBytesValueWithShortcutMethod.

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

Example 60 with FileValue

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

the class FileValueSerializerTest method testWriteFilenameAndEncodingValue.

@Test
public void testWriteFilenameAndEncodingValue() {
    String filename = "test.txt";
    String encoding = "UTF-8";
    FileValue fileValue = Variables.fileValue(filename).encoding(encoding).create();
    ValueFields valueFields = new MockValueFields();
    serializer.writeValue(fileValue, valueFields);
    assertThat(valueFields.getByteArrayValue(), is(nullValue()));
    assertThat(valueFields.getTextValue(), is(filename));
    assertThat(valueFields.getTextValue2(), is(SEPARATOR + encoding));
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) ValueFields(org.camunda.bpm.engine.impl.variable.serializer.ValueFields) 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