Github user olegz commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1179#discussion_r87201121
--- Diff:
nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/test/java/org/apache/nifi/processors/avro/TestConvertAvroToJSON.java
---
@@ -239,6 +239,37 @@ public void
testSingleSchemalessAvroMessage_wrapSingleMessage_noContainer() thro
}
@Test
+ public void
testSingleSchemalessAvroMessage_wrapSingleMessage_noContainer_StandardJson()
throws IOException {
+ final TestRunner runner = TestRunners.newTestRunner(new
ConvertAvroToJSON());
+ runner.setProperty(ConvertAvroToJSON.CONTAINER_OPTIONS,
ConvertAvroToJSON.CONTAINER_NONE);
+ runner.setProperty(ConvertAvroToJSON.WRAP_SINGLE_RECORD,
Boolean.toString(true));
+ Schema schema = new Schema.Parser().parse(new
File("src/test/resources/user.avsc"));
+ String stringSchema = schema.toString();
+ runner.setProperty(ConvertAvroToJSON.SCHEMA, stringSchema);
+ runner.setProperty(ConvertAvroToJSON.USE_STANDARD_JSON, "true");
+
+ final GenericRecord user1 = new GenericData.Record(schema);
+ user1.put("name", "Alyssa");
+ user1.put("favorite_number", 256);
+
+ final ByteArrayOutputStream out1 = new ByteArrayOutputStream();
+ final BinaryEncoder encoder =
EncoderFactory.get().binaryEncoder(out1, null);
+ final DatumWriter<GenericRecord> datumWriter = new
GenericDatumWriter<>(schema);
+ datumWriter.write(user1, encoder);
+
+ encoder.flush();
+ out1.flush();
+ byte[] test = out1.toByteArray();
+ runner.enqueue(test);
+
+ runner.run();
+
+
runner.assertAllFlowFilesTransferred(ConvertAvroToJSON.REL_SUCCESS, 1);
+ final MockFlowFile out =
runner.getFlowFilesForRelationship(ConvertAvroToJSON.REL_SUCCESS).get(0);
+
out.assertContentEquals("{\"name\":\"Alyssa\",\"favorite_number\":{\"int\":256},\"favorite_color\":null}");
--- End diff --
Thanks @rdblue , will polish the code to reflect that
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---