public override FileValue readValue(ValueFields valueFields, bool deserializeValue) { string fileName = valueFields.TextValue; if (string.ReferenceEquals(fileName, null)) { // ensure file name is not null fileName = ""; } FileValueBuilder builder = Variables.fileValue(fileName); if (valueFields.ByteArrayValue != null) { builder.file(valueFields.ByteArrayValue); } // to ensure the same array size all the time if (!string.ReferenceEquals(valueFields.TextValue2, null)) { string[] split = Arrays.copyOf(valueFields.TextValue2.Split(MIMETYPE_ENCODING_SEPARATOR, NR_OF_VALUES_IN_TEXTFIELD2), NR_OF_VALUES_IN_TEXTFIELD2); string mimeType = returnNullIfEmptyString(split[0]); string encoding = returnNullIfEmptyString(split[1]); builder.mimeType(mimeType); builder.encoding(encoding); } return(builder.create()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testSerializeFileVariable() public virtual void testSerializeFileVariable() { BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("process").startEvent().userTask().endEvent().done(); org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment().addModelInstance("process.bpmn", modelInstance).deploy(); VariableMap variables = Variables.createVariables(); string filename = "test.txt"; string type = "text/plain"; FileValue fileValue = Variables.fileValue(filename).file("ABC".GetBytes()).encoding("UTF-8").mimeType(type).create(); variables.put("file", fileValue); runtimeService.startProcessInstanceByKey("process", variables); Task task = taskService.createTaskQuery().singleResult(); VariableInstance result = runtimeService.createVariableInstanceQuery().processInstanceIdIn(task.ProcessInstanceId).singleResult(); FileValue value = (FileValue)result.TypedValue; assertThat(value.Filename, @is(filename)); assertThat(value.MimeType, @is(type)); assertThat(value.Encoding, @is("UTF-8")); assertThat(value.EncodingAsCharset, @is(Charset.forName("UTF-8"))); using (Scanner scanner = new Scanner(value.Value)) { assertThat(scanner.nextLine(), @is("ABC")); } // clean up repositoryService.deleteDeployment(deployment.Id, true); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testGetBinaryDataForNullFileVariable() public virtual void testGetBinaryDataForNullFileVariable() { string filename = "test.txt"; sbyte[] 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.Id)).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.StatusCode).and().contentType(ContentType.TEXT).and().body(@is(equalTo(""))).when().get(VARIABLE_INSTANCE_BINARY_DATA_URL); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testGetBinaryDataForFileVariable() public virtual void testGetBinaryDataForFileVariable() { string filename = "test.txt"; sbyte[] byteContent = "test".GetBytes(); string encoding = "UTF-8"; FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(ContentType.TEXT.ToString()).encoding(encoding).create(); HistoricVariableInstance variableInstanceMock = MockProvider.mockHistoricVariableInstance().typedValue(variableValue).build(); when(variableInstanceQueryMock.variableId(variableInstanceMock.Id)).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.StatusCode).and().body(@is(equalTo(StringHelper.NewString(byteContent)))).header("Content-Disposition", "attachment; filename=" + filename).when().get(VARIABLE_INSTANCE_BINARY_DATA_URL); //due to some problems with wildfly we gotta check this separately string contentType = response.ContentType; assertThat(contentType, @is(either(CoreMatchers.equalTo <object>(ContentType.TEXT.ToString() + "; charset=UTF-8")).or(CoreMatchers.equalTo <object>(ContentType.TEXT.ToString() + ";charset=UTF-8")))); verify(variableInstanceQueryMock, never()).disableBinaryFetching(); }
public virtual void testSerializeNullMimeTypeAndNullEncoding() { ProcessInstance pi = runtimeService.startProcessInstanceByKey("oneTaskProcess", Variables.createVariables().putValue("fileVar", Variables.fileValue("test.txt").file("ABC".GetBytes()).create())); FileValue fileVar = runtimeService.getVariableTyped(pi.Id, "fileVar"); assertNull(fileVar.MimeType); assertNull(fileVar.Encoding); }
public virtual void testSerializeEmptyFileName() { ProcessInstance pi = runtimeService.startProcessInstanceByKey("oneTaskProcess", Variables.createVariables().putValue("fileVar", Variables.fileValue("").create())); FileValue fileVar = runtimeService.getVariableTyped(pi.Id, "fileVar"); assertEquals("", fileVar.Filename); }