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



##########
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:
       Good point, I copy-pasted the code from the XML writer test and kind of 
left it alone, but you're right it could use more comments. Same goes for the 
test processor, I had to do it a bit differently than the XML one because it 
must inherit the writer schema from the reader (even though it doesn't do 
anything with it). Good catch! will update




----------------------------------------------------------------
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:
[email protected]


Reply via email to