dan-s1 commented on code in PR #8417:
URL: https://github.com/apache/nifi/pull/8417#discussion_r1492949112
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEncodeContent.java:
##########
@@ -16,25 +16,85 @@
*/
package org.apache.nifi.processors.standard;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.stream.Stream;
+import org.apache.nifi.components.DescribedValue;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processors.standard.encoding.EncodingMode;
+import org.apache.nifi.processors.standard.encoding.EncodingType;
+import org.apache.nifi.processors.standard.encoding.LineOutputMode;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.StringUtils;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+class TestEncodeContent {
-public class TestEncodeContent {
+ private static final String LOREM_IPSUM = "Lorem ipsum dolor sit amet,
consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua.";
private static final Path FILE_PATH =
Paths.get("src/test/resources/hello.txt");
+ private TestRunner testRunner;
+
+ @BeforeEach
+ void setUp() {
+ testRunner = TestRunners.newTestRunner(EncodeContent.class);
+ }
+
+ @Test
+ void testBase64RoundTrip() throws IOException {
+ runTestRoundTrip(EncodingType.BASE64_ENCODING.getValue());
+ }
+
+ @Test
+ void testFailDecodeNotBase64() throws IOException {
+ runTestDecodeFailure(EncodingType.BASE64_ENCODING.getValue());
+ }
Review Comment:
We are getting closer. We can collapse six of the unit tests into two
parameterized tests and remove two methods. Tests`testBase64RoundTrip(),
testBase32RoundTrip() and testHexRoundTrip()` can be collapsed into a
paramaterized test with the body from `runTestRoundTrip`. In this case you
would use the `@EnumSource` annotation for the argument.
```
@ParameterizedTest
@EnumSource(value = EncodingType.class)
void testRoundTrip(EncodingType encoding) throws IOException {
testRunner.setProperty(EncodeContent.MODE, EncodingMode.ENCODE);
testRunner.setProperty(EncodeContent.ENCODING, encoding);
testRunner.enqueue(FILE_PATH);
testRunner.clearTransferState();
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EncodeContent.REL_SUCCESS,
1);
MockFlowFile flowFile =
testRunner.getFlowFilesForRelationship(EncodeContent.REL_SUCCESS).get(0);
testRunner.assertQueueEmpty();
testRunner.setProperty(EncodeContent.MODE, EncodingMode.DECODE);
testRunner.enqueue(flowFile);
testRunner.clearTransferState();
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EncodeContent.REL_SUCCESS,
1);
flowFile =
testRunner.getFlowFilesForRelationship(EncodeContent.REL_SUCCESS).get(0);
flowFile.assertContentEquals(FILE_PATH);
}
```
Please add this and implement similar code for `testFailDecodeNotHex(),
testFailDecodeNotBase32(), testFailDecodeNotHex() and runTestDecodeFailure`.
Also do not forget the import
`import org.junit.jupiter.params.provider.EnumSource;`
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]