From 74a4104259e83b302d139fbc4216f9e3b2fe3c3e Mon Sep 17 00:00:00 2001 From: exceptionfactory Date: Wed, 6 Apr 2022 11:26:08 -0500 Subject: [PATCH] NIFI-9882 Updated HtmlDocumentationWriter to avoid writing null characters This closes #5935 Signed-off-by: Mike Thomsen --- .../html/HtmlDocumentationWriter.java | 22 +++++++++------ .../html/HtmlDocumentationWriterTest.java | 28 ++++++++++--------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlDocumentationWriter.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlDocumentationWriter.java index 90209cc571..8464143ce1 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlDocumentationWriter.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlDocumentationWriter.java @@ -843,16 +843,20 @@ public class HtmlDocumentationWriter implements DocumentationWriter { protected final static void writeSimpleElement(final XMLStreamWriter writer, final String elementName, final String characters, boolean strong, String id) throws XMLStreamException { writer.writeStartElement(elementName); - if (id != null) { - writer.writeAttribute("id", id); - } - if (strong) { - writer.writeStartElement("strong"); - } - writer.writeCharacters(characters); - if (strong) { - writer.writeEndElement(); + + if (characters != null) { + if (id != null) { + writer.writeAttribute("id", id); + } + if (strong) { + writer.writeStartElement("strong"); + } + writer.writeCharacters(characters); + if (strong) { + writer.writeEndElement(); + } } + writer.writeEndElement(); } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/HtmlDocumentationWriterTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/HtmlDocumentationWriterTest.java index c37ebeb36b..89bd6a566d 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/HtmlDocumentationWriterTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/HtmlDocumentationWriterTest.java @@ -32,21 +32,20 @@ import org.apache.nifi.nar.ExtensionManager; import org.apache.nifi.nar.StandardExtensionDiscoveringManager; import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.reporting.ReportingTask; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; import java.io.ByteArrayOutputStream; import java.io.IOException; import static org.apache.nifi.documentation.html.XmlValidator.assertContains; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class HtmlDocumentationWriterTest { private ExtensionManager extensionManager; - @Before + @BeforeEach public void setup() { extensionManager = new StandardExtensionDiscoveringManager(); } @@ -89,6 +88,9 @@ public class HtmlDocumentationWriterTest { assertContains(results, "PKCS12"); assertContains(results, "Sensitive Property: true"); + // property with null default value + assertContains(results, "Keystore Password"); + // restricted assertContains(results, "controller service restriction description"); @@ -101,11 +103,11 @@ public class HtmlDocumentationWriterTest { assertContains(results, "Not Specified"); // verify the right OnRemoved and OnShutdown methods were called - Assert.assertEquals(0, controllerService.getOnRemovedArgs()); - Assert.assertEquals(0, controllerService.getOnRemovedNoArgs()); + assertEquals(0, controllerService.getOnRemovedArgs()); + assertEquals(0, controllerService.getOnRemovedNoArgs()); - Assert.assertEquals(1, controllerService.getOnShutdownArgs()); - Assert.assertEquals(1, controllerService.getOnShutdownNoArgs()); + assertEquals(1, controllerService.getOnShutdownArgs()); + assertEquals(1, controllerService.getOnShutdownNoArgs()); } @Test @@ -149,11 +151,11 @@ public class HtmlDocumentationWriterTest { assertContains(results, "Not Specified"); // verify the right OnRemoved and OnShutdown methods were called - Assert.assertEquals(0, reportingTask.getOnRemovedArgs()); - Assert.assertEquals(0, reportingTask.getOnRemovedNoArgs()); + assertEquals(0, reportingTask.getOnRemovedArgs()); + assertEquals(0, reportingTask.getOnRemovedNoArgs()); - Assert.assertEquals(1, reportingTask.getOnShutdownArgs()); - Assert.assertEquals(1, reportingTask.getOnShutdownNoArgs()); + assertEquals(1, reportingTask.getOnShutdownArgs()); + assertEquals(1, reportingTask.getOnShutdownNoArgs()); } @Test