mirror of
https://github.com/apache/nifi.git
synced 2025-03-06 01:19:49 +00:00
NIFI-10013 For JASN1RecordReader added unit test for checking multi-record input.
This closes #6091. Signed-off-by: Peter Turcsanyi <turcsanyi@apache.org>
This commit is contained in:
parent
bc84532a8b
commit
edd862bf55
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user