Search in sources :

Example 1 with FileValue

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

the class VariableValueDto method fromTypedValue.

public static void fromTypedValue(VariableValueDto dto, TypedValue typedValue, boolean preferSerializedValue) {
    ValueType type = typedValue.getType();
    if (type != null) {
        String typeName = type.getName();
        dto.setType(toRestApiTypeName(typeName));
        dto.setValueInfo(type.getValueInfo(typedValue));
    }
    if (typedValue instanceof SerializableValue) {
        SerializableValue serializableValue = (SerializableValue) typedValue;
        if (serializableValue.isDeserialized() && !preferSerializedValue) {
            dto.setValue(serializableValue.getValue());
        } else {
            dto.setValue(serializableValue.getValueSerialized());
        }
    } else if (typedValue instanceof FileValue) {
    // do not set the value for FileValues since we don't want to send megabytes over the network without explicit request
    } else {
        dto.setValue(typedValue.getValue());
    }
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) SerializableValue(org.camunda.bpm.engine.variable.value.SerializableValue) SerializableValueType(org.camunda.bpm.engine.variable.type.SerializableValueType) FileValueType(org.camunda.bpm.engine.variable.type.FileValueType) ValueType(org.camunda.bpm.engine.variable.type.ValueType) PrimitiveValueType(org.camunda.bpm.engine.variable.type.PrimitiveValueType)

Example 2 with FileValue

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

the class TaskVariableLocalRestResourceInteractionTest method testGetNullFileVariable.

@Test
public void testGetNullFileVariable() {
    String variableKey = "aVariableKey";
    String filename = "test.txt";
    String mimeType = "text/plain";
    FileValue variableValue = Variables.fileValue(filename).mimeType(mimeType).create();
    when(taskServiceMock.getVariableLocalTyped(eq(MockProvider.EXAMPLE_TASK_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue);
    given().pathParam("id", MockProvider.EXAMPLE_TASK_ID).pathParam("varId", variableKey).then().expect().statusCode(Status.OK.getStatusCode()).contentType(ContentType.TEXT.toString()).and().body(is(equalTo(""))).when().get(SINGLE_TASK_SINGLE_BINARY_VARIABLE_URL);
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 3 with FileValue

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

the class TaskVariableLocalRestResourceInteractionTest method testPostSingleLocalFileVariableOnlyFilename.

@Test
public void testPostSingleLocalFileVariableOnlyFilename() throws Exception {
    String variableKey = "aVariableKey";
    String filename = "test.txt";
    given().pathParam("id", EXAMPLE_TASK_ID).pathParam("varId", variableKey).multiPart("data", filename, new byte[0]).multiPart("valueType", "File", "text/plain").header("accept", MediaType.APPLICATION_JSON).expect().statusCode(Status.NO_CONTENT.getStatusCode()).when().post(SINGLE_TASK_SINGLE_BINARY_VARIABLE_URL);
    ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
    verify(taskServiceMock).setVariableLocal(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(MediaType.APPLICATION_OCTET_STREAM));
    assertThat(captured.getValue().available(), is(0));
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 4 with FileValue

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

the class TaskVariableLocalRestResourceInteractionTest 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(taskServiceMock.getVariableLocalTyped(eq(EXAMPLE_TASK_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue);
    given().pathParam("id", EXAMPLE_TASK_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_TASK_SINGLE_BINARY_VARIABLE_URL);
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 5 with FileValue

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

the class TaskVariableLocalRestResourceInteractionTest 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(taskServiceMock.getVariableLocalTyped(eq(EXAMPLE_TASK_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue);
    given().pathParam("id", EXAMPLE_TASK_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_TASK_SINGLE_VARIABLE_URL);
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) 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