Search in sources :

Example 16 with FileValue

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

the class CaseExecutionRestServiceInteractionTest method testPostSingleLocalFileVariableWithMimeType.

@Test
public void testPostSingleLocalFileVariableWithMimeType() throws Exception {
    byte[] value = "some text".getBytes();
    String variableKey = "aVariableKey";
    String filename = "test.txt";
    String mimetype = MediaType.TEXT_PLAIN;
    given().pathParam("id", MockProvider.EXAMPLE_CASE_EXECUTION_ID).pathParam("varId", variableKey).multiPart("data", filename, value, mimetype).multiPart("valueType", "File", "text/plain").header("accept", MediaType.APPLICATION_JSON).expect().statusCode(Status.NO_CONTENT.getStatusCode()).when().post(SINGLE_CASE_EXECUTION_LOCAL_BINARY_VARIABLE_URL);
    ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
    verify(caseServiceMock).withCaseExecution(MockProvider.EXAMPLE_CASE_EXECUTION_ID);
    verify(caseExecutionCommandBuilderMock).setVariableLocal(eq(variableKey), captor.capture());
    FileValue captured = captor.getValue();
    assertThat(captured.getEncoding(), is(nullValue()));
    assertThat(captured.getFilename(), is(filename));
    assertThat(captured.getMimeType(), is(mimetype));
    assertThat(IoUtil.readInputStream(captured.getValue(), null), is(value));
}
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 17 with FileValue

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

the class CaseExecutionRestServiceInteractionTest method testPostSingleFileVariable.

@Test
public void testPostSingleFileVariable() throws Exception {
    byte[] value = "some text".getBytes();
    String variableKey = "aVariableKey";
    String encoding = "utf-8";
    String filename = "test.txt";
    String mimetype = MediaType.TEXT_PLAIN;
    given().pathParam("id", MockProvider.EXAMPLE_CASE_EXECUTION_ID).pathParam("varId", variableKey).multiPart("data", filename, value, mimetype + "; encoding=" + encoding).header("accept", MediaType.APPLICATION_JSON).multiPart("valueType", "File", "text/plain").expect().statusCode(Status.NO_CONTENT.getStatusCode()).when().post(SINGLE_CASE_EXECUTION_BINARY_VARIABLE_URL);
    ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
    verify(caseServiceMock).withCaseExecution(MockProvider.EXAMPLE_CASE_EXECUTION_ID);
    verify(caseExecutionCommandBuilderMock).setVariable(eq(variableKey), captor.capture());
    FileValue captured = captor.getValue();
    assertThat(captured.getEncoding(), is(encoding));
    assertThat(captured.getFilename(), is(filename));
    assertThat(captured.getMimeType(), is(mimetype));
    assertThat(IoUtil.readInputStream(captured.getValue(), null), is(value));
}
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 18 with FileValue

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

the class CaseExecutionRestServiceInteractionTest 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(caseServiceMock.getVariableTyped(eq(MockProvider.EXAMPLE_CASE_INSTANCE_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue);
    given().pathParam("id", MockProvider.EXAMPLE_CASE_INSTANCE_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_CASE_EXECUTION_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 19 with FileValue

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

the class ProcessInstanceRestServiceInteractionTest method testGetFileVariableDownloadWithType.

@Test
public void testGetFileVariableDownloadWithType() {
    String variableKey = "aVariableKey";
    final byte[] byteContent = "some bytes".getBytes();
    String filename = "test.txt";
    FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(ContentType.TEXT.toString()).create();
    when(runtimeServiceMock.getVariableTyped(eq(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue);
    given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey).then().expect().statusCode(Status.OK.getStatusCode()).contentType(ContentType.TEXT.toString()).and().body(is(equalTo(new String(byteContent)))).when().get(SINGLE_PROCESS_INSTANCE_BINARY_VARIABLE_URL);
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) Test(org.junit.Test)

Example 20 with FileValue

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

the class HistoricDetailRestServiceInteractionTest method testGetBinaryDataForNullFileVariable.

@Test
public void testGetBinaryDataForNullFileVariable() {
    String filename = "test.txt";
    byte[] byteContent = null;
    FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(ContentType.TEXT.toString()).create();
    MockHistoricVariableUpdateBuilder builder = MockProvider.mockHistoricVariableUpdate();
    HistoricVariableUpdate detailMock = builder.typedValue(variableValue).build();
    when(historicDetailQueryMock.detailId(detailMock.getId())).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.singleResult()).thenReturn(detailMock);
    given().pathParam("id", MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_ID).then().expect().statusCode(Status.OK.getStatusCode()).and().contentType(ContentType.TEXT).and().body(is(equalTo(new String()))).when().get(VARIABLE_INSTANCE_BINARY_DATA_URL);
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MockHistoricVariableUpdateBuilder(org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

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