NIFI-280 - adding additional unit tests

This commit is contained in:
danbress 2015-02-08 14:34:56 -05:00
parent d53abf02d1
commit 74857166f8
5 changed files with 122 additions and 5 deletions

View File

@ -57,6 +57,10 @@ public class FullyDocumentedProcessor extends AbstractProcessor {
public static final PropertyDescriptor TYPE_PROPERTY = new PropertyDescriptor.Builder() 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(); .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") public static final Relationship REL_SUCCESS = new Relationship.Builder().name("success")
.description("Successful files").build(); .description("Successful files").build();
public static final Relationship REL_FAILURE = new Relationship.Builder().name("failure") 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(POLLING_INTERVAL);
properties.add(OPTIONAL_PROPERTY); properties.add(OPTIONAL_PROPERTY);
properties.add(TYPE_PROPERTY); properties.add(TYPE_PROPERTY);
properties.add(SERVICE_PROPERTY);
this.properties = Collections.unmodifiableList(properties); this.properties = Collections.unmodifiableList(properties);
final Set<Relationship> relationships = new HashSet<>(); final Set<Relationship> relationships = new HashSet<>();

View File

@ -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
}
}

View File

@ -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();
}

View File

@ -16,6 +16,7 @@
*/ */
package org.apache.nifi.documentation.html; package org.apache.nifi.documentation.html;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import org.apache.nifi.controller.ControllerService; import org.apache.nifi.controller.ControllerService;
@ -28,6 +29,8 @@ import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.reporting.ReportingTask; import org.apache.nifi.reporting.ReportingTask;
import org.junit.Test; import org.junit.Test;
import static org.apache.nifi.documentation.html.XmlValidator.assertContains;
public class HtmlDocumentationWriterTest { public class HtmlDocumentationWriterTest {
@Test @Test
@ -38,8 +41,26 @@ public class HtmlDocumentationWriterTest {
DocumentationWriter writer = new HtmlDocumentationWriter(); 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 @Test
@ -50,7 +71,23 @@ public class HtmlDocumentationWriterTest {
DocumentationWriter writer = new HtmlDocumentationWriter(); 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");
}
} }

View File

@ -25,6 +25,7 @@ import java.io.IOException;
import org.apache.nifi.annotation.documentation.CapabilityDescription; import org.apache.nifi.annotation.documentation.CapabilityDescription;
import org.apache.nifi.documentation.DocumentationWriter; import org.apache.nifi.documentation.DocumentationWriter;
import org.apache.nifi.documentation.example.FullyDocumentedProcessor; import org.apache.nifi.documentation.example.FullyDocumentedProcessor;
import org.apache.nifi.documentation.example.NakedProcessor;
import org.apache.nifi.documentation.mock.MockProcessorInitializationContext; import org.apache.nifi.documentation.mock.MockProcessorInitializationContext;
import org.junit.Test; import org.junit.Test;
@ -42,6 +43,7 @@ public class ProcessorDocumentationWriterTest {
writer.write(processor, baos, false); writer.write(processor, baos, false);
String results = new String(baos.toByteArray()); String results = new String(baos.toByteArray());
XmlValidator.assertXmlValid(results);
assertContains(results, FullyDocumentedProcessor.DIRECTORY.getDisplayName()); assertContains(results, FullyDocumentedProcessor.DIRECTORY.getDisplayName());
assertContains(results, FullyDocumentedProcessor.DIRECTORY.getDescription()); assertContains(results, FullyDocumentedProcessor.DIRECTORY.getDescription());
@ -57,13 +59,45 @@ public class ProcessorDocumentationWriterTest {
assertContains(results, FullyDocumentedProcessor.REL_SUCCESS.getDescription()); assertContains(results, FullyDocumentedProcessor.REL_SUCCESS.getDescription());
assertContains(results, FullyDocumentedProcessor.REL_FAILURE.getName()); assertContains(results, FullyDocumentedProcessor.REL_FAILURE.getName());
assertContains(results, FullyDocumentedProcessor.REL_FAILURE.getDescription()); assertContains(results, FullyDocumentedProcessor.REL_FAILURE.getDescription());
assertContains(results, "Controller Service: ");
assertContains(results, "SampleService");
assertNotContains(results, "iconSecure.png"); 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, "This component has no required or optional properties.");
assertNotContains(results, "No description provided."); assertNotContains(results, "No description provided.");
assertNotContains(results, "No Tags provided."); assertNotContains(results, "No Tags provided.");
assertNotContains(results, "Additional Details..."); 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.");
}
} }