NIFI-280 - adding additional unit tests Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/74857166 Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/74857166 Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/74857166
Branch: refs/heads/NIFI-353 Commit: 74857166f8eb757754283960867ad7fda9541d05 Parents: d53abf0 Author: danbress <[email protected]> Authored: Sun Feb 8 14:34:56 2015 -0500 Committer: danbress <[email protected]> Committed: Sun Feb 8 14:34:56 2015 -0500 ---------------------------------------------------------------------- .../example/FullyDocumentedProcessor.java | 5 +++ .../documentation/example/NakedProcessor.java | 16 ++++++++ .../documentation/example/SampleService.java | 25 ++++++++++++ .../html/HtmlDocumentationWriterTest.java | 43 ++++++++++++++++++-- .../html/ProcessorDocumentationWriterTest.java | 38 ++++++++++++++++- 5 files changed, 122 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/74857166/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java index e1b8634..c2c7657 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java @@ -57,6 +57,10 @@ public class FullyDocumentedProcessor extends AbstractProcessor { public static final PropertyDescriptor TYPE_PROPERTY = new PropertyDescriptor.Builder() .name("Type").description("This is the type of something that you can choose. It has several possible values").allowableValues("yes", "no", "maybe", "possibly", "not likely", "longer option name").required(true).build(); + public static final PropertyDescriptor SERVICE_PROPERTY = new PropertyDescriptor.Builder() + .name("Controller Service").description("This is the controller service to use to do things") + .identifiesControllerService(SampleService.class).required(true).build(); + public static final Relationship REL_SUCCESS = new Relationship.Builder().name("success") .description("Successful files").build(); public static final Relationship REL_FAILURE = new Relationship.Builder().name("failure") @@ -73,6 +77,7 @@ public class FullyDocumentedProcessor extends AbstractProcessor { properties.add(POLLING_INTERVAL); properties.add(OPTIONAL_PROPERTY); properties.add(TYPE_PROPERTY); + properties.add(SERVICE_PROPERTY); this.properties = Collections.unmodifiableList(properties); final Set<Relationship> relationships = new HashSet<>(); http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/74857166/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/NakedProcessor.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/NakedProcessor.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/NakedProcessor.java new file mode 100644 index 0000000..6fce1e1 --- /dev/null +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/NakedProcessor.java @@ -0,0 +1,16 @@ +package org.apache.nifi.documentation.example; + +import org.apache.nifi.processor.AbstractProcessor; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processor.exception.ProcessException; + +public class NakedProcessor extends AbstractProcessor { + + @Override + public void onTrigger(ProcessContext arg0, ProcessSession arg1) throws ProcessException { + // TODO Auto-generated method stub + + } + +} http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/74857166/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/SampleService.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/SampleService.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/SampleService.java new file mode 100644 index 0000000..6224364 --- /dev/null +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/SampleService.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.documentation.example; + +import org.apache.nifi.controller.ControllerService; + +public interface SampleService extends ControllerService { + + public void doSomething(); + +} http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/74857166/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/HtmlDocumentationWriterTest.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/HtmlDocumentationWriterTest.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/HtmlDocumentationWriterTest.java index f685f39..9d7926e 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/HtmlDocumentationWriterTest.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/HtmlDocumentationWriterTest.java @@ -16,6 +16,7 @@ */ package org.apache.nifi.documentation.html; +import java.io.ByteArrayOutputStream; import java.io.IOException; import org.apache.nifi.controller.ControllerService; @@ -28,6 +29,8 @@ import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.reporting.ReportingTask; import org.junit.Test; +import static org.apache.nifi.documentation.html.XmlValidator.assertContains; + public class HtmlDocumentationWriterTest { @Test @@ -38,8 +41,26 @@ public class HtmlDocumentationWriterTest { DocumentationWriter writer = new HtmlDocumentationWriter(); - writer.write(controllerService, System.out, false); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + writer.write(controllerService, baos, false); + + String results = new String(baos.toByteArray()); + XmlValidator.assertXmlValid(results); + // description + assertContains(results, "A documented controller service that can help you do things"); + + // tags + assertContains(results, "one, two, three"); + + // properties + assertContains(results, "Keystore Filename"); + assertContains(results, "The fully-qualified filename of the Keystore"); + assertContains(results, "Keystore Type"); + assertContains(results, "JKS"); + assertContains(results, "PKCS12"); + assertContains(results, "Sensitive Property: true"); } @Test @@ -50,7 +71,23 @@ public class HtmlDocumentationWriterTest { DocumentationWriter writer = new HtmlDocumentationWriter(); - writer.write(reportingTask, System.out, false); - } + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + writer.write(reportingTask, baos, false); + + String results = new String(baos.toByteArray()); + XmlValidator.assertXmlValid(results); + + // description + assertContains(results, "A helper reporting task to do..."); + + // tags + assertContains(results, "first, second, third"); + + // properties + assertContains(results, "Show Deltas"); + assertContains(results, "Specifies whether or not to show the difference in values between the current status and the previous status"); + assertContains(results, "true"); + assertContains(results, "false"); + } } http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/74857166/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java index faf66b5..5306ddf 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java @@ -25,6 +25,7 @@ import java.io.IOException; import org.apache.nifi.annotation.documentation.CapabilityDescription; import org.apache.nifi.documentation.DocumentationWriter; import org.apache.nifi.documentation.example.FullyDocumentedProcessor; +import org.apache.nifi.documentation.example.NakedProcessor; import org.apache.nifi.documentation.mock.MockProcessorInitializationContext; import org.junit.Test; @@ -40,8 +41,9 @@ public class ProcessorDocumentationWriterTest { ByteArrayOutputStream baos = new ByteArrayOutputStream(); writer.write(processor, baos, false); - + String results = new String(baos.toByteArray()); + XmlValidator.assertXmlValid(results); assertContains(results, FullyDocumentedProcessor.DIRECTORY.getDisplayName()); assertContains(results, FullyDocumentedProcessor.DIRECTORY.getDescription()); @@ -57,13 +59,45 @@ public class ProcessorDocumentationWriterTest { assertContains(results, FullyDocumentedProcessor.REL_SUCCESS.getDescription()); assertContains(results, FullyDocumentedProcessor.REL_FAILURE.getName()); assertContains(results, FullyDocumentedProcessor.REL_FAILURE.getDescription()); + assertContains(results, "Controller Service: "); + assertContains(results, "SampleService"); assertNotContains(results, "iconSecure.png"); - assertContains(results, FullyDocumentedProcessor.class.getAnnotation(CapabilityDescription.class).value()); + assertContains(results, FullyDocumentedProcessor.class.getAnnotation(CapabilityDescription.class) + .value()); assertNotContains(results, "This component has no required or optional properties."); assertNotContains(results, "No description provided."); assertNotContains(results, "No Tags provided."); assertNotContains(results, "Additional Details..."); } + @Test + public void testNakedProcessor() throws IOException { + NakedProcessor processor = new NakedProcessor(); + processor.initialize(new MockProcessorInitializationContext()); + + DocumentationWriter writer = new HtmlProcessorDocumentationWriter(); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + writer.write(processor, baos, false); + + String results = new String(baos.toByteArray()); + XmlValidator.assertXmlValid(results); + + // no description + assertContains(results, "No description provided."); + + // no tags + assertContains(results, "None."); + + // properties + assertContains(results, "This component has no required or optional properties."); + + // relationships + assertContains(results, "This processor has no relationships."); + + + } + }
