import org.pf4j.util.io.OrPathFilter;
import org.pf4j.util.io.PathFilter;
import org.pf4j.util.io.ZipPathFilter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.UncheckedIOException;
*/
public class DefaultPluginRepository extends BasePluginRepository {
- private static final Logger log = LoggerFactory.getLogger(DefaultPluginRepository.class);
-
public DefaultPluginRepository(Path... pluginsRoots) {
this(Arrays.asList(pluginsRoots));
}
/** The list of path filters. */
protected List<PathFilter> pathFilters;
- public CompoundPathFilter() {
+ protected CompoundPathFilter() {
this(new ArrayList<>());
}
- public CompoundPathFilter(PathFilter... pathFilters) {
+ protected CompoundPathFilter(PathFilter... pathFilters) {
this(Arrays.asList(pathFilters));
}
- public CompoundPathFilter(List<PathFilter> pathFilters) {
+ protected CompoundPathFilter(List<PathFilter> pathFilters) {
this.pathFilters = new ArrayList<>(pathFilters);
}
* Test of {@link AbstractExtensionFinder#find(Class)}.
*/
@Test
- public void testFindFailType() {
+ void testFindFailType() {
ExtensionFinder instance = new AbstractExtensionFinder(pluginManager) {
@Override
* Test of {@link AbstractExtensionFinder#find(Class)}.
*/
@Test
- public void testFindFromClasspath() {
+ void testFindFromClasspath() {
ExtensionFinder instance = new AbstractExtensionFinder(pluginManager) {
@Override
* Test of {@link AbstractExtensionFinder#find(Class, String)}.
*/
@Test
- public void testFindFromPlugin() {
+ void testFindFromPlugin() {
ExtensionFinder instance = new AbstractExtensionFinder(pluginManager) {
@Override
* Test of {@link AbstractExtensionFinder#findClassNames(String)}.
*/
@Test
- public void testFindClassNames() {
+ void testFindClassNames() {
ExtensionFinder instance = new AbstractExtensionFinder(pluginManager) {
@Override
* Test of {@link org.pf4j.AbstractExtensionFinder#find(java.lang.String)}.
*/
@Test
- public void testFindExtensionWrappersFromPluginId() {
+ void testFindExtensionWrappersFromPluginId() {
ExtensionFinder instance = new AbstractExtensionFinder(pluginManager) {
@Override
}
@Test
- public void findExtensionAnnotation() throws Exception {
+ void findExtensionAnnotation() throws Exception {
Compilation compilation = javac().compile(ExtensionAnnotationProcessorTest.Greeting,
ExtensionAnnotationProcessorTest.WhazzupGreeting);
assertThat(compilation).succeededWithoutWarnings();
}
@Test
- public void findExtensionAnnotationThatMissing() throws Exception {
+ void findExtensionAnnotationThatMissing() throws Exception {
Compilation compilation = javac().compile(ExtensionAnnotationProcessorTest.Greeting,
ExtensionAnnotationProcessorTest.SpinnakerExtension_NoExtension,
ExtensionAnnotationProcessorTest.WhazzupGreeting_SpinnakerExtension);
public class AbstractPluginManagerTest {
@Test
- public void getExtensionsByType() {
+ void getExtensionsByType() {
AbstractPluginManager pluginManager = mock(AbstractPluginManager.class, CALLS_REAL_METHODS);
ExtensionFinder extensionFinder = mock(ExtensionFinder.class);
List<TestExtensionPoint> extensions = pluginManager.getExtensions(TestExtensionPoint.class);
assertEquals(1, extensions.size());
}
-
+
@Test
- public void getVersion() {
+ void getVersion() {
AbstractPluginManager pluginManager = mock(AbstractPluginManager.class, CALLS_REAL_METHODS);
assertNotEquals("0.0.0", pluginManager.getVersion());
}
Path pluginsPath;
@Test
- public void add() {
+ void add() {
CompoundPluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder();
assertEquals(0, descriptorFinder.size());
}
@Test
- public void find() throws Exception {
+ void find() throws Exception {
Path pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-1"));
storePropertiesToPath(getPlugin1Properties(), pluginPath);
}
@Test
- public void findInJar() throws Exception {
+ void findInJar() throws Exception {
PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder()
.add(new ManifestPluginDescriptorFinder());
}
@Test
- public void testNotFound() {
+ void testNotFound() {
PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder();
assertThrows(PluginRuntimeException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3")));
}
@Test
- public void testSpaceCharacterInFileName() throws Exception {
+ void testSpaceCharacterInFileName() throws Exception {
PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder()
.add(new ManifestPluginDescriptorFinder());
* Test of create method, of class DefaultExtensionFactory.
*/
@Test
- public void testCreate() {
+ void testCreate() {
assertNotNull(extensionFactory.create(TestExtension.class));
}
* Test of create method, of class DefaultExtensionFactory.
*/
@Test
- public void testCreateFailConstructor() {
+ void testCreateFailConstructor() {
assertThrows(PluginRuntimeException.class, () -> extensionFactory.create(FailTestExtension.class));
}
/**
* @author Mario Franco
*/
-public class DefaultPluginFactoryTest {
+class DefaultPluginFactoryTest {
@Test
- public void testCreate() {
+ void testCreate() {
PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
when(pluginDescriptor.getPluginClass()).thenReturn(TestPlugin.class.getName());
}
@Test
- public void testCreateFail() {
+ void testCreateFail() {
PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
when(pluginDescriptor.getPluginClass()).thenReturn(FailTestPlugin.class.getName());
}
@Test
- public void testCreateFailNotFound() {
+ void testCreateFailNotFound() {
PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
when(pluginDescriptor.getPluginClass()).thenReturn("org.pf4j.plugin.NotFoundTestPlugin");
}
@Test
- public void testCreateFailConstructor() {
+ void testCreateFailConstructor() {
PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
when(pluginDescriptor.getPluginClass()).thenReturn(AnotherFailTestPlugin.class.getName());
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public class DefaultPluginManagerTest {
+class DefaultPluginManagerTest {
private DefaultPluginManager pluginManager;
private DefaultPluginDescriptor pluginDescriptor;
Path pluginsPath;
@BeforeEach
- public void setUp() throws IOException {
+ void setUp() throws IOException {
pluginManager = new DefaultPluginManager(pluginsPath);
pluginDescriptor = new DefaultPluginDescriptor();
}
@AfterEach
- public void tearDown() {
+ void tearDown() {
pluginManager = null;
pluginDescriptor = null;
pluginWrapper = null;
}
@Test
- public void validateOK() {
+ void validateOK() {
pluginManager.validatePluginDescriptor(pluginDescriptor);
}
@Test
- public void validateFailsOnId() {
+ void validateFailsOnId() {
pluginDescriptor.setPluginId("");
assertThrows(PluginRuntimeException.class, () -> pluginManager.validatePluginDescriptor(pluginDescriptor));
}
@Test
- public void validateFailsOnVersion() {
+ void validateFailsOnVersion() {
pluginDescriptor.setPluginVersion(null);
assertThrows(PluginRuntimeException.class, () -> pluginManager.validatePluginDescriptor(pluginDescriptor));
}
@Test
- public void validateNoPluginClass() {
+ void validateNoPluginClass() {
pluginManager.validatePluginDescriptor(pluginDescriptor);
assertEquals(Plugin.class.getName(), pluginDescriptor.getPluginClass());
}
@Test
- public void isPluginValid() {
+ void isPluginValid() {
// By default accept all since system version not given
assertTrue(pluginManager.isPluginValid(pluginWrapper));
}
@Test
- public void isPluginValidAllowExact() {
+ void isPluginValidAllowExact() {
pluginManager.setExactVersionAllowed(true);
// By default accept all since system version not given
}
@Test
- public void testDefaultExactVersionAllowed() {
+ void testDefaultExactVersionAllowed() {
assertFalse(pluginManager.isExactVersionAllowed());
}
* See https://github.com/pf4j/pf4j/issues/223.
*/
@Test
- public void testPluginDisabledNoStart() throws IOException {
+ void testPluginDisabledNoStart() throws IOException {
new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3")
.build();
}
@Test
- public void deleteZipPlugin() throws Exception {
+ void deleteZipPlugin() throws Exception {
PluginZip pluginZip = new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3")
.build();
}
@Test
- public void deleteJarPlugin() throws Exception {
+ void deleteJarPlugin() throws Exception {
PluginJar pluginJar = new PluginJar.Builder(pluginsPath.resolve("my-plugin-1.2.3.jar"), "myPlugin")
.pluginVersion("1.2.3")
.build();
* @author Mario Franco
* @author Decebal Suiu
*/
-public class DefaultPluginRepositoryTest {
+class DefaultPluginRepositoryTest {
Path pluginsPath1;
Path pluginsPath2;
@BeforeEach
- public void setUp() throws IOException {
+ void setUp() throws IOException {
pluginsPath1 = Files.createTempDirectory("junit-pf4j-");
pluginsPath2 = Files.createTempDirectory("junit-pf4j-");
Path plugin1Path = Files.createDirectory(pluginsPath1.resolve("plugin-1"));
}
@AfterEach
- public void tearDown() throws IOException {
+ void tearDown() throws IOException {
FileUtils.delete(pluginsPath1);
FileUtils.delete(pluginsPath2);
}
* Test of {@link DefaultPluginRepository#getPluginPaths()} method.
*/
@Test
- public void testGetPluginArchivesFromSinglePath() {
+ void testGetPluginArchivesFromSinglePath() {
PluginRepository repository = new DefaultPluginRepository(pluginsPath2);
List<Path> pluginPaths = repository.getPluginPaths();
* Test of {@link DefaultPluginRepository#getPluginPaths()} method.
*/
@Test
- public void testGetPluginArchives() {
+ void testGetPluginArchives() {
PluginRepository repository = new DefaultPluginRepository(pluginsPath1, pluginsPath2);
List<Path> pluginPaths = repository.getPluginPaths();
* Test of {@link DefaultPluginRepository#deletePluginPath(Path)} method.
*/
@Test
- public void testDeletePluginPath() {
+ void testDeletePluginPath() {
PluginRepository repository = new DefaultPluginRepository(pluginsPath1, pluginsPath2);
assertTrue(Files.exists(pluginsPath1.resolve("plugin-1.zip")));
* @author Mario Franco
* @author Decebal Suiu
*/
-public class DefaultPluginStatusProviderTest {
+class DefaultPluginStatusProviderTest {
@TempDir
Path pluginsPath;
@Test
- public void testIsPluginDisabled() throws IOException {
+ void testIsPluginDisabled() throws IOException {
createEnabledFile();
createDisabledFile();
}
@Test
- public void testIsPluginDisabledWithEnableEmpty() throws IOException {
+ void testIsPluginDisabledWithEnableEmpty() throws IOException {
createDisabledFile();
PluginStatusProvider statusProvider = new DefaultPluginStatusProvider(pluginsPath);
}
@Test
- public void testDisablePlugin() throws Exception {
+ void testDisablePlugin() throws Exception {
createEnabledFile();
createDisabledFile();
}
@Test
- public void testDisablePluginWithEnableEmpty() throws Exception {
+ void testDisablePluginWithEnableEmpty() throws Exception {
// scenario with "disabled.txt"
createDisabledFile();
}
@Test
- public void testEnablePlugin() throws Exception {
+ void testEnablePlugin() throws Exception {
// scenario with "enabled.txt"
createEnabledFile();
}
@Test
- public void testEnablePluginWithEnableEmpty() {
+ void testEnablePluginWithEnableEmpty() {
PluginStatusProvider statusProvider = new DefaultPluginStatusProvider(pluginsPath);
statusProvider.enablePlugin("plugin-2");
}
@Test
- public void testDisablePluginWithoutDisabledFile() {
+ void testDisablePluginWithoutDisabledFile() {
PluginStatusProvider statusProvider = new DefaultPluginStatusProvider(pluginsPath);
assertFalse(statusProvider.isPluginDisabled("plugin-1"));
/**
* @author Decebal Suiu
*/
-public class DefaultVersionManagerTest {
+class DefaultVersionManagerTest {
private VersionManager versionManager;
@BeforeEach
- public void init() {
+ void init() {
versionManager = new DefaultVersionManager();
}
@Test
- public void checkVersionConstraint() {
+ void checkVersionConstraint() {
assertFalse(versionManager.checkVersionConstraint("1.4.3", ">2.0.0")); // simple
assertTrue(versionManager.checkVersionConstraint("1.4.3", ">=1.4.0 & <1.6.0")); // range
assertTrue(versionManager.checkVersionConstraint("undefined", "*"));
}
@Test
- public void nullOrEmptyVersion() {
+ void nullOrEmptyVersion() {
assertThrows(IllegalArgumentException.class, () -> versionManager.checkVersionConstraint(null, ">2.0.0"));
}
@Test
- public void invalidVersion() {
+ void invalidVersion() {
assertThrows(ParseException.class, () -> versionManager.checkVersionConstraint("1.0", ">2.0.0"));
}
@Test
- public void compareVersions() {
+ void compareVersions() {
assertTrue(versionManager.compareVersions("1.1.0", "1.0.0") > 0);
}
/**
* @author Decebal Suiu
*/
-public class DependencyResolverTest {
+class DependencyResolverTest {
private DependencyResolver resolver;
@BeforeEach
- public void init() {
+ void init() {
VersionManager versionManager = new DefaultVersionManager();
resolver = new DependencyResolver(versionManager);
}
@Test
- public void sortedPlugins() {
+ void sortedPlugins() {
// create incomplete plugin descriptor (ignore some attributes)
PluginDescriptor pd1 = new DefaultPluginDescriptor()
.setPluginId("p1")
}
@Test
- public void notFoundDependencies() {
+ void notFoundDependencies() {
PluginDescriptor pd1 = new DefaultPluginDescriptor()
.setPluginId("p1")
.setDependencies("p2, p3");
}
@Test
- public void cyclicDependencies() {
+ void cyclicDependencies() {
PluginDescriptor pd1 = new DefaultPluginDescriptor()
.setPluginId("p1")
.setPluginVersion("0.0.0")
}
@Test
- public void wrongDependencyVersion() {
+ void wrongDependencyVersion() {
PluginDescriptor pd1 = new DefaultPluginDescriptor()
.setPluginId("p1")
// .setDependencies("p2@2.0.0"); // simple version
}
@Test
- public void goodDependencyVersion() {
+ void goodDependencyVersion() {
PluginDescriptor pd1 = new DefaultPluginDescriptor()
.setPluginId("p1")
.setDependencies("p2@2.0.0");
/**
* @author Decebal Suiu
*/
-public class DevelopmentPluginRepositoryTest {
+class DevelopmentPluginRepositoryTest {
@TempDir
Path pluginsPath;
@BeforeEach
- public void setUp() throws IOException {
+ 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() {
+ void testGetPluginArchivesInDevelopmentMode() {
PluginRepository repository = new DevelopmentPluginRepository(pluginsPath);
List<Path> pluginPaths = repository.getPluginPaths();
* @author Mario Franco
* @author Decebal Suiu
*/
-public class ExtensionAnnotationProcessorTest {
+class ExtensionAnnotationProcessorTest {
- public static final JavaFileObject Greeting = JavaFileObjects.forSourceLines(
+ static final JavaFileObject Greeting = JavaFileObjects.forSourceLines(
"Greeting",
"package test;",
"import org.pf4j.ExtensionPoint;",
" String getGreeting();",
"}");
- public static final JavaFileObject WhazzupGreeting = JavaFileObjects.forSourceLines(
+ static final JavaFileObject WhazzupGreeting = JavaFileObjects.forSourceLines(
"WhazzupGreeting",
"package test;",
"import org.pf4j.Extension;",
" }",
"}");
- public static final JavaFileObject WhazzupGreeting_NoExtensionPoint = JavaFileObjects.forSourceLines(
+ static final JavaFileObject WhazzupGreeting_NoExtensionPoint = JavaFileObjects.forSourceLines(
"WhazzupGreeting",
"package test;",
"import org.pf4j.Extension;",
" }",
"}");
- public static final JavaFileObject SpinnakerExtension = JavaFileObjects.forSourceLines(
+ static final JavaFileObject SpinnakerExtension = JavaFileObjects.forSourceLines(
"SpinnakerExtension",
"package test;",
"",
"public @interface SpinnakerExtension {",
"}");
- public static final JavaFileObject WhazzupGreeting_SpinnakerExtension = JavaFileObjects.forSourceLines(
+ static final JavaFileObject WhazzupGreeting_SpinnakerExtension = JavaFileObjects.forSourceLines(
"WhazzupGreeting",
"package test;",
"",
/**
* The same like {@link #SpinnakerExtension} but without {@code Extension} annotation.
*/
- public static final JavaFileObject SpinnakerExtension_NoExtension = JavaFileObjects.forSourceLines(
+ static final JavaFileObject SpinnakerExtension_NoExtension = JavaFileObjects.forSourceLines(
"SpinnakerExtension",
"package test;",
"",
"}");
@Test
- public void getSupportedAnnotationTypes() {
+ void getSupportedAnnotationTypes() {
ExtensionAnnotationProcessor instance = new ExtensionAnnotationProcessor();
Set<String> result = instance.getSupportedAnnotationTypes();
assertEquals(1, result.size());
}
@Test
- public void getSupportedOptions() {
+ void getSupportedOptions() {
ExtensionAnnotationProcessor instance = new ExtensionAnnotationProcessor();
Set<String> result = instance.getSupportedOptions();
assertEquals(2, result.size());
}
@Test
- public void options() {
+ void options() {
ExtensionAnnotationProcessor processor = new ExtensionAnnotationProcessor();
Compilation compilation = javac().withProcessors(processor).withOptions("-Ab=2", "-Ac=3")
.compile(Greeting, WhazzupGreeting);
}
@Test
- public void storage() {
+ void storage() {
ExtensionAnnotationProcessor processor = new ExtensionAnnotationProcessor();
Compilation compilation = javac().withProcessors(processor).compile(Greeting, WhazzupGreeting);
assertEquals(compilation.status(), Compilation.Status.SUCCESS);
}
@Test
- public void compileWithoutError() {
+ void compileWithoutError() {
ExtensionAnnotationProcessor processor = new ExtensionAnnotationProcessor();
Compilation compilation = javac().withProcessors(processor).compile(Greeting, WhazzupGreeting);
assertThat(compilation).succeededWithoutWarnings();
}
@Test
- public void compileWithError() {
+ void compileWithError() {
ExtensionAnnotationProcessor processor = new ExtensionAnnotationProcessor();
Compilation compilation = javac().withProcessors(processor).compile(Greeting, WhazzupGreeting_NoExtensionPoint);
assertThat(compilation).failed();
}
@Test
- public void getExtensions() {
+ void getExtensions() {
ExtensionAnnotationProcessor processor = new ExtensionAnnotationProcessor();
Compilation compilation = javac().withProcessors(processor).compile(Greeting, WhazzupGreeting);
assertThat(compilation).succeededWithoutWarnings();
}
@Test
- public void compileNestedExtensionAnnotation() {
+ void compileNestedExtensionAnnotation() {
ExtensionAnnotationProcessor processor = new ExtensionAnnotationProcessor();
Compilation compilation = javac().withProcessors(processor).compile(Greeting, SpinnakerExtension, WhazzupGreeting_SpinnakerExtension);
assertThat(compilation).succeededWithoutWarnings();
Path pluginsPath;
@BeforeEach
- public void setUp() throws IOException {
+ void setUp() throws IOException {
pluginJar = new PluginJar.Builder(pluginsPath.resolve("test-plugin.jar"), "test-plugin")
.pluginClass(TestPlugin.class.getName())
.pluginVersion("1.2.3")
}
@AfterEach
- public void tearDown() {
+ void tearDown() {
pluginManager.unloadPlugins();
pluginJar = null;
}
@Test
- public void getExtensions() {
+ void getExtensions() {
pluginManager.loadPlugins();
pluginManager.startPlugins();
}
@Test
- public void unloadPlugin() throws Exception {
+ void unloadPlugin() throws Exception {
pluginManager.loadPlugins();
assertEquals(1, pluginManager.getPlugins().size());
}
@Test
- public void deletePlugin() {
+ void deletePlugin() {
pluginManager.loadPlugins();
assertEquals(1, pluginManager.getPlugins().size());
/**
* @author Decebal Suiu
*/
-public class JarPluginRepositoryTest {
+class JarPluginRepositoryTest {
@TempDir
Path pluginsPath;
* Test of {@link JarPluginRepository#deletePluginPath(Path)} method.
*/
@Test
- public void testDeletePluginPath() throws Exception {
+ void testDeletePluginPath() throws Exception {
PluginRepository repository = new JarPluginRepository(pluginsPath);
Path plugin1Path = Files.createDirectory(pluginsPath.resolve("plugin-1"));
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.condition.OS.WINDOWS;
-public class LegacyExtensionFinderTest {
+class LegacyExtensionFinderTest {
@TempDir
Path pluginsPath;
@Test
@EnabledOnOs(WINDOWS)
- public void shouldUnlockFileAfterReadingExtensionsFromPlugin() throws Exception {
+ void shouldUnlockFileAfterReadingExtensionsFromPlugin() throws Exception {
PluginJar pluginJar = new PluginJar.Builder(pluginsPath.resolve("test-plugin.jar"), "test-plugin")
.pluginClass(TestPlugin.class.getName())
.pluginVersion("1.2.3")
/**
* @author Decebal Suiu
*/
-public class LegacyExtensionStorageTest {
+class LegacyExtensionStorageTest {
/**
* Test of {@link LegacyExtensionStorage#read(Reader, Set)}.
*/
@Test
- public void testRead() throws IOException {
+ void read() throws IOException {
Reader reader = new StringReader(
"# comment\n"
+ "org.pf4j.demo.hello.HelloPlugin$HelloGreeting\n"
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
-public class LoadPluginsFromMultipleRootsTest {
+class LoadPluginsFromMultipleRootsTest {
private DefaultPluginManager pluginManager;
Path pluginsPath2;
@BeforeEach
- public void setUp() throws IOException {
+ void setUp() throws IOException {
pluginsPath1 = Files.createTempDirectory("junit-pf4j-");
pluginsPath2 = Files.createTempDirectory("junit-pf4j-");
pluginManager = new DefaultPluginManager(pluginsPath1, pluginsPath2);
}
@AfterEach
- public void tearDown() throws IOException {
+ void tearDown() throws IOException {
FileUtils.delete(pluginsPath1);
FileUtils.delete(pluginsPath2);
}
@Test
- public void load() throws Exception {
+ void load() throws Exception {
PluginZip pluginZip1 = new PluginZip.Builder(pluginsPath1.resolve("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3")
.build();
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
-public class LoadPluginsTest {
+class LoadPluginsTest {
private DefaultPluginManager pluginManager;
Path pluginsPath;
@BeforeEach
- public void setUp() {
+ void setUp() {
pluginManager = new DefaultPluginManager(pluginsPath);
}
@Test
- public void load() throws Exception {
+ void load() throws Exception {
PluginZip pluginZip = new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3")
.build();
}
@Test
- public void loadNonExisting() {
+ void loadNonExisting() {
assertThrows(IllegalArgumentException.class, () -> pluginManager.loadPlugin(Paths.get("nonexisting")));
}
@Test
- public void loadTwiceFails() throws Exception {
+ void loadTwiceFails() throws Exception {
PluginZip pluginZip = new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3")
.build();
}
@Test
- public void loadPluginWithSameIdDifferentPathFails() throws Exception {
+ void loadPluginWithSameIdDifferentPathFails() throws Exception {
String pluginId = "myPlugin";
String pluginVersion = "1.2.3";
Path plugin1Path = pluginsPath.resolve("my-plugin-1.2.3.zip");
* uses pluginId as the unique identifier of the loaded plugin.
*/
@Test
- public void loadPluginWithSameIdDifferentVersionsFails() throws Exception {
+ void loadPluginWithSameIdDifferentVersionsFails() throws Exception {
String pluginId = "myPlugin";
String plugin1Version = "1.2.3";
Path plugin1Path = pluginsPath.resolve("my-plugin-1.2.3.zip");
}
@Test
- public void loadUnloadLoad() throws Exception {
+ void loadUnloadLoad() throws Exception {
PluginZip pluginZip = new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3")
.build();
}
@Test
- public void upgrade() throws Exception {
+ void upgrade() throws Exception {
String pluginId = "myPlugin";
new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), pluginId)
}
@Test
- public void getRoot() {
+ void getRoot() {
assertEquals(pluginsPath, pluginManager.getPluginsRoot());
}
@Test
- public void getRoots() {
+ void getRoots() {
assertEquals(Collections.singletonList(pluginsPath), pluginManager.getPluginsRoots());
}
@Test
- public void notAPlugin() {
+ void notAPlugin() {
pluginsPath.resolve("not-a-zip");
pluginManager.loadPlugins();
}
@Test
- public void deletePlugin() throws Exception {
+ void deletePlugin() throws Exception {
PluginZip pluginZip1 = new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3")
.build();
import org.junit.jupiter.api.io.TempDir;
import org.pf4j.test.PluginJar;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
* @author Mario Franco
* @author Decebal Suiu
*/
-public class ManifestPluginDescriptorFinderTest {
+class ManifestPluginDescriptorFinderTest {
private VersionManager versionManager;
Path pluginsPath;
@BeforeEach
- public void setUp() throws IOException {
+ void setUp() throws IOException {
Path pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-1"));
storeManifestToPath(getPlugin1Manifest(), pluginPath);
* Test of {@link ManifestPluginDescriptorFinder#find(Path)} method.
*/
@Test
- public void testFind() throws Exception {
+ void find() throws Exception {
PluginDescriptorFinder descriptorFinder = new ManifestPluginDescriptorFinder();
PluginDescriptor plugin1 = descriptorFinder.find(pluginsPath.resolve("test-plugin-1"));
* Test of {@link ManifestPluginDescriptorFinder#find(Path)} method.
*/
@Test
- public void testFindNotFound() {
+ void findNotFound() {
PluginDescriptorFinder descriptorFinder = new ManifestPluginDescriptorFinder();
assertThrows(PluginRuntimeException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3")));
}
/**
* @author Sebastian Lövdahl
*/
-public class PluginClassLoaderTest {
+class PluginClassLoaderTest {
private TestPluginManager pluginManager;
private TestPluginManager pluginManagerParentFirst;
/**
* @author Mario Franco
*/
-public class PluginDependencyTest {
+class PluginDependencyTest {
private DefaultPluginManager pluginManager;
Path pluginsPath;
@BeforeEach
- public void setUp() {
+ void setUp() {
pluginManager = new DefaultPluginManager(pluginsPath);
}
/**
- * Test of getPluginId method, of class PluginDependency.
+ * Test of {@code getPluginId} method, of class {@link PluginDependency}.
*/
@Test
- public void testPluginDependecy() {
+ void pluginDependency() {
PluginDependency instance = new PluginDependency("test");
PluginDependency instance2 = new PluginDependency("test");
assertEquals(instance, instance2);
}
@Test
- public void dependentStop() throws Exception {
+ void dependentStop() throws Exception {
// B depends on A
PluginZip pluginA = new PluginZip.Builder(pluginsPath.resolve("A-plugin-1.2.3.zip"), "plugin.a")
.pluginVersion("1.2.3").build();
}
@Test
- public void dependentUnload() throws Exception {
+ void dependentUnload() throws Exception {
// B depends on A
PluginZip pluginA = new PluginZip.Builder(pluginsPath.resolve("A-plugin-1.2.3.zip"), "plugin.a")
.pluginVersion("1.2.3").build();
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-public class PropertiesPluginDescriptorFinderTest {
+class PropertiesPluginDescriptorFinderTest {
private VersionManager versionManager;
Path pluginsPath;
@BeforeEach
- public void setUp() throws IOException {
+ void setUp() throws IOException {
Path pluginPath = Files.createDirectory(pluginsPath.resolve("test-plugin-1"));
storePropertiesToPath(getPlugin1Properties(), pluginPath);
}
@Test
- public void testFind() throws Exception {
+ void find() throws Exception {
PluginDescriptorFinder descriptorFinder = new PropertiesPluginDescriptorFinder();
PluginDescriptor plugin1 = descriptorFinder.find(pluginsPath.resolve("test-plugin-1"));
}
@Test
- public void testNotFound() {
+ void notFound() {
PluginDescriptorFinder descriptorFinder = new PropertiesPluginDescriptorFinder();
assertThrows(PluginRuntimeException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3")));
}
-package org.pf4j;\r
-\r
-import static org.junit.jupiter.api.Assertions.assertTrue;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.jupiter.api.Assertions.assertEquals;\r
-import static org.junit.jupiter.api.Assertions.assertThrows;\r
-\r
-import java.io.IOException;\r
-import java.nio.file.Path;\r
-import java.util.List;\r
-\r
-import org.junit.jupiter.api.AfterEach;\r
-import org.junit.jupiter.api.BeforeEach;\r
-import org.junit.jupiter.api.Test;\r
-import org.junit.jupiter.api.io.TempDir;\r
-import org.pf4j.test.PluginJar;\r
-import org.pf4j.test.TestExtension;\r
-import org.pf4j.test.TestExtensionPoint;\r
-import org.pf4j.test.TestPlugin;\r
-\r
-public class SecurePluginManagerWrapperTest {\r
-\r
- private static final String OTHER_PLUGIN_ID = "test-plugin-2";\r
- private static final String THIS_PLUGIN_ID = "test-plugin-1";\r
- private PluginJar thisPlugin;\r
- private PluginJar otherPlugin;\r
- private PluginManager pluginManager;\r
- private PluginManager wrappedPluginManager;\r
- private int pluginManagerEvents = 0;\r
- private int wrappedPluginManagerEvents = 0;\r
-\r
- @TempDir\r
- Path pluginsPath;\r
-\r
- @BeforeEach\r
- public void setUp() throws IOException {\r
- pluginManagerEvents = 0;\r
- wrappedPluginManagerEvents = 0;\r
- thisPlugin = new PluginJar.Builder(pluginsPath.resolve("test-plugin1.jar"), THIS_PLUGIN_ID).pluginClass(TestPlugin.class.getName()).pluginVersion("1.2.3").extension(TestExtension.class.getName()).build();\r
- otherPlugin = new PluginJar.Builder(pluginsPath.resolve("test-plugin2.jar"), OTHER_PLUGIN_ID).pluginClass(TestPlugin.class.getName()).pluginVersion("1.2.3").extension(TestExtension.class.getName()).build();\r
-\r
- pluginManager = new JarPluginManager(pluginsPath);\r
- wrappedPluginManager = new SecurePluginManagerWrapper(pluginManager, THIS_PLUGIN_ID);\r
- }\r
-\r
- @AfterEach\r
- public void tearDown() {\r
- pluginManager.unloadPlugins();\r
-\r
- thisPlugin = null;\r
- otherPlugin = null;\r
- pluginManager = null;\r
- }\r
-\r
- @Test\r
- public void pluginStateListeners() {\r
- pluginManager.addPluginStateListener(new PluginStateListener() {\r
- @Override\r
- public void pluginStateChanged(PluginStateEvent event) {\r
- pluginManagerEvents++;\r
- }\r
- });\r
- wrappedPluginManager.addPluginStateListener(new PluginStateListener() {\r
- @Override\r
- public void pluginStateChanged(PluginStateEvent event) {\r
- wrappedPluginManagerEvents++;\r
- }\r
- });\r
- pluginManager.loadPlugins();\r
- pluginManager.startPlugins();\r
- assertEquals(4, pluginManagerEvents);\r
- assertEquals(2, wrappedPluginManagerEvents);\r
- }\r
-\r
- @Test\r
- public void deletePlugin() {\r
- pluginManager.loadPlugins();\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.deletePlugin(OTHER_PLUGIN_ID));\r
- assertTrue(wrappedPluginManager.deletePlugin(THIS_PLUGIN_ID));\r
- }\r
-\r
- @Test\r
- public void disablePlugin() {\r
- pluginManager.loadPlugins();\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.disablePlugin(OTHER_PLUGIN_ID));\r
- assertTrue(wrappedPluginManager.disablePlugin(THIS_PLUGIN_ID));\r
- }\r
-\r
- @Test\r
- public void enablePlugin() {\r
- pluginManager.loadPlugins();\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.enablePlugin(OTHER_PLUGIN_ID));\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.enablePlugin(THIS_PLUGIN_ID));\r
- }\r
-\r
- @Test\r
- public void getExtensionClasses() {\r
- pluginManager.loadPlugins();\r
- pluginManager.startPlugins();\r
- assertEquals(1, wrappedPluginManager.getExtensionClasses(TestExtensionPoint.class).size());\r
-\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.getExtensionClasses(TestExtensionPoint.class, OTHER_PLUGIN_ID));\r
- assertEquals(1, wrappedPluginManager.getExtensionClasses(TestExtensionPoint.class, THIS_PLUGIN_ID).size());\r
-\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.getExtensionClasses(OTHER_PLUGIN_ID));\r
- assertEquals(1, wrappedPluginManager.getExtensionClasses(THIS_PLUGIN_ID).size());\r
- }\r
-\r
- @Test\r
- public void getExtensionClassNames() {\r
- pluginManager.loadPlugins();\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.getExtensionClassNames(OTHER_PLUGIN_ID));\r
- assertEquals(1, wrappedPluginManager.getExtensionClassNames(THIS_PLUGIN_ID).size());\r
- }\r
-\r
- @Test\r
- public void getExtensionFactory() {\r
- pluginManager.loadPlugins();\r
- assertEquals(pluginManager.getExtensionFactory(), wrappedPluginManager.getExtensionFactory());\r
- }\r
-\r
- @Test\r
- public void getExtensions() {\r
- pluginManager.loadPlugins();\r
- pluginManager.startPlugins();\r
- assertEquals(1, wrappedPluginManager.getExtensions(TestExtensionPoint.class).size());\r
-\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.getExtensions(TestExtensionPoint.class, OTHER_PLUGIN_ID));\r
- assertEquals(1, wrappedPluginManager.getExtensions(TestExtensionPoint.class, THIS_PLUGIN_ID).size());\r
-\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.getExtensions(OTHER_PLUGIN_ID));\r
- assertEquals(1, wrappedPluginManager.getExtensions(THIS_PLUGIN_ID).size());\r
- }\r
-\r
- @Test\r
- public void getPlugin() {\r
- pluginManager.loadPlugins();\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.getPlugin(OTHER_PLUGIN_ID));\r
- assertEquals(THIS_PLUGIN_ID, wrappedPluginManager.getPlugin(THIS_PLUGIN_ID).getPluginId());\r
- }\r
-\r
- @Test\r
- public void getPluginClassLoader() {\r
- pluginManager.loadPlugins();\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.getPluginClassLoader(OTHER_PLUGIN_ID));\r
- assertNotNull(wrappedPluginManager.getPluginClassLoader(THIS_PLUGIN_ID));\r
- }\r
-\r
- @Test\r
- public void getPlugins() {\r
- pluginManager.loadPlugins();\r
- assertEquals(2, pluginManager.getPlugins().size());\r
- assertEquals(1, wrappedPluginManager.getPlugins().size());\r
- }\r
-\r
- @Test\r
- public void getPluginsRoot() {\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.getPluginsRoot());\r
- }\r
-\r
- @Test\r
- public void getPluginsRoots() {\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.getPluginsRoots());\r
- }\r
-\r
- @Test\r
- public void getResolvedPlugins() {\r
- pluginManager.loadPlugins();\r
- assertEquals(2, pluginManager.getResolvedPlugins().size());\r
- assertEquals(1, wrappedPluginManager.getResolvedPlugins().size());\r
- }\r
-\r
- @Test\r
- public void getRuntimeMode() {\r
- assertEquals(pluginManager.getRuntimeMode(), wrappedPluginManager.getRuntimeMode());\r
- }\r
-\r
- @Test\r
- public void getStartedPlugins() {\r
- pluginManager.loadPlugins();\r
- pluginManager.startPlugins();\r
- assertEquals(2, pluginManager.getStartedPlugins().size());\r
- assertEquals(1, wrappedPluginManager.getStartedPlugins().size());\r
- }\r
-\r
- @Test\r
- public void getSystemVersion() {\r
- assertEquals(pluginManager.getSystemVersion(), wrappedPluginManager.getSystemVersion());\r
- }\r
-\r
- @Test\r
- public void getUnresolvedPlugins() {\r
- assertNotNull(wrappedPluginManager);\r
- assertNotNull(wrappedPluginManager.getUnresolvedPlugins());\r
- assertTrue(wrappedPluginManager.getUnresolvedPlugins().isEmpty());\r
- }\r
-\r
- @Test\r
- public void getVersionManager() {\r
- assertEquals(pluginManager.getVersionManager(), wrappedPluginManager.getVersionManager());\r
- }\r
-\r
- @Test\r
- public void isDevelopment() {\r
- assertEquals(pluginManager.isDevelopment(), wrappedPluginManager.isDevelopment());\r
- }\r
-\r
- @Test\r
- public void isNotDevelopment() {\r
- assertEquals(pluginManager.isNotDevelopment(), wrappedPluginManager.isNotDevelopment());\r
- }\r
-\r
- @Test\r
- public void loadPlugin() {\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.loadPlugin(thisPlugin.path()));\r
- }\r
-\r
- @Test\r
- public void loadPlugins() {\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.loadPlugins());\r
- }\r
-\r
- @Test\r
- public void setSystemVersion() {\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.setSystemVersion("1.0.0"));\r
- }\r
-\r
- @Test\r
- public void startPlugin() {\r
- pluginManager.loadPlugins();\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.startPlugin(OTHER_PLUGIN_ID));\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.startPlugin(THIS_PLUGIN_ID));\r
- }\r
-\r
- @Test\r
- public void startPlugins() {\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.startPlugins());\r
- }\r
-\r
- @Test\r
- public void stopPlugin() {\r
- pluginManager.loadPlugins();\r
- pluginManager.startPlugins();\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.stopPlugin(OTHER_PLUGIN_ID));\r
- assertEquals(PluginState.STOPPED, wrappedPluginManager.stopPlugin(THIS_PLUGIN_ID));\r
- }\r
-\r
- @Test\r
- public void stopPlugins() {\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.stopPlugins());\r
- }\r
-\r
- @Test\r
- public void unloadPlugin() {\r
- pluginManager.loadPlugins();\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.unloadPlugin(OTHER_PLUGIN_ID));\r
- assertTrue(wrappedPluginManager.unloadPlugin(THIS_PLUGIN_ID));\r
- }\r
-\r
- @Test\r
- public void unloadPlugins() {\r
- assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.unloadPlugins());\r
- }\r
-\r
- @Test\r
- public void whichPlugin() {\r
- pluginManager.loadPlugins();\r
- pluginManager.startPlugins();\r
- assertEquals(null, wrappedPluginManager.whichPlugin(pluginManager.getExtensionClasses(OTHER_PLUGIN_ID).get(0)));\r
- assertEquals(THIS_PLUGIN_ID, wrappedPluginManager.whichPlugin(pluginManager.getExtensionClasses(THIS_PLUGIN_ID).get(0)).getPluginId());\r
- }\r
-}\r
+package org.pf4j;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.pf4j.test.PluginJar;
+import org.pf4j.test.TestExtension;
+import org.pf4j.test.TestExtensionPoint;
+import org.pf4j.test.TestPlugin;
+
+import java.io.IOException;
+import java.nio.file.Path;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class SecurePluginManagerWrapperTest {
+
+ private static final String OTHER_PLUGIN_ID = "test-plugin-2";
+ private static final String THIS_PLUGIN_ID = "test-plugin-1";
+
+ private PluginJar thisPlugin;
+ private PluginJar otherPlugin;
+ private PluginManager pluginManager;
+ private PluginManager wrappedPluginManager;
+ private int pluginManagerEvents = 0;
+ private int wrappedPluginManagerEvents = 0;
+
+ @TempDir
+ Path pluginsPath;
+
+ @BeforeEach
+ void setUp() throws IOException {
+ pluginManagerEvents = 0;
+ wrappedPluginManagerEvents = 0;
+ thisPlugin = new PluginJar.Builder(pluginsPath.resolve("test-plugin1.jar"), THIS_PLUGIN_ID).pluginClass(TestPlugin.class.getName()).pluginVersion("1.2.3").extension(TestExtension.class.getName()).build();
+ otherPlugin = new PluginJar.Builder(pluginsPath.resolve("test-plugin2.jar"), OTHER_PLUGIN_ID).pluginClass(TestPlugin.class.getName()).pluginVersion("1.2.3").extension(TestExtension.class.getName()).build();
+
+ pluginManager = new JarPluginManager(pluginsPath);
+ wrappedPluginManager = new SecurePluginManagerWrapper(pluginManager, THIS_PLUGIN_ID);
+ }
+
+ @AfterEach
+ void tearDown() {
+ pluginManager.unloadPlugins();
+
+ thisPlugin = null;
+ otherPlugin = null;
+ pluginManager = null;
+ }
+
+ @Test
+ void pluginStateListeners() {
+ pluginManager.addPluginStateListener(event -> pluginManagerEvents++);
+ wrappedPluginManager.addPluginStateListener(event -> wrappedPluginManagerEvents++);
+ pluginManager.loadPlugins();
+ pluginManager.startPlugins();
+ assertEquals(4, pluginManagerEvents);
+ assertEquals(2, wrappedPluginManagerEvents);
+ }
+
+ @Test
+ void deletePlugin() {
+ pluginManager.loadPlugins();
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.deletePlugin(OTHER_PLUGIN_ID));
+ assertTrue(wrappedPluginManager.deletePlugin(THIS_PLUGIN_ID));
+ }
+
+ @Test
+ void disablePlugin() {
+ pluginManager.loadPlugins();
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.disablePlugin(OTHER_PLUGIN_ID));
+ assertTrue(wrappedPluginManager.disablePlugin(THIS_PLUGIN_ID));
+ }
+
+ @Test
+ void enablePlugin() {
+ pluginManager.loadPlugins();
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.enablePlugin(OTHER_PLUGIN_ID));
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.enablePlugin(THIS_PLUGIN_ID));
+ }
+
+ @Test
+ void getExtensionClasses() {
+ pluginManager.loadPlugins();
+ pluginManager.startPlugins();
+ assertEquals(1, wrappedPluginManager.getExtensionClasses(TestExtensionPoint.class).size());
+
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.getExtensionClasses(TestExtensionPoint.class, OTHER_PLUGIN_ID));
+ assertEquals(1, wrappedPluginManager.getExtensionClasses(TestExtensionPoint.class, THIS_PLUGIN_ID).size());
+
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.getExtensionClasses(OTHER_PLUGIN_ID));
+ assertEquals(1, wrappedPluginManager.getExtensionClasses(THIS_PLUGIN_ID).size());
+ }
+
+ @Test
+ void getExtensionClassNames() {
+ pluginManager.loadPlugins();
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.getExtensionClassNames(OTHER_PLUGIN_ID));
+ assertEquals(1, wrappedPluginManager.getExtensionClassNames(THIS_PLUGIN_ID).size());
+ }
+
+ @Test
+ void getExtensionFactory() {
+ pluginManager.loadPlugins();
+ assertEquals(pluginManager.getExtensionFactory(), wrappedPluginManager.getExtensionFactory());
+ }
+
+ @Test
+ void getExtensions() {
+ pluginManager.loadPlugins();
+ pluginManager.startPlugins();
+ assertEquals(1, wrappedPluginManager.getExtensions(TestExtensionPoint.class).size());
+
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.getExtensions(TestExtensionPoint.class, OTHER_PLUGIN_ID));
+ assertEquals(1, wrappedPluginManager.getExtensions(TestExtensionPoint.class, THIS_PLUGIN_ID).size());
+
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.getExtensions(OTHER_PLUGIN_ID));
+ assertEquals(1, wrappedPluginManager.getExtensions(THIS_PLUGIN_ID).size());
+ }
+
+ @Test
+ void getPlugin() {
+ pluginManager.loadPlugins();
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.getPlugin(OTHER_PLUGIN_ID));
+ assertEquals(THIS_PLUGIN_ID, wrappedPluginManager.getPlugin(THIS_PLUGIN_ID).getPluginId());
+ }
+
+ @Test
+ void getPluginClassLoader() {
+ pluginManager.loadPlugins();
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.getPluginClassLoader(OTHER_PLUGIN_ID));
+ assertNotNull(wrappedPluginManager.getPluginClassLoader(THIS_PLUGIN_ID));
+ }
+
+ @Test
+ void getPlugins() {
+ pluginManager.loadPlugins();
+ assertEquals(2, pluginManager.getPlugins().size());
+ assertEquals(1, wrappedPluginManager.getPlugins().size());
+ }
+
+ @Test
+ void getPluginsRoot() {
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.getPluginsRoot());
+ }
+
+ @Test
+ void getPluginsRoots() {
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.getPluginsRoots());
+ }
+
+ @Test
+ void getResolvedPlugins() {
+ pluginManager.loadPlugins();
+ assertEquals(2, pluginManager.getResolvedPlugins().size());
+ assertEquals(1, wrappedPluginManager.getResolvedPlugins().size());
+ }
+
+ @Test
+ void getRuntimeMode() {
+ assertEquals(pluginManager.getRuntimeMode(), wrappedPluginManager.getRuntimeMode());
+ }
+
+ @Test
+ void getStartedPlugins() {
+ pluginManager.loadPlugins();
+ pluginManager.startPlugins();
+ assertEquals(2, pluginManager.getStartedPlugins().size());
+ assertEquals(1, wrappedPluginManager.getStartedPlugins().size());
+ }
+
+ @Test
+ void getSystemVersion() {
+ assertEquals(pluginManager.getSystemVersion(), wrappedPluginManager.getSystemVersion());
+ }
+
+ @Test
+ void getUnresolvedPlugins() {
+ assertNotNull(wrappedPluginManager);
+ assertNotNull(wrappedPluginManager.getUnresolvedPlugins());
+ assertTrue(wrappedPluginManager.getUnresolvedPlugins().isEmpty());
+ }
+
+ @Test
+ void getVersionManager() {
+ assertEquals(pluginManager.getVersionManager(), wrappedPluginManager.getVersionManager());
+ }
+
+ @Test
+ void isDevelopment() {
+ assertEquals(pluginManager.isDevelopment(), wrappedPluginManager.isDevelopment());
+ }
+
+ @Test
+ void isNotDevelopment() {
+ assertEquals(pluginManager.isNotDevelopment(), wrappedPluginManager.isNotDevelopment());
+ }
+
+ @Test
+ void loadPlugin() {
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.loadPlugin(thisPlugin.path()));
+ }
+
+ @Test
+ void loadPlugins() {
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.loadPlugins());
+ }
+
+ @Test
+ void setSystemVersion() {
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.setSystemVersion("1.0.0"));
+ }
+
+ @Test
+ void startPlugin() {
+ pluginManager.loadPlugins();
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.startPlugin(OTHER_PLUGIN_ID));
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.startPlugin(THIS_PLUGIN_ID));
+ }
+
+ @Test
+ void startPlugins() {
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.startPlugins());
+ }
+
+ @Test
+ void stopPlugin() {
+ pluginManager.loadPlugins();
+ pluginManager.startPlugins();
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.stopPlugin(OTHER_PLUGIN_ID));
+ assertEquals(PluginState.STOPPED, wrappedPluginManager.stopPlugin(THIS_PLUGIN_ID));
+ }
+
+ @Test
+ void stopPlugins() {
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.stopPlugins());
+ }
+
+ @Test
+ void unloadPlugin() {
+ pluginManager.loadPlugins();
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.unloadPlugin(OTHER_PLUGIN_ID));
+ assertTrue(wrappedPluginManager.unloadPlugin(THIS_PLUGIN_ID));
+ }
+
+ @Test
+ void unloadPlugins() {
+ assertThrows(IllegalAccessError.class, () -> wrappedPluginManager.unloadPlugins());
+ }
+
+ @Test
+ void whichPlugin() {
+ pluginManager.loadPlugins();
+ pluginManager.startPlugins();
+ assertEquals(null, wrappedPluginManager.whichPlugin(pluginManager.getExtensionClasses(OTHER_PLUGIN_ID).get(0)));
+ assertEquals(THIS_PLUGIN_ID, wrappedPluginManager.whichPlugin(pluginManager.getExtensionClasses(THIS_PLUGIN_ID).get(0)).getPluginId());
+ }
+
+}
* @author Decebal Suiu
* @author Ajith Kumar
*/
-public class SingletonExtensionFactoryTest {
+class SingletonExtensionFactoryTest {
@Test
- public void create() {
+ void create() {
ExtensionFactory extensionFactory = new SingletonExtensionFactory();
Object extensionOne = extensionFactory.create(TestExtension.class);
Object extensionTwo = extensionFactory.create(TestExtension.class);
}
@Test
- public void createNewEachTime() {
+ void createNewEachTime() {
ExtensionFactory extensionFactory = new SingletonExtensionFactory(FailTestExtension.class.getName());
Object extensionOne = extensionFactory.create(TestExtension.class);
Object extensionTwo = extensionFactory.create(TestExtension.class);
}
@Test
- @SuppressWarnings("unchecked")
- public void createNewEachTimeFromDifferentClassLoaders() throws Exception {
+ void createNewEachTimeFromDifferentClassLoaders() throws Exception {
ExtensionFactory extensionFactory = new SingletonExtensionFactory();
// Get classpath locations
// Create different classloaders for the classpath references and load classes respectively
ClassLoader klassLoaderOne = new URLClassLoader(classpathReferences, null);
- Class klassOne = klassLoaderOne.loadClass(TestExtension.class.getName());
+ Class<?> klassOne = klassLoaderOne.loadClass(TestExtension.class.getName());
ClassLoader klassLoaderTwo = new URLClassLoader(classpathReferences, null);
- Class klassTwo = klassLoaderTwo.loadClass(TestExtension.class.getName());
+ Class<?> klassTwo = klassLoaderTwo.loadClass(TestExtension.class.getName());
// create instances
Object instanceOne = extensionFactory.create(klassOne);
for (int index = 0; index < classpaths.length; index++) {
uris[index] = new File(classpaths[index]).toURI().toURL();
}
+
return uris;
}
/**
* @author Josiah Haswell
*/
-public class ServiceProviderExtensionStorageTest {
+class ServiceProviderExtensionStorageTest {
@Test
- public void ensureServiceProviderExtensionStorageReadWorks() throws IOException {
+ void ensureServiceProviderExtensionStorageReadWorks() throws IOException {
final StringReader file = new StringReader("#hello\n World");
final Set<String> entries = new HashSet<>();
ServiceProviderExtensionStorage.read(file, entries);
}
@Test
- public void ensureReadingExtensionsProducesCorrectListOfExtensions() {
+ void ensureReadingExtensionsProducesCorrectListOfExtensions() {
final StringReader file = new StringReader("#hello\n World");
final ExtensionAnnotationProcessor processor = mock(ExtensionAnnotationProcessor.class);
final Map<String, Set<String>> extensions = new HashMap<>();
/**
* @author Decebal Suiu
*/
-public class DirectedGraphTest {
+class DirectedGraphTest {
private static DirectedGraph<Character> graph;
}
@Test
- public void reverseTopologicalSort() {
+ void reverseTopologicalSort() {
List<Character> result = graph.reverseTopologicalSort();
List<Character> expected = Arrays.asList('C', 'G', 'F', 'B', 'A', 'E', 'D');
assertEquals(expected, result);
}
@Test
- public void topologicalSort() {
+ void topologicalSort() {
List<Character> result = graph.topologicalSort();
List<Character> expected = Arrays.asList('D', 'E', 'A', 'B', 'F', 'G', 'C');
assertEquals(expected, result);
}
@Test
- public void inDegree() {
+ void inDegree() {
Map<Character, Integer> result = graph.inDegree();
Map<Character, Integer> expected = new HashMap<>(7);
expected.put('A', 0);
}
@Test
- public void outDegree() {
+ void outDegree() {
Map<Character, Integer> result = graph.outDegree();
Map<Character, Integer> expected = new HashMap<>(7);
expected.put('A', 1);
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
-public class FileUtilsTest {
+class FileUtilsTest {
@TempDir
Path pluginsPath;
@Test
- public void expandIfZipForZipWithOnlyModuleDescriptor() throws IOException {
+ void expandIfZipForZipWithOnlyModuleDescriptor() throws IOException {
PluginZip pluginZip = new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3")
.build();
}
@Test
- public void expandIfZipForZipWithResourceFile() throws IOException {
+ void expandIfZipForZipWithResourceFile() throws IOException {
PluginZip pluginZip = new PluginZip.Builder(pluginsPath.resolve("my-second-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3")
.addFile(Paths.get("classes/META-INF/plugin-file"), "plugin")
}
@Test
- public void expandIfZipNonZipFiles() throws IOException {
+ void expandIfZipNonZipFiles() throws IOException {
// File without .suffix
Path extra = pluginsPath.resolve("extra");
assertEquals(extra, FileUtils.expandIfZip(extra));
}
@Test
- public void findPaths() throws IOException {
+ void findPaths() throws IOException {
PluginZip pluginZip = new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3")
.build();