NIFI-7184 - This closes #4074. Added mime type property to GenerateFlowFile

Signed-off-by: Joe Witt <joewitt@apache.org>
This commit is contained in:
Pierre Villard 2020-02-21 19:06:12 -08:00 committed by Joe Witt
parent 9a8a551e03
commit fd7c01453b
No known key found for this signature in database
GPG Key ID: 9093BF854F811A1A
2 changed files with 18 additions and 1 deletions

View File

@ -43,6 +43,7 @@ import org.apache.nifi.components.ValidationResult;
import org.apache.nifi.expression.AttributeExpression;
import org.apache.nifi.expression.ExpressionLanguageScope;
import org.apache.nifi.flowfile.FlowFile;
import org.apache.nifi.flowfile.attributes.CoreAttributes;
import org.apache.nifi.processor.AbstractProcessor;
import org.apache.nifi.processor.DataUnit;
import org.apache.nifi.processor.ProcessContext;
@ -115,6 +116,13 @@ public class GenerateFlowFile extends AbstractProcessor {
.defaultValue("UTF-8")
.addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
.build();
public static final PropertyDescriptor MIME_TYPE = new PropertyDescriptor.Builder()
.name("mime-type")
.displayName("Mime Type")
.description("Specifies the value to set for the \"mime.type\" attribute.")
.required(false)
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
.build();
public static final Relationship SUCCESS = new Relationship.Builder()
.name("success")
@ -134,6 +142,7 @@ public class GenerateFlowFile extends AbstractProcessor {
descriptors.add(UNIQUE_FLOWFILES);
descriptors.add(CUSTOM_TEXT);
descriptors.add(CHARSET);
descriptors.add(MIME_TYPE);
this.descriptors = Collections.unmodifiableList(descriptors);
final Set<Relationship> relationships = new HashSet<>();
@ -226,6 +235,10 @@ public class GenerateFlowFile extends AbstractProcessor {
}
}
if(context.getProperty(MIME_TYPE).isSet()) {
generatedAttributes.put(CoreAttributes.MIME_TYPE.key(), context.getProperty(MIME_TYPE).getValue());
}
for (int i = 0; i < context.getProperty(BATCH_SIZE).asInteger(); i++) {
FlowFile flowFile = session.create();
if (data.length > 0) {

View File

@ -38,7 +38,9 @@ public class TestGenerateFlowFile {
runner.run();
runner.assertTransferCount(GenerateFlowFile.SUCCESS, 1);
runner.getFlowFilesForRelationship(GenerateFlowFile.SUCCESS).get(0).assertContentEquals("This is my custom text!");
MockFlowFile generatedFlowFile = runner.getFlowFilesForRelationship(GenerateFlowFile.SUCCESS).get(0);
generatedFlowFile.assertContentEquals("This is my custom text!");
generatedFlowFile.assertAttributeNotExists("mime.type");
}
@Test
@ -59,6 +61,7 @@ public class TestGenerateFlowFile {
TestRunner runner = TestRunners.newTestRunner(new GenerateFlowFile());
runner.setProperty(GenerateFlowFile.FILE_SIZE, "1B");
runner.setProperty(GenerateFlowFile.DATA_FORMAT, GenerateFlowFile.DATA_FORMAT_TEXT);
runner.setProperty(GenerateFlowFile.MIME_TYPE, "application/text");
runner.setProperty("plain.dynamic.property", "Plain Value");
runner.setProperty("expression.dynamic.property", "${literal('Expression Value')}");
runner.assertValid();
@ -69,6 +72,7 @@ public class TestGenerateFlowFile {
MockFlowFile generatedFlowFile = runner.getFlowFilesForRelationship(GenerateFlowFile.SUCCESS).get(0);
generatedFlowFile.assertAttributeEquals("plain.dynamic.property", "Plain Value");
generatedFlowFile.assertAttributeEquals("expression.dynamic.property", "Expression Value");
generatedFlowFile.assertAttributeEquals("mime.type", "application/text");
}
}