dan-s1 commented on code in PR #8417:
URL: https://github.com/apache/nifi/pull/8417#discussion_r1492643756
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EncodeContent.java:
##########
@@ -29,55 +37,88 @@
import org.apache.nifi.annotation.documentation.CapabilityDescription;
import org.apache.nifi.annotation.documentation.Tags;
import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.expression.ExpressionLanguageScope;
import org.apache.nifi.flowfile.FlowFile;
import org.apache.nifi.processor.AbstractProcessor;
import org.apache.nifi.processor.ProcessContext;
import org.apache.nifi.processor.ProcessSession;
import org.apache.nifi.processor.Relationship;
import org.apache.nifi.processor.io.StreamCallback;
+import org.apache.nifi.processor.util.StandardValidators;
+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.processors.standard.util.ValidatingBase32InputStream;
import org.apache.nifi.processors.standard.util.ValidatingBase64InputStream;
import org.apache.nifi.stream.io.StreamUtils;
import org.apache.nifi.util.StopWatch;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
@SideEffectFree
@SupportsBatching
@InputRequirement(Requirement.INPUT_REQUIRED)
@Tags({"encode", "decode", "base64", "base32", "hex"})
@CapabilityDescription("Encode or decode the contents of a FlowFile using
Base64, Base32, or hex encoding schemes")
public class EncodeContent extends AbstractProcessor {
- public static final String ENCODE_MODE = "Encode";
- public static final String DECODE_MODE = "Decode";
-
- public static final String BASE64_ENCODING = "base64";
- public static final String BASE32_ENCODING = "base32";
- public static final String HEX_ENCODING = "hex";
-
public static final PropertyDescriptor MODE = new
PropertyDescriptor.Builder()
.name("Mode")
.description("Specifies whether the content should be encoded or
decoded")
.required(true)
- .allowableValues(ENCODE_MODE, DECODE_MODE)
- .defaultValue(ENCODE_MODE)
+ .allowableValues(EncodingMode.class)
+ .defaultValue(EncodingMode.ENCODE.getValue())
Review Comment:
`defaultValue` is overloaded to take a `DescribedValue`
```suggestion
.defaultValue(EncodingMode.ENCODE)
```
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EncodeContent.java:
##########
@@ -29,55 +37,88 @@
import org.apache.nifi.annotation.documentation.CapabilityDescription;
import org.apache.nifi.annotation.documentation.Tags;
import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.expression.ExpressionLanguageScope;
import org.apache.nifi.flowfile.FlowFile;
import org.apache.nifi.processor.AbstractProcessor;
import org.apache.nifi.processor.ProcessContext;
import org.apache.nifi.processor.ProcessSession;
import org.apache.nifi.processor.Relationship;
import org.apache.nifi.processor.io.StreamCallback;
+import org.apache.nifi.processor.util.StandardValidators;
+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.processors.standard.util.ValidatingBase32InputStream;
import org.apache.nifi.processors.standard.util.ValidatingBase64InputStream;
import org.apache.nifi.stream.io.StreamUtils;
import org.apache.nifi.util.StopWatch;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
@SideEffectFree
@SupportsBatching
@InputRequirement(Requirement.INPUT_REQUIRED)
@Tags({"encode", "decode", "base64", "base32", "hex"})
@CapabilityDescription("Encode or decode the contents of a FlowFile using
Base64, Base32, or hex encoding schemes")
public class EncodeContent extends AbstractProcessor {
- public static final String ENCODE_MODE = "Encode";
- public static final String DECODE_MODE = "Decode";
-
- public static final String BASE64_ENCODING = "base64";
- public static final String BASE32_ENCODING = "base32";
- public static final String HEX_ENCODING = "hex";
-
public static final PropertyDescriptor MODE = new
PropertyDescriptor.Builder()
.name("Mode")
.description("Specifies whether the content should be encoded or
decoded")
.required(true)
- .allowableValues(ENCODE_MODE, DECODE_MODE)
- .defaultValue(ENCODE_MODE)
+ .allowableValues(EncodingMode.class)
+ .defaultValue(EncodingMode.ENCODE.getValue())
.build();
public static final PropertyDescriptor ENCODING = new
PropertyDescriptor.Builder()
.name("Encoding")
.description("Specifies the type of encoding used")
.required(true)
- .allowableValues(BASE64_ENCODING, BASE32_ENCODING, HEX_ENCODING)
- .defaultValue(BASE64_ENCODING)
+ .allowableValues(EncodingType.class)
+ .defaultValue(EncodingType.BASE64_ENCODING.getValue())
Review Comment:
```suggestion
.defaultValue(EncodingType.BASE64_ENCODING)
```
##########
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() {
Review Comment:
```suggestion
@Test
void testBasicEncodeBase320() {
```
##########
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() {
Review Comment:
```suggestion
@Test
void testBasicDecodeHex() {
```
##########
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() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg"
+ System.lineSeparator()
+ +
"c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu"
+ System.lineSeparator()
+ + "YSBhbGlxdWEu" + System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentSingleLineBase64() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg"
+ +
"c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu"
+ + "YSBhbGlxdWEu";
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentSingleLineBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJONRWS3THEBSWY2LUF"
+ +
"QQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BAOV2CA3DBMJXXEZJAMV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===";
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentMultipleLinesBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJ" +
System.lineSeparator()
+ +
"ONRWS3THEBSWY2LUFQQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BA" +
System.lineSeparator()
+ + "OV2CA3DBMJXXEZJAMV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===" +
System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES, // set false to output multiple
lines
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentMultipleLinesNonStandardLengthBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJONRWS3TH"
+ System.lineSeparator()
+ +
"EBSWY2LUFQQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BAOV2CA3DBMJXXEZJA"
+ System.lineSeparator()
+ + "MV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===" +
System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES,
+ 80,
+ System.lineSeparator(),
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testThatLineLengthIsIgnoredIfSingleLineOutputTrueBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJONRWS3THEBSWY2LUFQQHGZLEEB"
+ +
"SG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BAOV2CA3DBMJXXEZJAMV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===";
+
+ // Setting a low value for `lineLength` but single line true ensures
that `lineLength` is ignored
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ 2, // set a low value >= 0
+ System.lineSeparator(),
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentMultipleLinesNonStandardLengthBase64() {
Review Comment:
```suggestion
@Test
void testEncodeContentMultipleLinesNonStandardLengthBase64() {
```
##########
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() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg"
+ System.lineSeparator()
+ +
"c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu"
+ System.lineSeparator()
+ + "YSBhbGlxdWEu" + System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentSingleLineBase64() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg"
+ +
"c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu"
+ + "YSBhbGlxdWEu";
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentSingleLineBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJONRWS3THEBSWY2LUF"
+ +
"QQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BAOV2CA3DBMJXXEZJAMV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===";
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentMultipleLinesBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJ" +
System.lineSeparator()
+ +
"ONRWS3THEBSWY2LUFQQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BA" +
System.lineSeparator()
+ + "OV2CA3DBMJXXEZJAMV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===" +
System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES, // set false to output multiple
lines
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentMultipleLinesNonStandardLengthBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJONRWS3TH"
+ System.lineSeparator()
+ +
"EBSWY2LUFQQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BAOV2CA3DBMJXXEZJA"
+ System.lineSeparator()
+ + "MV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===" +
System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES,
+ 80,
+ System.lineSeparator(),
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testThatLineLengthIsIgnoredIfSingleLineOutputTrueBase32() {
Review Comment:
```suggestion
@Test
void testThatLineLengthIsIgnoredIfSingleLineOutputTrueBase32() {
```
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EncodeContent.java:
##########
@@ -129,31 +175,35 @@ public void onTrigger(final ProcessContext context, final
ProcessSession session
}
}
- private static StreamCallback getStreamCallback(final boolean encode,
final String encoding) {
- if (encode) {
- if (encoding.equalsIgnoreCase(BASE64_ENCODING)) {
- return new EncodeBase64();
- } else if (encoding.equalsIgnoreCase(BASE32_ENCODING)) {
- return new EncodeBase32();
- } else {
- return new EncodeHex();
- }
- } else {
- if (encoding.equalsIgnoreCase(BASE64_ENCODING)) {
- return new DecodeBase64();
- } else if (encoding.equalsIgnoreCase(BASE32_ENCODING)) {
- return new DecodeBase32();
- } else {
- return new DecodeHex();
- }
+ private static StreamCallback getStreamCallback(final Boolean encode,
final EncodingType encoding,
Review Comment:
```suggestion
private static StreamCallback getStreamCallback(final boolean encode,
final EncodingType encoding,
```
##########
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() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg"
+ System.lineSeparator()
+ +
"c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu"
+ System.lineSeparator()
+ + "YSBhbGlxdWEu" + System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentSingleLineBase64() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg"
+ +
"c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu"
+ + "YSBhbGlxdWEu";
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentSingleLineBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJONRWS3THEBSWY2LUF"
+ +
"QQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BAOV2CA3DBMJXXEZJAMV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===";
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentMultipleLinesBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJ" +
System.lineSeparator()
+ +
"ONRWS3THEBSWY2LUFQQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BA" +
System.lineSeparator()
+ + "OV2CA3DBMJXXEZJAMV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===" +
System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES, // set false to output multiple
lines
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentMultipleLinesNonStandardLengthBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJONRWS3TH"
+ System.lineSeparator()
+ +
"EBSWY2LUFQQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BAOV2CA3DBMJXXEZJA"
+ System.lineSeparator()
+ + "MV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===" +
System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES,
+ 80,
+ System.lineSeparator(),
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testThatLineLengthIsIgnoredIfSingleLineOutputTrueBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJONRWS3THEBSWY2LUFQQHGZLEEB"
+ +
"SG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BAOV2CA3DBMJXXEZJAMV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===";
+
+ // Setting a low value for `lineLength` but single line true ensures
that `lineLength` is ignored
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ 2, // set a low value >= 0
+ System.lineSeparator(),
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentMultipleLinesNonStandardLengthBase64() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwgc2Vk"
+ System.lineSeparator()
+ +
"IGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWduYSBhbGlx"
+ System.lineSeparator()
+ + "dWEu" + System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES, // set false to output multiple
lines
+ 80,
+ System.lineSeparator(),
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testOverrideLineSeparatorBase64() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwgc2Vk"
+ "|"
+ +
"IGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWduYSBhbGlx"
+ "|"
+ + "dWEu" + "|";
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES, // set false to output multiple
lines
+ 80,
+ "|",
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testOverrideLineSeparatorBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJONRWS3TH"
+ "|"
+ +
"EBSWY2LUFQQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BAOV2CA3DBMJXXEZJA"
+ "|"
+ + "MV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===" + "|";
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES, // set false to output multiple
lines
+ 80,
+ "|",
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testThatLineLengthIsIgnoredIfSingleLineOutputTrueBase64() {
Review Comment:
```suggestion
@Test
void testThatLineLengthIsIgnoredIfSingleLineOutputTrueBase64() {
```
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EncodeContent.java:
##########
@@ -29,55 +37,88 @@
import org.apache.nifi.annotation.documentation.CapabilityDescription;
import org.apache.nifi.annotation.documentation.Tags;
import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.expression.ExpressionLanguageScope;
import org.apache.nifi.flowfile.FlowFile;
import org.apache.nifi.processor.AbstractProcessor;
import org.apache.nifi.processor.ProcessContext;
import org.apache.nifi.processor.ProcessSession;
import org.apache.nifi.processor.Relationship;
import org.apache.nifi.processor.io.StreamCallback;
+import org.apache.nifi.processor.util.StandardValidators;
+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.processors.standard.util.ValidatingBase32InputStream;
import org.apache.nifi.processors.standard.util.ValidatingBase64InputStream;
import org.apache.nifi.stream.io.StreamUtils;
import org.apache.nifi.util.StopWatch;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
@SideEffectFree
@SupportsBatching
@InputRequirement(Requirement.INPUT_REQUIRED)
@Tags({"encode", "decode", "base64", "base32", "hex"})
@CapabilityDescription("Encode or decode the contents of a FlowFile using
Base64, Base32, or hex encoding schemes")
public class EncodeContent extends AbstractProcessor {
- public static final String ENCODE_MODE = "Encode";
- public static final String DECODE_MODE = "Decode";
-
- public static final String BASE64_ENCODING = "base64";
- public static final String BASE32_ENCODING = "base32";
- public static final String HEX_ENCODING = "hex";
-
public static final PropertyDescriptor MODE = new
PropertyDescriptor.Builder()
.name("Mode")
.description("Specifies whether the content should be encoded or
decoded")
.required(true)
- .allowableValues(ENCODE_MODE, DECODE_MODE)
- .defaultValue(ENCODE_MODE)
+ .allowableValues(EncodingMode.class)
+ .defaultValue(EncodingMode.ENCODE.getValue())
.build();
public static final PropertyDescriptor ENCODING = new
PropertyDescriptor.Builder()
.name("Encoding")
.description("Specifies the type of encoding used")
.required(true)
- .allowableValues(BASE64_ENCODING, BASE32_ENCODING, HEX_ENCODING)
- .defaultValue(BASE64_ENCODING)
+ .allowableValues(EncodingType.class)
+ .defaultValue(EncodingType.BASE64_ENCODING.getValue())
+ .build();
+
+ static final PropertyDescriptor LINE_OUTPUT_MODE = new
PropertyDescriptor.Builder()
+ .name("line-output-mode")
+ .displayName("Line Output Mode")
+ .description("If set to 'single-line', the encoded FlowFile
content will output as a single line. If set to 'multiple-lines', "
+ + "it will output as multiple lines. This property is only
applicable when Base64 or Base32 encoding is selected.")
+ .required(false)
+ .defaultValue(LineOutputMode.SINGLE_LINE.getValue())
Review Comment:
```suggestion
.defaultValue(LineOutputMode.SINGLE_LINE)
```
##########
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() {
Review Comment:
Keep the annotation and the test method signature on separate lines like the
original tests were.
```suggestion
@Test
void testEncodeDecodeSpecialCharsBase64() {
```
##########
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() {
Review Comment:
```suggestion
@Test
void testBasicDecodeBase64() {
```
##########
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() {
Review Comment:
```suggestion
@Test
void testBasicEncodeBase640() {
```
##########
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() {
Review Comment:
```suggestion
@Test
void testBasicEncodeHex0() {
```
##########
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() {
Review Comment:
```suggestion
@Test
void testBasicEncodeBase641() {
```
##########
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() {
Review Comment:
```suggestion
@Test
void testBasicDecodeBase32() {
```
##########
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() {
```
##########
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() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg"
+ System.lineSeparator()
+ +
"c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu"
+ System.lineSeparator()
+ + "YSBhbGlxdWEu" + System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentSingleLineBase64() {
Review Comment:
```suggestion
@Test
void testEncodeContentSingleLineBase64() {
```
##########
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() {
Review Comment:
```suggestion
@Test
void testBasicEncodeBase321() {
```
##########
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() {
Review Comment:
```suggestion
@Test
void testBlankValueShouldNotFail() {
```
##########
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() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg"
+ System.lineSeparator()
+ +
"c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu"
+ System.lineSeparator()
+ + "YSBhbGlxdWEu" + System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentSingleLineBase64() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg"
+ +
"c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu"
+ + "YSBhbGlxdWEu";
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentSingleLineBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJONRWS3THEBSWY2LUF"
+ +
"QQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BAOV2CA3DBMJXXEZJAMV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===";
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentMultipleLinesBase32() {
Review Comment:
```suggestion
@Test
void testEncodeContentMultipleLinesBase32() {
```
##########
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() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg"
+ System.lineSeparator()
+ +
"c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu"
+ System.lineSeparator()
+ + "YSBhbGlxdWEu" + System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentSingleLineBase64() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg"
+ +
"c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu"
+ + "YSBhbGlxdWEu";
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentSingleLineBase32() {
Review Comment:
```suggestion
@Test
void testEncodeContentSingleLineBase32() {
```
##########
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() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg"
+ System.lineSeparator()
+ +
"c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu"
+ System.lineSeparator()
+ + "YSBhbGlxdWEu" + System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentSingleLineBase64() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg"
+ +
"c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu"
+ + "YSBhbGlxdWEu";
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentSingleLineBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJONRWS3THEBSWY2LUF"
+ +
"QQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BAOV2CA3DBMJXXEZJAMV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===";
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentMultipleLinesBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJ" +
System.lineSeparator()
+ +
"ONRWS3THEBSWY2LUFQQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BA" +
System.lineSeparator()
+ + "OV2CA3DBMJXXEZJAMV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===" +
System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES, // set false to output multiple
lines
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentMultipleLinesNonStandardLengthBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJONRWS3TH"
+ System.lineSeparator()
+ +
"EBSWY2LUFQQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BAOV2CA3DBMJXXEZJA"
+ System.lineSeparator()
+ + "MV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===" +
System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES,
+ 80,
+ System.lineSeparator(),
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testThatLineLengthIsIgnoredIfSingleLineOutputTrueBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJONRWS3THEBSWY2LUFQQHGZLEEB"
+ +
"SG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BAOV2CA3DBMJXXEZJAMV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===";
+
+ // Setting a low value for `lineLength` but single line true ensures
that `lineLength` is ignored
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ 2, // set a low value >= 0
+ System.lineSeparator(),
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentMultipleLinesNonStandardLengthBase64() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwgc2Vk"
+ System.lineSeparator()
+ +
"IGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWduYSBhbGlx"
+ System.lineSeparator()
+ + "dWEu" + System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES, // set false to output multiple
lines
+ 80,
+ System.lineSeparator(),
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testOverrideLineSeparatorBase64() {
Review Comment:
```suggestion
@Test
void testOverrideLineSeparatorBase64() {
```
##########
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() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg"
+ System.lineSeparator()
+ +
"c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu"
+ System.lineSeparator()
+ + "YSBhbGlxdWEu" + System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentSingleLineBase64() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg"
+ +
"c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu"
+ + "YSBhbGlxdWEu";
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentSingleLineBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJONRWS3THEBSWY2LUF"
+ +
"QQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BAOV2CA3DBMJXXEZJAMV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===";
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentMultipleLinesBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJ" +
System.lineSeparator()
+ +
"ONRWS3THEBSWY2LUFQQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BA" +
System.lineSeparator()
+ + "OV2CA3DBMJXXEZJAMV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===" +
System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES, // set false to output multiple
lines
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentMultipleLinesNonStandardLengthBase32() {
Review Comment:
```suggestion
@Test
void testEncodeContentMultipleLinesNonStandardLengthBase32() {
```
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEncodeContent.java:
##########
@@ -16,65 +16,50 @@
*/
package org.apache.nifi.processors.standard;
+import static org.junit.Assert.assertEquals;
+
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
+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;
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
+ public void setUp() {
+ testRunner = TestRunners.newTestRunner(EncodeContent.class);
+ }
@Test
public void testBase64RoundTrip() throws IOException {
Review Comment:
Since you are adding other tests which do not have `public`, please remove
`public` from this test and any other test which has `public` since for JUnit 5
`public` is not needed.
```suggestion
void testBase64RoundTrip() throws IOException {
```
##########
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() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg"
+ System.lineSeparator()
+ +
"c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu"
+ System.lineSeparator()
+ + "YSBhbGlxdWEu" + System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentSingleLineBase64() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg"
+ +
"c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu"
+ + "YSBhbGlxdWEu";
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentSingleLineBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJONRWS3THEBSWY2LUF"
+ +
"QQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BAOV2CA3DBMJXXEZJAMV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===";
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentMultipleLinesBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJ" +
System.lineSeparator()
+ +
"ONRWS3THEBSWY2LUFQQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BA" +
System.lineSeparator()
+ + "OV2CA3DBMJXXEZJAMV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===" +
System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES, // set false to output multiple
lines
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentMultipleLinesNonStandardLengthBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJONRWS3TH"
+ System.lineSeparator()
+ +
"EBSWY2LUFQQHGZLEEBSG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BAOV2CA3DBMJXXEZJA"
+ System.lineSeparator()
+ + "MV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===" +
System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES,
+ 80,
+ System.lineSeparator(),
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testThatLineLengthIsIgnoredIfSingleLineOutputTrueBase32() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"JRXXEZLNEBUXA43VNUQGI33MN5ZCA43JOQQGC3LFOQWCAY3PNZZWKY3UMV2HK4RAMFSGS4DJONRWS3THEBSWY2LUFQQHGZLEEB"
+ +
"SG6IDFNF2XG3LPMQQHIZLNOBXXEIDJNZRWSZDJMR2W45BAOV2CA3DBMJXXEZJAMV2CAZDPNRXXEZJANVQWO3TBEBQWY2LROVQS4===";
+
+ // Setting a low value for `lineLength` but single line true ensures
that `lineLength` is ignored
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE32_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.SINGLE_LINE,
+ 2, // set a low value >= 0
+ System.lineSeparator(),
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testEncodeContentMultipleLinesNonStandardLengthBase64() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwgc2Vk"
+ System.lineSeparator()
+ +
"IGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWduYSBhbGlx"
+ System.lineSeparator()
+ + "dWEu" + System.lineSeparator();
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES, // set false to output multiple
lines
+ 80,
+ System.lineSeparator(),
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testOverrideLineSeparatorBase64() {
+ // this input is greater than 57 bytes, sure to generate multiple
lines in base64
+ final String expectedOutput =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwgc2Vk"
+ "|"
+ +
"IGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWduYSBhbGlx"
+ "|"
+ + "dWEu" + "|";
+
+ // Execute the test using the helper method
+ executeTestHelper(EncodingMode.ENCODE,
+ EncodingType.BASE64_ENCODING,
+ LOREM_IPSUM,
+ LineOutputMode.MULTIPLE_LINES, // set false to output multiple
lines
+ 80,
+ "|",
+ expectedOutput,
+ EncodeContent.REL_SUCCESS);
+ }
+
+ @Test void testOverrideLineSeparatorBase32() {
Review Comment:
```suggestion
@Test
void testOverrideLineSeparatorBase32() {
```
--
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]