This is an automated email from the ASF dual-hosted git repository.
turcsanyi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new edd862bf55 NIFI-10013 For JASN1RecordReader added unit test for
checking multi-record input.
edd862bf55 is described below
commit edd862bf55f34c8f45c1817603e303cea6254f81
Author: Tamas Palfy <[email protected]>
AuthorDate: Wed Jun 1 20:16:28 2022 +0200
NIFI-10013 For JASN1RecordReader added unit test for checking multi-record
input.
This closes #6091.
Signed-off-by: Peter Turcsanyi <[email protected]>
---
.../apache/nifi/jasn1/ExampleDataGenerator.java | 29 +++++++++++++++++++
.../apache/nifi/jasn1/TestJASN1RecordReader.java | 31 +++++++++++++++++++++
.../src/test/resources/examples/multi-record.dat | Bin 0 -> 124 bytes
3 files changed, 60 insertions(+)
diff --git
a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/ExampleDataGenerator.java
b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/ExampleDataGenerator.java
index 75ca9e1ef6..878e821ccd 100644
---
a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/ExampleDataGenerator.java
+++
b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/ExampleDataGenerator.java
@@ -49,6 +49,8 @@ public class ExampleDataGenerator {
generateBasicTypes(dir);
generateComposite(dir);
+
+ generateMultiRecord(dir);
}
private static void generateBasicTypes(File dir) throws IOException {
@@ -112,4 +114,31 @@ public class ExampleDataGenerator {
}
}
+
+ private static void generateMultiRecord(File dir) throws IOException {
+ final File file = new File(dir, "multi-record.dat");
+ try (
+ final ReverseByteArrayOutputStream rev = new
ReverseByteArrayOutputStream(1024);
+ final OutputStream out = new FileOutputStream(file)
+ ) {
+
+ int record1Length = write(rev, out, true, 123, new byte[]{1, 2, 3,
4, 5}, "Some UTF-8 String. こんにちは世界。");
+ int record2Length = write(rev, out, false, 456, new byte[]{6, 7,
8, 9, 10}, "Another UTF-8 String. こんばんは世界。");
+
+ LOG.info("Generated {} bytes to {}", record1Length +
record2Length, file);
+ }
+ }
+
+ private static int write(ReverseByteArrayOutputStream rev, OutputStream
out, boolean b, int i, byte[] octStr, String uft8Str) throws IOException {
+ BasicTypes basicTypes = new BasicTypes();
+ basicTypes.setB(new BerBoolean(b));
+ basicTypes.setI(new BerInteger(i));
+ basicTypes.setOctStr(new BerOctetString(octStr));
+ basicTypes.setUtf8Str(new BerUTF8String(uft8Str));
+
+ int encoded = basicTypes.encode(rev);
+ out.write(rev.getArray(), 0, encoded);
+
+ return encoded;
+ }
}
diff --git
a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestJASN1RecordReader.java
b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestJASN1RecordReader.java
index dda8d593c2..e40027c149 100644
---
a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestJASN1RecordReader.java
+++
b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestJASN1RecordReader.java
@@ -121,4 +121,35 @@ public class TestJASN1RecordReader implements
JASN1ReadRecordTester {
assertNull(record);
}
}
+
+ @Test
+ public void testMultiRecord() throws Exception {
+ try (final InputStream input =
TestJASN1RecordReader.class.getResourceAsStream("/examples/multi-record.dat")) {
+ final JASN1RecordReader reader = new
JASN1RecordReader("org.apache.nifi.jasn1.example.BasicTypes", null,
+ new RecordSchemaProvider(),
Thread.currentThread().getContextClassLoader(), null,
+ input, new MockComponentLog("id", new JASN1Reader()));
+
+ final RecordSchema schema = reader.getSchema();
+ assertEquals("BasicTypes", schema.getSchemaName().orElse(null));
+
+ Record record1 = reader.nextRecord(true, false);
+ assertNotNull(record1);
+
+ assertEquals(true, record1.getAsBoolean("b"));
+ assertEquals(123, record1.getAsInt("i").intValue());
+ assertEquals("0102030405", record1.getValue("octStr"));
+ assertEquals("Some UTF-8 String. こんにちは世界。",
record1.getValue("utf8Str"));
+
+ Record record2 = reader.nextRecord(true, false);
+ assertNotNull(record2);
+
+ assertEquals(false, record2.getAsBoolean("b"));
+ assertEquals(456, record2.getAsInt("i").intValue());
+ assertEquals("060708090A", record2.getValue("octStr"));
+ assertEquals("Another UTF-8 String. こんばんは世界。",
record2.getValue("utf8Str"));
+
+ Record record3 = reader.nextRecord(true, false);
+ assertNull(record3);
+ }
+ }
}
diff --git
a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/resources/examples/multi-record.dat
b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/resources/examples/multi-record.dat
new file mode 100644
index 0000000000..8fdf53df2c
Binary files /dev/null and
b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/resources/examples/multi-record.dat
differ