diff options
author | decebals <decebal.suiu@gmail.com> | 2019-05-03 01:08:02 +0300 |
---|---|---|
committer | decebals <decebal.suiu@gmail.com> | 2019-05-03 01:08:02 +0300 |
commit | a487cbf37a0e3c6d36113d5da7c0571398a19d43 (patch) | |
tree | afc28ee2b64e6046a45d39e6ac28fe31e6600a4c /pf4j/src/test | |
parent | fde642e63a6a0165d0e60b80f6fc559368f712e7 (diff) | |
download | pf4j-a487cbf37a0e3c6d36113d5da7c0571398a19d43.tar.gz pf4j-a487cbf37a0e3c6d36113d5da7c0571398a19d43.zip |
Improve #307 (add support for development mode)
Diffstat (limited to 'pf4j/src/test')
3 files changed, 68 insertions, 30 deletions
diff --git a/pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java b/pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java index 7e6043b..d74bea3 100644 --- a/pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java +++ b/pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java @@ -92,13 +92,14 @@ public class CompoundPluginDescriptorFinderTest { @Test public void testSpaceCharacterInFileName() throws Exception { - PluginDescriptorFinder descriptorFinder = new PropertiesPluginDescriptorFinder(); + PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder() + .add(new ManifestPluginDescriptorFinder()); - PluginZip pluginZip = new PluginZip.Builder(pluginsPath.resolve("my plugin-1.2.3.jar"), "myPlugin") + PluginJar pluginJar = new PluginJar.Builder(pluginsPath.resolve("my plugin-1.2.3.jar"), "myPlugin") .pluginVersion("1.2.3") .build(); - PluginDescriptor pluginDescriptor = descriptorFinder.find(pluginZip.path()); + PluginDescriptor pluginDescriptor = descriptorFinder.find(pluginJar.path()); assertNotNull(pluginDescriptor); } diff --git a/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java b/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java index 3805c42..2237dfe 100644 --- a/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java +++ b/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java @@ -46,9 +46,6 @@ public class DefaultPluginRepositoryTest { Files.createFile(pluginsPath.resolve("plugin-1.zip")); Files.createDirectory(pluginsPath.resolve("plugin-2")); Files.createDirectory(pluginsPath.resolve("plugin-3")); - // standard maven/gradle bin folder - these should be skipped in development mode because the cause errors - Files.createDirectory(pluginsPath.resolve("target")); - Files.createDirectory(pluginsPath.resolve("build")); } /** @@ -56,29 +53,14 @@ public class DefaultPluginRepositoryTest { */ @Test public void testGetPluginArchives() { - PluginRepository repository = new DefaultPluginRepository(pluginsPath, false); + PluginRepository repository = new DefaultPluginRepository(pluginsPath); List<Path> pluginsPaths = repository.getPluginsPaths(); - assertEquals(5, pluginsPaths.size()); + assertEquals(3, pluginsPaths.size()); assertPathExists(pluginsPaths, pluginsPath.resolve("plugin-1")); assertPathExists(pluginsPaths, pluginsPath.resolve("plugin-2")); assertPathExists(pluginsPaths, pluginsPath.resolve("plugin-3")); - // when not in development mode we will honor these folders - assertPathExists(pluginsPaths, pluginsPath.resolve("target")); - assertPathExists(pluginsPaths, pluginsPath.resolve("build")); - } - - @Test - public void testGetPluginArchivesInDevelopmentMode() { - PluginRepository repository = new DefaultPluginRepository(pluginsPath, true); - - List<Path> pluginsPaths = repository.getPluginsPaths(); - - // target and build should be ignored - assertEquals(3, pluginsPaths.size()); - assertPathDoesNotExists(pluginsPaths, pluginsPath.resolve("target")); - assertPathDoesNotExists(pluginsPaths, pluginsPath.resolve("build")); } /** @@ -86,15 +68,13 @@ public class DefaultPluginRepositoryTest { */ @Test public void testDeletePluginPath() throws PluginException { - PluginRepository repository = new DefaultPluginRepository(pluginsPath, false); + PluginRepository repository = new DefaultPluginRepository(pluginsPath); assertTrue(Files.exists(pluginsPath.resolve("plugin-1.zip"))); assertTrue(repository.deletePluginPath(pluginsPath.resolve("plugin-1"))); assertFalse(Files.exists(pluginsPath.resolve("plugin-1.zip"))); assertTrue(repository.deletePluginPath(pluginsPath.resolve("plugin-3"))); assertFalse(repository.deletePluginPath(pluginsPath.resolve("plugin-4"))); - assertTrue(repository.deletePluginPath(pluginsPath.resolve("target"))); - assertTrue(repository.deletePluginPath(pluginsPath.resolve("build"))); List<Path> pluginsPaths = repository.getPluginsPaths(); @@ -106,8 +86,4 @@ public class DefaultPluginRepositoryTest { assertTrue(paths.contains(path), "The directory must contain the file " + path); } - private void assertPathDoesNotExists(List<Path> paths, Path path) { - assertFalse(paths.contains(path), "The directory must not contain the file " + path); - } - } diff --git a/pf4j/src/test/java/org/pf4j/DevelopmentPluginRepositoryTest.java b/pf4j/src/test/java/org/pf4j/DevelopmentPluginRepositoryTest.java new file mode 100644 index 0000000..9e4c8da --- /dev/null +++ b/pf4j/src/test/java/org/pf4j/DevelopmentPluginRepositoryTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2012-present the original author or authors. + * + * Licensed 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.pf4j; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + +/** + * @author Decebal Suiu + */ +public class DevelopmentPluginRepositoryTest { + + @TempDir + Path pluginsPath; + + @BeforeEach + public void setUp() throws IOException { + // standard maven/gradle bin folder - these should be skipped in development mode because the cause errors + Files.createDirectory(pluginsPath.resolve(DevelopmentPluginRepository.MAVEN_BUILD_DIR)); + Files.createDirectory(pluginsPath.resolve(DevelopmentPluginRepository.GRADLE_BUILD_DIR)); + } + + @Test + public void testGetPluginArchivesInDevelopmentMode() { + PluginRepository repository = new DevelopmentPluginRepository(pluginsPath); + + List<Path> pluginsPaths = repository.getPluginsPaths(); + + // target and build should be ignored + assertEquals(0, pluginsPaths.size()); + assertPathDoesNotExists(pluginsPaths, pluginsPath.resolve(DevelopmentPluginRepository.MAVEN_BUILD_DIR)); + assertPathDoesNotExists(pluginsPaths, pluginsPath.resolve(DevelopmentPluginRepository.GRADLE_BUILD_DIR)); + } + + private void assertPathDoesNotExists(List<Path> paths, Path path) { + assertFalse(paths.contains(path), "The directory must not contain the file " + path); + } + +} |