import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
private DefaultPluginDescriptor pluginDescriptor;
private PluginWrapper pluginWrapper;
+ private List<PluginStateEvent> receivedEvents;
+
@TempDir
Path pluginsPath;
@BeforeEach
public void setUp() throws IOException {
+ receivedEvents = new ArrayList<>();
+
pluginManager = new DefaultPluginManager(pluginsPath);
+ pluginManager.addPluginStateListener(event -> receivedEvents.add(event));
pluginDescriptor = new DefaultPluginDescriptor();
pluginDescriptor.setPluginId("myPlugin");
pluginManager = null;
pluginDescriptor = null;
pluginWrapper = null;
+ receivedEvents = null;
}
@Test
PluginManager pluginManager = new DefaultPluginManager(pluginsPath) {
+ @Override
protected PluginStatusProvider createPluginStatusProvider() {
return statusProvider;
}
assertTrue(deleted);
assertFalse(pluginZip.file().exists());
+
+ Optional<PluginStateEvent> unloadedEvent = receivedEvents.stream()
+ .filter(event -> event.getPluginState() == PluginState.UNLOADED)
+ .findFirst();
+
+ assertTrue(unloadedEvent.isPresent());
}
@Test
assertTrue(deleted);
assertFalse(pluginJar.file().exists());
+
+ Optional<PluginStateEvent> unloadedEvent = receivedEvents.stream()
+ .filter(event -> event.getPluginState() == PluginState.UNLOADED)
+ .findFirst();
+
+ assertTrue(unloadedEvent.isPresent());
}
@Test
assertThrows(DependencyResolver.CyclicDependencyException.class, () -> pluginManager.loadPlugins());
}
+ @Test
+ public void deleteZipPluginForPluginThatHasNotBeenStartedPostsUnloadedEvent() throws Exception {
+ PluginZip pluginZip = new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin")
+ .pluginVersion("1.2.3")
+ .build();
+
+ pluginManager.loadPlugin(pluginZip.path());
+
+ assertEquals(1, pluginManager.getPlugins().size());
+
+ boolean deleted = pluginManager.deletePlugin(pluginZip.pluginId());
+ assertTrue(deleted);
+
+ assertFalse(pluginZip.file().exists());
+
+ Optional<PluginStateEvent> unloadedEvent = receivedEvents.stream()
+ .filter(event -> event.getPluginState() == PluginState.UNLOADED)
+ .findFirst();
+
+ assertTrue(unloadedEvent.isPresent());
+ }
}