This is an automated email from the ASF dual-hosted git repository.
kdoran pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new c1c1d0da82 NIFI-10153 Refactored DocGeneratorTest and removed binary
test files
c1c1d0da82 is described below
commit c1c1d0da8261004559029c11c59fb9b019df27a2
Author: exceptionfactory <[email protected]>
AuthorDate: Wed Jun 22 10:57:57 2022 -0500
NIFI-10153 Refactored DocGeneratorTest and removed binary test files
This closes #6146
Signed-off-by: Kevin Doran <[email protected]>
---
.../nifi/documentation/DocGeneratorTest.java | 152 ++++++++++-----------
.../src/test/resources/conf/nifi.properties | 125 -----------------
.../src/test/resources/lib/example.nar | Bin 721040 -> 0 bytes
.../src/test/resources/lib/jetty.nar | Bin 4638519 -> 0 bytes
.../src/test/resources/lib/nifi-framework-nar.nar | Bin 406 -> 0 bytes
.../src/test/resources/lib/nifiserver-test-nar.nar | Bin 298794 -> 0 bytes
6 files changed, 69 insertions(+), 208 deletions(-)
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/DocGeneratorTest.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/DocGeneratorTest.java
index 749d938820..617fa7e39c 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/DocGeneratorTest.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/DocGeneratorTest.java
@@ -19,101 +19,87 @@ package org.apache.nifi.documentation;
import org.apache.commons.io.FileUtils;
import org.apache.nifi.bundle.Bundle;
import org.apache.nifi.bundle.BundleCoordinate;
-import org.apache.nifi.nar.ExtensionDiscoveringManager;
+import org.apache.nifi.bundle.BundleDetails;
+import org.apache.nifi.documentation.example.ProcessorWithLogger;
+import org.apache.nifi.nar.ExtensionDefinition;
+import org.apache.nifi.nar.ExtensionManager;
import org.apache.nifi.nar.ExtensionMapping;
-import org.apache.nifi.nar.NarClassLoadersHolder;
-import org.apache.nifi.nar.NarUnpacker;
-import org.apache.nifi.nar.StandardExtensionDiscoveringManager;
-import org.apache.nifi.nar.SystemBundle;
-import org.apache.nifi.nar.NarUnpackMode;
+import org.apache.nifi.processor.Processor;
import org.apache.nifi.util.NiFiProperties;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.io.TempDir;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
-import java.io.BufferedInputStream;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Properties;
import java.util.Set;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
public class DocGeneratorTest {
+ private static final Class<ProcessorWithLogger> PROCESSOR_CLASS =
ProcessorWithLogger.class;
+
+ private static final String[] HTML_EXTENSIONS = new String[]{"html"};
+
+ private static final boolean RECURSIVE_ENABLED = true;
+
+ @Mock
+ ExtensionManager extensionManager;
@Test
- public void testProcessorLoadsNarResources() throws IOException,
ClassNotFoundException {
- TemporaryFolder temporaryFolder = new TemporaryFolder();
- temporaryFolder.create();
-
- NiFiProperties properties =
loadSpecifiedProperties("/conf/nifi.properties",
- NiFiProperties.COMPONENT_DOCS_DIRECTORY,
- temporaryFolder.getRoot().getAbsolutePath());
-
- final Bundle systemBundle = SystemBundle.create(properties);
- final ExtensionMapping mapping = NarUnpacker.unpackNars(properties,
systemBundle, NarUnpackMode.UNPACK_INDIVIDUAL_JARS);
-
-
NarClassLoadersHolder.getInstance().init(properties.getFrameworkWorkingDirectory(),
properties.getExtensionsWorkingDirectory());
-
- final ExtensionDiscoveringManager extensionManager = new
StandardExtensionDiscoveringManager();
- extensionManager.discoverExtensions(systemBundle,
NarClassLoadersHolder.getInstance().getBundles());
-
- DocGenerator.generate(properties, extensionManager, mapping);
-
- final String extensionClassName =
"org.apache.nifi.processors.WriteResourceToStream";
- final BundleCoordinate coordinate =
mapping.getProcessorNames().get(extensionClassName).stream().findFirst().get();
- final String path = coordinate.getGroup() + "/" + coordinate.getId() +
"/" + coordinate.getVersion() + "/" + extensionClassName;
- File processorDirectory = new File(temporaryFolder.getRoot(), path);
- File indexHtml = new File(processorDirectory, "index.html");
- Assert.assertTrue(indexHtml + " should have been generated",
indexHtml.exists());
- String generatedHtml = FileUtils.readFileToString(indexHtml,
Charset.defaultCharset());
- Assert.assertNotNull(generatedHtml);
- Assert.assertTrue(generatedHtml.contains("This example processor loads
a resource from the nar and writes it to the FlowFile content"));
- Assert.assertTrue(generatedHtml.contains("files that were successfully
processed"));
- Assert.assertTrue(generatedHtml.contains("files that were not
successfully processed"));
- Assert.assertTrue(generatedHtml.contains("resources"));
+ void testGenerateExtensionsNotFound(@TempDir final File workingDirectory) {
+ final NiFiProperties properties = getProperties(workingDirectory);
+ final ExtensionMapping extensionMapping = new ExtensionMapping();
+
+ DocGenerator.generate(properties, extensionManager, extensionMapping);
+
+ final Collection<File> files = FileUtils.listFiles(workingDirectory,
HTML_EXTENSIONS, RECURSIVE_ENABLED);
+ assertTrue(files.isEmpty());
+ }
+
+ @Test
+ void testGenerateProcessor(@TempDir final File workingDirectory) throws
IOException {
+ final NiFiProperties properties = getProperties(workingDirectory);
+ final ExtensionMapping extensionMapping = new ExtensionMapping();
+
+ final BundleCoordinate bundleCoordinate =
BundleCoordinate.UNKNOWN_COORDINATE;
+ final BundleDetails bundleDetails = new
BundleDetails.Builder().workingDir(workingDirectory).coordinate(bundleCoordinate).build();
+ final Bundle bundle = new Bundle(bundleDetails,
getClass().getClassLoader());
+ final ExtensionDefinition definition = new
ExtensionDefinition(PROCESSOR_CLASS.getName(), bundle, Processor.class);
+ final Set<ExtensionDefinition> extensions =
Collections.singleton(definition);
+
when(extensionManager.getExtensions(eq(Processor.class))).thenReturn(extensions);
+
doReturn(PROCESSOR_CLASS).when(extensionManager).getClass(eq(definition));
+
+ final Processor processor = new ProcessorWithLogger();
+ when(extensionManager.getTempComponent(eq(PROCESSOR_CLASS.getName()),
eq(bundleCoordinate))).thenReturn(processor);
+
+ DocGenerator.generate(properties, extensionManager, extensionMapping);
+
+ final Collection<File> files = FileUtils.listFiles(workingDirectory,
HTML_EXTENSIONS, RECURSIVE_ENABLED);
+ assertFalse(files.isEmpty());
+
+ final File file = files.iterator().next();
+ final byte[] bytes = Files.readAllBytes(file.toPath());
+ final String html = new String(bytes, StandardCharsets.UTF_8);
+
+ assertTrue(html.contains(PROCESSOR_CLASS.getSimpleName()));
}
- private NiFiProperties loadSpecifiedProperties(final String
propertiesFile, final String key, final String value) {
- String file =
DocGeneratorTest.class.getResource(propertiesFile).getFile();
-
- System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, file);
-
- final Properties props = new Properties();
- InputStream inStream = null;
- try {
- inStream = new BufferedInputStream(new FileInputStream(file));
- props.load(inStream);
- } catch (final Exception ex) {
- throw new RuntimeException("Cannot load properties file due to "
- + ex.getLocalizedMessage(), ex);
- } finally {
- if (null != inStream) {
- try {
- inStream.close();
- } catch (final Exception ex) {
- /**
- * do nothing *
- */
- }
- }
- }
-
- if (key != null && value != null) {
- props.setProperty(key, value);
- }
-
- return new NiFiProperties() {
- @Override
- public String getProperty(String key) {
- return props.getProperty(key);
- }
-
- @Override
- public Set<String> getPropertyKeys() {
- return props.stringPropertyNames();
- }
- };
+ private NiFiProperties getProperties(final File workingDirectory) {
+ final Properties properties = new Properties();
+ properties.setProperty(NiFiProperties.COMPONENT_DOCS_DIRECTORY,
workingDirectory.getAbsolutePath());
+ return NiFiProperties.createBasicNiFiProperties(null, properties);
}
}
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/resources/conf/nifi.properties
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/resources/conf/nifi.properties
deleted file mode 100644
index bc0e5346ff..0000000000
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/resources/conf/nifi.properties
+++ /dev/null
@@ -1,125 +0,0 @@
-# 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.
-
-# Core Properties #
-nifi.flow.configuration.file=./target/flow.xml.gz
-nifi.flow.configuration.archive.dir=./target/archive/
-nifi.flowcontroller.autoResumeState=true
-nifi.flowcontroller.graceful.shutdown.period=10 sec
-nifi.flowservice.writedelay.interval=2 sec
-nifi.administrative.yield.duration=30 sec
-
-nifi.reporting.task.configuration.file=./target/reporting-tasks.xml
-nifi.controller.service.configuration.file=./target/controller-services.xml
-nifi.templates.directory=./target/templates
-nifi.ui.banner.text=UI Banner Text
-nifi.ui.autorefresh.interval=30 sec
-nifi.nar.library.directory=./target/test-classes/lib/
-nifi.nar.library.directory.alt=./target/test-classes/lib2/
-
-nifi.nar.working.directory=./target/work/nar/
-
-# H2 Settings
-nifi.database.directory=./target/database_repository
-nifi.h2.url.append=;LOCK_TIMEOUT=25000;WRITE_DELAY=0;AUTO_SERVER=FALSE
-
-# FlowFile Repository
-nifi.flowfile.repository.directory=./target/test-repo
-nifi.flowfile.repository.partitions=1
-nifi.flowfile.repository.checkpoint.interval=2 mins
-nifi.queue.swap.threshold=20000
-nifi.swap.storage.directory=./target/test-repo/swap
-nifi.swap.in.period=5 sec
-nifi.swap.in.threads=1
-nifi.swap.out.period=5 sec
-nifi.swap.out.threads=4
-
-# Content Repository
-nifi.content.claim.max.appendable.size=10 MB
-nifi.content.claim.max.flow.files=100
-nifi.content.repository.directory.default=./target/content_repository
-
-# Provenance Repository Properties
-nifi.provenance.repository.storage.directory=./target/provenance_repository
-nifi.provenance.repository.max.storage.time=24 hours
-nifi.provenance.repository.max.storage.size=1 GB
-nifi.provenance.repository.rollover.time=30 secs
-nifi.provenance.repository.rollover.size=100 MB
-
-# Site to Site properties
-nifi.remote.input.socket.port=9990
-nifi.remote.input.secure=true
-
-# web properties #
-nifi.web.war.directory=./target/lib
-nifi.web.http.host=
-nifi.web.http.port=8080
-nifi.web.https.host=
-nifi.web.https.port=
-nifi.web.jetty.working.directory=./target/work/jetty
-
-# security properties #
-nifi.sensitive.props.key=key
-nifi.sensitive.props.algorithm=PBEWITHMD5AND256BITAES-CBC-OPENSSL
-
-nifi.security.keystore=
-nifi.security.keystoreType=
-nifi.security.keystorePasswd=
-nifi.security.keyPasswd=
-nifi.security.truststore=
-nifi.security.truststoreType=
-nifi.security.truststorePasswd=
-nifi.security.user.authorizer=
-
-# cluster common properties (cluster manager and nodes must have same values) #
-nifi.cluster.protocol.heartbeat.interval=5 sec
-nifi.cluster.protocol.is.secure=false
-nifi.cluster.protocol.socket.timeout=30 sec
-nifi.cluster.protocol.connection.handshake.timeout=45 sec
-# if multicast is used, then nifi.cluster.protocol.multicast.xxx properties
must be configured #
-nifi.cluster.protocol.use.multicast=false
-nifi.cluster.protocol.multicast.address=
-nifi.cluster.protocol.multicast.port=
-nifi.cluster.protocol.multicast.service.broadcast.delay=500 ms
-nifi.cluster.protocol.multicast.service.locator.attempts=3
-nifi.cluster.protocol.multicast.service.locator.attempts.delay=1 sec
-
-# cluster node properties (only configure for cluster nodes) #
-nifi.cluster.is.node=false
-nifi.cluster.node.address=
-nifi.cluster.node.protocol.port=
-nifi.cluster.node.protocol.threads=2
-# if multicast is not used, nifi.cluster.node.unicast.xxx must have same
values as nifi.cluster.manager.xxx #
-nifi.cluster.node.unicast.manager.address=
-nifi.cluster.node.unicast.manager.protocol.port=
-nifi.cluster.node.unicast.manager.authority.provider.port=
-
-# cluster manager properties (only configure for cluster manager) #
-nifi.cluster.is.manager=false
-nifi.cluster.manager.address=
-nifi.cluster.manager.protocol.port=
-nifi.cluster.manager.authority.provider.port=
-nifi.cluster.manager.authority.provider.threads=10
-nifi.cluster.manager.node.firewall.file=
-nifi.cluster.manager.node.event.history.size=10
-nifi.cluster.manager.node.api.connection.timeout=30 sec
-nifi.cluster.manager.node.api.read.timeout=30 sec
-nifi.cluster.manager.node.api.request.threads=10
-nifi.cluster.manager.flow.retrieval.delay=5 sec
-nifi.cluster.manager.protocol.threads=10
-nifi.cluster.manager.safemode.duration=0 sec
-
-# analytics properties #
-nifi.analytics.predict.interval=3 mins
\ No newline at end of file
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/resources/lib/example.nar
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/resources/lib/example.nar
deleted file mode 100644
index 0bca10b513..0000000000
Binary files
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/resources/lib/example.nar
and /dev/null differ
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/resources/lib/jetty.nar
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/resources/lib/jetty.nar
deleted file mode 100644
index f92d6154d1..0000000000
Binary files
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/resources/lib/jetty.nar
and /dev/null differ
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/resources/lib/nifi-framework-nar.nar
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/resources/lib/nifi-framework-nar.nar
deleted file mode 100644
index d2a8b9667e..0000000000
Binary files
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/resources/lib/nifi-framework-nar.nar
and /dev/null differ
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/resources/lib/nifiserver-test-nar.nar
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/resources/lib/nifiserver-test-nar.nar
deleted file mode 100644
index c60026ecd1..0000000000
Binary files
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/resources/lib/nifiserver-test-nar.nar
and /dev/null differ