1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- /*
- * 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.AfterEach;
- import org.junit.jupiter.api.BeforeEach;
- import org.junit.jupiter.api.Test;
- import org.junit.jupiter.api.io.TempDir;
- import org.pf4j.plugin.PluginJar;
- import org.pf4j.plugin.TestPlugin;
-
- import java.io.IOException;
- import java.nio.file.Path;
-
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import static org.junit.jupiter.api.Assertions.assertFalse;
- import static org.junit.jupiter.api.Assertions.assertTrue;
-
- public class JarPluginManagerTest {
-
- private PluginJar pluginJar;
- private JarPluginManager pluginManager;
-
- @TempDir
- Path pluginsPath;
-
- @BeforeEach
- public void setUp() throws IOException {
- pluginJar = new PluginJar.Builder(pluginsPath.resolve("test-plugin.jar"), "test-plugin")
- .pluginClass(TestPlugin.class.getName())
- .pluginVersion("1.2.3")
- .build();
-
- pluginManager = new JarPluginManager(pluginsPath);
- }
-
- @AfterEach
- public void tearDown() {
- pluginJar = null;
- pluginManager = null;
- }
-
- @Test
- public void unloadPlugin() throws Exception {
- pluginManager.loadPlugins();
-
- assertEquals(1, pluginManager.getPlugins().size());
-
- boolean unloaded = pluginManager.unloadPlugin(pluginJar.pluginId());
- assertTrue(unloaded);
-
- assertTrue(pluginJar.file().exists());
- }
-
- @Test
- public void deletePlugin() throws Exception {
- pluginManager.loadPlugins();
-
- assertEquals(1, pluginManager.getPlugins().size());
-
- boolean deleted = pluginManager.deletePlugin(pluginJar.pluginId());
- assertTrue(deleted);
-
- assertFalse(pluginJar.file().exists());
- }
-
- }
|