Search in sources :

Example 76 with FileValue

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

the class TaskVariableLocalRestResourceInteractionTest 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(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.TEXT.toString()).and().body(is(equalTo(new String(byteContent)))).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 77 with FileValue

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

the class TaskVariableLocalRestResourceInteractionTest method testGetFileVariableDownloadWithTypeAndEncoding.

@Test
public void testGetFileVariableDownloadWithTypeAndEncoding() {
    String variableKey = "aVariableKey";
    final byte[] byteContent = "some bytes".getBytes();
    String filename = "test.txt";
    String encoding = "UTF-8";
    FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(ContentType.TEXT.toString()).encoding(encoding).create();
    when(taskServiceMock.getVariableLocalTyped(eq(EXAMPLE_TASK_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue);
    Response response = given().pathParam("id", EXAMPLE_TASK_ID).pathParam("varId", variableKey).then().expect().statusCode(Status.OK.getStatusCode()).body(is(equalTo(new String(byteContent)))).when().get(SINGLE_TASK_SINGLE_BINARY_VARIABLE_URL);
    String contentType = response.contentType().replaceAll(" ", "");
    assertThat(contentType, is(ContentType.TEXT + ";charset=" + encoding));
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) Response(com.jayway.restassured.response.Response) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 78 with FileValue

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

the class VariableInstanceRestServiceInteractionTest method testGetBinaryDataForFileVariable.

@Test
public void testGetBinaryDataForFileVariable() {
    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();
    MockVariableInstanceBuilder builder = MockProvider.mockVariableInstance();
    VariableInstance variableInstanceMock = builder.typedValue(variableValue).build();
    when(variableInstanceQueryMock.variableId(variableInstanceMock.getId())).thenReturn(variableInstanceQueryMock);
    when(variableInstanceQueryMock.disableBinaryFetching()).thenReturn(variableInstanceQueryMock);
    when(variableInstanceQueryMock.disableCustomObjectDeserialization()).thenReturn(variableInstanceQueryMock);
    when(variableInstanceQueryMock.singleResult()).thenReturn(variableInstanceMock);
    Response response = given().pathParam("id", MockProvider.EXAMPLE_VARIABLE_INSTANCE_ID).then().expect().statusCode(Status.OK.getStatusCode()).and().header("Content-Disposition", "attachment; filename=" + filename).and().body(is(equalTo(new String(byteContent)))).when().get(VARIABLE_INSTANCE_BINARY_DATA_URL);
    // due to some problems with wildfly we gotta check this separately
    String contentType = response.getContentType();
    assertThat(contentType, is(either(CoreMatchers.<Object>equalTo(ContentType.TEXT.toString() + "; charset=UTF-8")).or(CoreMatchers.<Object>equalTo(ContentType.TEXT.toString() + ";charset=UTF-8"))));
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) Response(com.jayway.restassured.response.Response) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MockVariableInstanceBuilder(org.camunda.bpm.engine.rest.helper.MockVariableInstanceBuilder) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test)

Example 79 with FileValue

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

the class CaseInstanceRestServiceInteractionTest 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(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(ContentType.TEXT.toString()).and().body(is(equalTo(new String(byteContent)))).when().get(SINGLE_CASE_INSTANCE_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 80 with FileValue

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

the class CaseInstanceRestServiceInteractionTest 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_INSTANCE_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)

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