Exemple #1
0
//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);
        }
Exemple #2
0
        public virtual void testSerializeNullMimeType()
        {
            ProcessInstance pi = runtimeService.startProcessInstanceByKey("oneTaskProcess", Variables.createVariables().putValue("fileVar", Variables.fileValue("test.txt").file("ABC".GetBytes()).encoding("UTF-8").create()));

            FileValue fileVar = runtimeService.getVariableTyped(pi.Id, "fileVar");

            assertNull(fileVar.MimeType);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void execute(org.camunda.bpm.engine.delegate.DelegateExecution execution) throws Exception
        public virtual void execute(DelegateExecution execution)
        {
            bool?     shouldFail         = (bool?)execution.getVariable("shouldFail");
            FileValue invoiceDocumentVar = execution.getVariableTyped("invoiceDocument");

            if (shouldFail != null && shouldFail)
            {
                throw new ProcessEngineException("Could not archive invoice...");
            }
            else
            {
                LOGGER.info("\n\n  ... Now archiving invoice " + execution.getVariable("invoiceNumber") + ", filename: " + invoiceDocumentVar.Filename + " \n\n");
            }
        }
Exemple #5
0
//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);
        }
Exemple #6
0
//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();
        }