org.camunda.bpm.engine.variable.value.FileValue Java Examples
The following examples show how to use
org.camunda.bpm.engine.variable.value.FileValue.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CaseExecutionRestServiceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testPostSingleLocalFileVariableOnlyFilename() throws Exception { String variableKey = "aVariableKey"; String filename = "test.txt"; given() .pathParam("id", MockProvider.EXAMPLE_CASE_EXECUTION_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_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(MediaType.APPLICATION_OCTET_STREAM)); assertThat(captured.getValue().available(), is(0)); }
Example #2
Source File: HistoryByteArrayTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testHistoricDetailBinaryForFileValues() { // given BpmnModelInstance instance = createProcess(); testRule.deploy(instance); FileValue fileValue = createFile(); runtimeService.startProcessInstanceByKey("Process", Variables.createVariables().putValueTyped("fileVar", fileValue)); String byteArrayValueId = ((HistoricDetailVariableInstanceUpdateEntity) historyService.createHistoricDetailQuery().singleResult()).getByteArrayValueId(); // when ByteArrayEntity byteArrayEntity = configuration.getCommandExecutorTxRequired() .execute(new GetByteArrayCommand(byteArrayValueId)); checkBinary(byteArrayEntity); }
Example #3
Source File: CaseInstanceRestServiceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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); }
Example #4
Source File: HistoryByteArrayTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testHistoricVariableBinaryForFileValues() { // given BpmnModelInstance instance = createProcess(); testRule.deploy(instance); FileValue fileValue = createFile(); runtimeService.startProcessInstanceByKey("Process", Variables.createVariables().putValueTyped("fileVar", fileValue)); String byteArrayValueId = ((HistoricVariableInstanceEntity)historyService.createHistoricVariableInstanceQuery().singleResult()).getByteArrayValueId(); // when ByteArrayEntity byteArrayEntity = configuration.getCommandExecutorTxRequired() .execute(new GetByteArrayCommand(byteArrayValueId)); checkBinary(byteArrayEntity); }
Example #5
Source File: TaskQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Deployment(resources={"org/camunda/bpm/engine/test/api/cmmn/oneTaskCaseWithManualActivation.cmmn"}) public void testQueryByFileCaseInstanceVariableValueGreaterThan() { FileValue fileValue = createDefaultFileValue(); String variableName = "aFileValue"; startDefaultCaseWithVariable(fileValue, variableName); startDefaultCaseExecutionManually(); TaskQuery query = taskService.createTaskQuery(); try { query.caseInstanceVariableValueGreaterThan(variableName, fileValue).list(); fail(); } catch (ProcessEngineException e) { assertThat(e.getMessage(), containsString("Variables of type File cannot be used to query")); } }
Example #6
Source File: CaseInstanceRestServiceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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); }
Example #7
Source File: Variables.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
/** * Creates an untyped value, i.e. {@link TypedValue#getType()} returns <code>null</code> * for the returned instance. */ public static TypedValue untypedValue(Object value, boolean isTransient) { if(value == null) { return untypedNullValue(isTransient); } else if (value instanceof TypedValueBuilder<?>) { return ((TypedValueBuilder<?>) value).setTransient(isTransient).create(); } else if (value instanceof TypedValue) { TypedValue transientValue = (TypedValue) value; if (value instanceof NullValueImpl) { transientValue = untypedNullValue(isTransient); } else if (value instanceof FileValue) { ((FileValueImpl) transientValue).setTransient(isTransient); } else if (value instanceof AbstractTypedValue<?>) { ((AbstractTypedValue<?>) transientValue).setTransient(isTransient); } return transientValue; } else { // unknown value return new UntypedValueImpl(value, isTransient); } }
Example #8
Source File: FileValueSerializerTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testReadFullValue() 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 mimeType = "text/plain"; String encoding = "UTF-16"; valueFields.setTextValue2(mimeType + SEPARATOR + encoding); FileValue fileValue = serializer.readValue(valueFields, true, false); assertThat(fileValue.getFilename(), is(filename)); assertThat(fileValue.getMimeType(), is(mimeType)); assertThat(fileValue.getEncoding(), is("UTF-16")); assertThat(fileValue.getEncodingAsCharset(), is(Charset.forName("UTF-16"))); checkStreamFromValue(fileValue, "text"); }
Example #9
Source File: CaseInstanceRestServiceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testPostSingleFileVariableWithEncodingAndMimeType() 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_INSTANCE_ID).pathParam("varId", variableKey) .multiPart("data", filename, value, mimetype + "; encoding="+encoding) .multiPart("valueType", "File", "text/plain") .expect() .statusCode(Status.NO_CONTENT.getStatusCode()) .when() .post(SINGLE_CASE_INSTANCE_BINARY_VARIABLE_URL); ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class); verify(caseServiceMock).withCaseExecution(MockProvider.EXAMPLE_CASE_INSTANCE_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)); }
Example #10
Source File: TaskVariableRestResourceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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.getVariableTyped(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); }
Example #11
Source File: CaseInstanceRestServiceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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(caseServiceMock.getVariableTyped(eq(MockProvider.EXAMPLE_CASE_INSTANCE_ID), eq(variableKey), anyBoolean())) .thenReturn(variableValue); Response response = given() .pathParam("id", MockProvider.EXAMPLE_CASE_INSTANCE_ID) .pathParam("varId", variableKey) .then().expect() .statusCode(Status.OK.getStatusCode()) .body(is(equalTo(new String(byteContent)))) .when().get(SINGLE_CASE_INSTANCE_BINARY_VARIABLE_URL); String contentType = response.contentType().replaceAll(" ", ""); assertThat(contentType, is(ContentType.TEXT + ";charset=" + encoding)); }
Example #12
Source File: CaseExecutionRestServiceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testGetNullFileVariable() { String variableKey = "aVariableKey"; String filename = "test.txt"; String mimeType = "text/plain"; FileValue variableValue = Variables.fileValue(filename).mimeType(mimeType).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(""))) .when().get(SINGLE_CASE_EXECUTION_BINARY_VARIABLE_URL); }
Example #13
Source File: CaseExecutionRestServiceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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_EXECUTION_BINARY_VARIABLE_URL); }
Example #14
Source File: CaseExecutionRestServiceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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(caseServiceMock.getVariableTyped(eq(MockProvider.EXAMPLE_CASE_INSTANCE_ID), eq(variableKey), anyBoolean())) .thenReturn(variableValue); Response response = given() .pathParam("id", MockProvider.EXAMPLE_CASE_INSTANCE_ID) .pathParam("varId", variableKey) .then().expect() .statusCode(Status.OK.getStatusCode()) .body(is(equalTo(new String(byteContent)))) .when().get(SINGLE_CASE_EXECUTION_BINARY_VARIABLE_URL); String contentType = response.contentType().replaceAll(" ", ""); assertThat(contentType, is(ContentType.TEXT + ";charset=" + encoding)); }
Example #15
Source File: CaseExecutionRestServiceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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); }
Example #16
Source File: FileValueSerializerTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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, false); assertThat(fileValue.getFilename(), is(filename)); assertThat(fileValue.getEncoding(), is("UTF-8")); assertThat(fileValue.getEncodingAsCharset(), is(Charset.forName("UTF-8"))); checkStreamFromValue(fileValue, "text"); }
Example #17
Source File: CaseInstanceRestServiceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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(caseServiceMock.getVariableTyped(MockProvider.EXAMPLE_CASE_INSTANCE_ID, variableKey, true)) .thenReturn(variableValue); given().pathParam("id", MockProvider.EXAMPLE_CASE_INSTANCE_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_CASE_INSTANCE_VARIABLE_URL); }
Example #18
Source File: TaskVariableRestResourceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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.getVariableTyped(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); }
Example #19
Source File: TaskVariableLocalRestResourceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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); }
Example #20
Source File: TaskVariableLocalRestResourceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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); }
Example #21
Source File: TaskVariableLocalRestResourceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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); }
Example #22
Source File: TaskVariableLocalRestResourceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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)); }
Example #23
Source File: TaskVariableRestResourceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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.getVariableTyped(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)); }
Example #24
Source File: ProcessInstanceRestServiceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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); }
Example #25
Source File: HistoricVariableInstanceRestServiceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testGetBinaryDataForNullFileVariable() { String filename = "test.txt"; byte[] byteContent = null; FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(ContentType.TEXT.toString()).create(); HistoricVariableInstance variableInstanceMock = MockProvider.mockHistoricVariableInstance() .typedValue(variableValue) .build(); when(variableInstanceQueryMock.variableId(variableInstanceMock.getId())).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.disableCustomObjectDeserialization()).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.singleResult()).thenReturn(variableInstanceMock); given().pathParam("id", MockProvider.EXAMPLE_VARIABLE_INSTANCE_ID) .then().expect().statusCode(Status.OK.getStatusCode()) .and().contentType(ContentType.TEXT) .and().body(is(equalTo(new String()))) .when().get(VARIABLE_INSTANCE_BINARY_DATA_URL); }
Example #26
Source File: ProcessInstanceRestServiceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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)); }
Example #27
Source File: TaskVariableRestResourceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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_TASK_SINGLE_BINARY_VARIABLE_URL); ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class); verify(taskServiceMock).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)); }
Example #28
Source File: ProcessInstanceRestServiceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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)); }
Example #29
Source File: TaskVariableRestResourceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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.getVariableTyped(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); }
Example #30
Source File: TaskVariableRestResourceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@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.getVariableTyped(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); }