use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class ProcessInstanceRestServiceInteractionTest 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(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(""))).when().get(SINGLE_PROCESS_INSTANCE_BINARY_VARIABLE_URL);
}
use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class ProcessInstanceRestServiceInteractionTest method testPostSingleFileVariableOnlyFilename.
@Test
public void testPostSingleFileVariableOnlyFilename() 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_PROCESS_INSTANCE_BINARY_VARIABLE_URL);
ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
verify(runtimeServiceMock).setVariable(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));
}
use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class ProcessInstanceRestServiceInteractionTest 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(runtimeServiceMock.getVariableTyped(eq(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue);
Response response = given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey).then().expect().statusCode(Status.OK.getStatusCode()).body(is(equalTo(new String(byteContent)))).when().get(SINGLE_PROCESS_INSTANCE_BINARY_VARIABLE_URL);
String contentType = response.contentType().replaceAll(" ", "");
assertThat(contentType, is(ContentType.TEXT + ";charset=" + encoding));
}
use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class TaskRestServiceInteractionTest method testSubmitTaskFormWithFileValue.
@SuppressWarnings({ "unchecked" })
@Test
public void testSubmitTaskFormWithFileValue() {
String variableKey = "aVariable";
String filename = "test.txt";
Map<String, Object> variables = VariablesBuilder.create().variable(variableKey, Base64.encodeBase64String("someBytes".getBytes()), "File").getVariables();
((Map<String, Object>) variables.get(variableKey)).put("valueInfo", Collections.<String, Object>singletonMap("filename", filename));
Map<String, Object> json = new HashMap<String, Object>();
json.put("variables", variables);
given().pathParam("id", EXAMPLE_TASK_ID).header("accept", MediaType.APPLICATION_JSON).contentType(POST_JSON_CONTENT_TYPE).body(json).then().expect().statusCode(Status.NO_CONTENT.getStatusCode()).when().post(SUBMIT_FORM_URL);
ArgumentCaptor<VariableMap> captor = ArgumentCaptor.forClass(VariableMap.class);
verify(formServiceMock).submitTaskForm(eq(EXAMPLE_TASK_ID), captor.capture());
VariableMap map = captor.getValue();
FileValue fileValue = (FileValue) map.getValueTyped(variableKey);
assertThat(fileValue, is(notNullValue()));
assertThat(fileValue.getFilename(), is(filename));
assertThat(IoUtil.readInputStream(fileValue.getValue(), null), is("someBytes".getBytes()));
}
use of org.camunda.bpm.engine.variable.value.FileValue in project camunda-bpm-platform by camunda.
the class TaskVariableLocalRestResourceInteractionTest method testPostSingleLocalFileVariableWithEncodingAndMimeType.
@Test
public void testPostSingleLocalFileVariableWithEncodingAndMimeType() 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", EXAMPLE_TASK_ID).pathParam("varId", variableKey).multiPart("data", filename, value, mimetype + "; encoding=" + encoding).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(encoding));
assertThat(captured.getFilename(), is(filename));
assertThat(captured.getMimeType(), is(mimetype));
assertThat(IoUtil.readInputStream(captured.getValue(), null), is(value));
}
Aggregations