dan-s1 commented on code in PR #8417:
URL: https://github.com/apache/nifi/pull/8417#discussion_r1492654917
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEncodeContent.java:
##########
@@ -123,43 +122,275 @@ public void testFailDecodeNotBase32() throws IOException
{
testRunner.assertAllFlowFilesTransferred(EncodeContent.REL_FAILURE, 1);
}
- @Test
- public void testHexRoundTrip() throws IOException {
- final TestRunner testRunner = TestRunners.newTestRunner(new
EncodeContent());
+ @Test void testEncodeDecodeSpecialCharsBase64() {
+ final String specialChars = "!@#$%^&*()_+{}:\"<>?[];',./~`-=";
+ final String expectedOutput =
"IUAjJCVeJiooKV8re306Ijw+P1tdOycsLi9+YC09" + System.lineSeparator();
- testRunner.setProperty(EncodeContent.MODE, EncodeContent.ENCODE_MODE);
- testRunner.setProperty(EncodeContent.ENCODING,
EncodeContent.HEX_ENCODING);
+ executeTestSuccessHelper(EncodingMode.ENCODE,
EncodingType.BASE64_ENCODING, specialChars, expectedOutput);
+ testRunner.clearTransferState(); // clear the state for the next test
+ executeTestSuccessHelper(EncodingMode.DECODE,
EncodingType.BASE64_ENCODING, expectedOutput, specialChars);
+ }
- testRunner.enqueue(FILE_PATH);
- testRunner.clearTransferState();
- testRunner.run();
+ @Test void testBasicDecodeBase32() {
+ executeTestSuccessHelper(EncodingMode.DECODE,
EncodingType.BASE32_ENCODING, "NBSWY3DP", "hello");
+ }
- testRunner.assertAllFlowFilesTransferred(EncodeContent.REL_SUCCESS, 1);
+ @Test void testBasicDecodeBase64() {
+ executeTestSuccessHelper(EncodingMode.DECODE,
EncodingType.BASE64_ENCODING, "Zm9v", "foo");
+ }
- MockFlowFile flowFile =
testRunner.getFlowFilesForRelationship(EncodeContent.REL_SUCCESS).get(0);
- testRunner.assertQueueEmpty();
+ @Test void testBasicDecodeHex() {
+ executeTestSuccessHelper(EncodingMode.DECODE,
EncodingType.HEX_ENCODING, "666F6F", "foo");
+ }
- testRunner.setProperty(EncodeContent.MODE, EncodeContent.DECODE_MODE);
- testRunner.enqueue(flowFile);
- testRunner.clearTransferState();
- testRunner.run();
- testRunner.assertAllFlowFilesTransferred(EncodeContent.REL_SUCCESS, 1);
+ @Test void testBasicEncodeHex0() {
+ executeTestSuccessHelper(EncodingMode.ENCODE,
EncodingType.HEX_ENCODING, "hello", "68656C6C6F");
+ }
- flowFile =
testRunner.getFlowFilesForRelationship(EncodeContent.REL_SUCCESS).get(0);
- flowFile.assertContentEquals(FILE_PATH);
+ @Test void testBasicEncodeHex1() {
+ executeTestSuccessHelper(EncodingMode.ENCODE,
EncodingType.HEX_ENCODING, "foo", "666F6F");
}
- @Test
- public void testFailDecodeNotHex() throws IOException {
- final TestRunner testRunner = TestRunners.newTestRunner(new
EncodeContent());
+ @Test void testBasicEncodeBase320() {
+ executeTestSuccessHelper(EncodingMode.ENCODE,
EncodingType.BASE32_ENCODING, "hello", "NBSWY3DP" + System.lineSeparator());
+ }
- testRunner.setProperty(EncodeContent.MODE, EncodeContent.DECODE_MODE);
- testRunner.setProperty(EncodeContent.ENCODING,
EncodeContent.HEX_ENCODING);
+ @Test void testBasicEncodeBase321() {
+ executeTestSuccessHelper(EncodingMode.ENCODE,
EncodingType.BASE32_ENCODING, "foo", "MZXW6===" + System.lineSeparator());
+ }
- testRunner.enqueue(FILE_PATH);
- testRunner.clearTransferState();
+ @Test void testBasicEncodeBase640() {
+ executeTestSuccessHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ "hello",
+ "aGVsbG8=" + System.lineSeparator());
+ }
+
+ @Test void testBasicEncodeBase641() {
+ executeTestSuccessHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ "foo",
+ "Zm9v" + System.lineSeparator());
+ }
+
+ @Test void testBlankValueShouldNotFail() {
+ executeTestSuccessHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ StringUtils.EMPTY,
+ StringUtils.EMPTY);
+ }
+
+ @Test void testEncodeContentMultipleLinesBase64() {
Review Comment:
```suggestion
@Test
void testEncodeContentMultipleLinesBase64() {
```
--
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]