You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/05/14 21:29:55 UTC

[GitHub] [nifi] ottobackwards commented on a change in pull request #4275: NIFI-6497: Allow FreeFormTextRecordSetWriter to access FlowFile Attributes

ottobackwards commented on a change in pull request #4275:
URL: https://github.com/apache/nifi/pull/4275#discussion_r425440486



##########
File path: nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/text/TestFreeFormTextRecordSetWriter.java
##########
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.text;
+
+import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.schema.access.SchemaAccessUtils;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestFreeFormTextRecordSetWriter {
+
+    private TestRunner setup(FreeFormTextRecordSetWriter writer) throws InitializationException, IOException {
+        TestRunner runner = TestRunners.newTestRunner(TestFreeFormTextRecordSetWriterProcessor.class);
+
+        final String outputSchemaText = new String(Files.readAllBytes(Paths.get("src/test/resources/text/testschema")));
+
+        runner.addControllerService("writer", writer);
+        runner.setProperty(TestFreeFormTextRecordSetWriterProcessor.WRITER, "writer");
+
+        runner.setProperty(writer, SchemaAccessUtils.SCHEMA_ACCESS_STRATEGY, SchemaAccessUtils.SCHEMA_TEXT_PROPERTY);
+        runner.setProperty(writer, SchemaAccessUtils.SCHEMA_TEXT, outputSchemaText);
+        runner.setProperty(writer, FreeFormTextRecordSetWriter.TEXT, "ID: ${ID}, Name: ${NAME}, Age: ${AGE}, Country: ${COUNTRY}, Username: ${user.name}");
+
+        return runner;
+    }
+
+    @Test
+    public void testDefault() throws IOException, InitializationException {
+        FreeFormTextRecordSetWriter writer = new FreeFormTextRecordSetWriter();
+        TestRunner runner = setup(writer);
+
+        runner.enableControllerService(writer);
+        Map<String, String> attributes = new HashMap<>();
+        attributes.put("user.name", "jdoe64");
+        runner.enqueue("", attributes);
+        runner.run();
+        runner.assertQueueEmpty();
+        runner.assertAllFlowFilesTransferred(TestFreeFormTextRecordSetWriterProcessor.SUCCESS, 1);
+

Review comment:
       This is pretty neat, but I had to go through the code and debug to figure out why there were two return values here, because just looking at it it looks wrong.
   
   Maybe a comment or two to help help here would be good.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org