exceptionfactory commented on code in PR #10187:
URL: https://github.com/apache/nifi/pull/10187#discussion_r2271477915
##########
nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/xml/TestXMLRecordReader.java:
##########
@@ -62,6 +62,39 @@ public void testSingleRecord() throws IOException,
MalformedRecordException {
assertNull(reader.nextRecord());
}
+ @Test
+ public void testEmptyFieldNameForContentProperty() throws Exception {
+ final String contentFieldName = "";
+ final boolean parseXmlAttributes = true;
+ final RecordSchema schema = new
SimpleRecordSchema(Collections.emptyList());
+ final byte[] xml = "<note><to
alias=\"TK\">Kyle</to></note>".getBytes(java.nio.charset.StandardCharsets.UTF_8);
+ ComponentLog logger = Mockito.mock(ComponentLog.class);
+ XMLRecordReader reader = new XMLRecordReader(
+ new ByteArrayInputStream(xml),
+ schema,
+ parseXmlAttributes,
+ false,
+ "",
+ contentFieldName,
+ "",
+ "note",
+ "",
+ logger
+ );
+ Record record = reader.nextRecord();
+ assertNotNull(record, "Record should not be null");
+ Object toFieldObj = record.getValue("to");
+ if (toFieldObj == null) {
+ assertNull(toFieldObj, "'to' field is null as expected when
contentFieldName is empty");
+ } else {
+ assertInstanceOf(Record.class, toFieldObj, "'to' field should be a
Record");
+ Record toField = (Record) toFieldObj;
+ Object valueField = toField.getValue("value");
+ assertNotNull(valueField, "'value' field should exist inside 'to'
record");
+ assertEquals("Kyle", valueField, "'value' field should contain the
correct content");
+ }
Review Comment:
This conditional seems problematic, the test should be deterministic,
expecting one output or the other.
--
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]