use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldUseOldClassLoaderBehaviourWhenSystemPropertyIsSet.
@Test
void shouldUseOldClassLoaderBehaviourWhenSystemPropertyIsSet() {
systemEnvironment.setProperty("gocd.plugins.classloader.old", "true");
final GoPluginDescriptor goPluginDescriptor = getPluginDescriptor("plugin.to.test.classloader", pluginToTestClassloadPluginBundleDir);
final GoPluginBundleDescriptor descriptor = new GoPluginBundleDescriptor(goPluginDescriptor);
registry.loadPlugin(descriptor);
Bundle bundle = pluginOSGiFramework.loadPlugin(descriptor);
assertThat(bundle.getState()).isEqualTo(Bundle.ACTIVE);
ActionWithReturn<GoPlugin, Object> action = (plugin, pluginDescriptor) -> {
assertThat(pluginDescriptor).isEqualTo(goPluginDescriptor);
assertThat(Thread.currentThread().getContextClassLoader().getClass().getCanonicalName()).isNotEqualTo(BundleClassLoader.class.getCanonicalName());
return null;
};
pluginOSGiFramework.doOn(GoPlugin.class, "plugin.to.test.classloader", "notification", action);
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.
the class PluginLoaderTest method shouldCallUnloadListenersForEveryPluginInBundle.
@Test
void shouldCallUnloadListenersForEveryPluginInBundle() {
final GoPluginDescriptor pluginDescriptor1 = GoPluginDescriptor.builder().id("plugin.1").build();
final GoPluginDescriptor pluginDescriptor2 = GoPluginDescriptor.builder().id("plugin.2").build();
GoPluginBundleDescriptor pluginBundleDescriptor = new GoPluginBundleDescriptor(pluginDescriptor1, pluginDescriptor2);
pluginBundleDescriptor.setBundle(mock(Bundle.class));
PluginChangeListener pluginChangeListener = mock(PluginChangeListener.class, "Listener Which Works: 1");
pluginLoader.addPluginChangeListener(pluginChangeListener);
pluginLoader.unloadPlugin(pluginBundleDescriptor);
verify(pluginChangeListener, times(1)).pluginUnLoaded(pluginDescriptor1);
verify(pluginChangeListener, times(1)).pluginUnLoaded(pluginDescriptor2);
verify(pluginOSGiFramework, times(1)).unloadPlugin(pluginBundleDescriptor);
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.
the class PluginLoaderTest method shouldNotCallPostLoadHooksAndListenersIfBundleFailsToLoad.
@Test
void shouldNotCallPostLoadHooksAndListenersIfBundleFailsToLoad() {
PluginChangeListener changeListener = mock(PluginChangeListener.class);
PluginPostLoadHook postLoadHook = mock(PluginPostLoadHook.class);
GoPluginDescriptor pluginDescriptor = GoPluginDescriptor.builder().id("plugin1").build();
GoPluginBundleDescriptor goPluginBundleDescriptor = new GoPluginBundleDescriptor(pluginDescriptor);
when(pluginOSGiFramework.loadPlugin(goPluginBundleDescriptor)).then(invocation -> {
goPluginBundleDescriptor.markAsInvalid(singletonList("Ouch!"), null);
goPluginBundleDescriptor.setBundle(mock(Bundle.class));
return goPluginBundleDescriptor.bundle();
});
pluginLoader.addPluginChangeListener(changeListener);
pluginLoader.addPluginPostLoadHook(postLoadHook);
pluginLoader.loadPlugin(goPluginBundleDescriptor);
verifyNoMoreInteractions(postLoadHook);
verify(changeListener, times(0)).pluginLoaded(pluginDescriptor);
verify(changeListener, times(1)).pluginUnLoaded(pluginDescriptor);
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.
the class PluginLoaderTest method shouldUnloadPluginIfBundleThrowsExceptionDuringLoad.
@Test
void shouldUnloadPluginIfBundleThrowsExceptionDuringLoad() {
GoPluginDescriptor pluginDescriptor = GoPluginDescriptor.builder().id("plugin1").build();
GoPluginBundleDescriptor pluginBundleDescriptor = new GoPluginBundleDescriptor(pluginDescriptor);
when(pluginOSGiFramework.loadPlugin(pluginBundleDescriptor)).then(invocation -> {
pluginBundleDescriptor.setBundle(mock(Bundle.class));
throw new UnsupportedOperationException("Ouch!");
});
assertThatCode(() -> pluginLoader.loadPlugin(pluginBundleDescriptor)).isInstanceOf(RuntimeException.class).hasMessageContaining("Failed to load plugin");
assertThat(pluginDescriptor.isInvalid()).isTrue();
assertThat(pluginDescriptor.getStatus().getMessages()).isEqualTo(singletonList("Ouch!"));
verify(pluginOSGiFramework, times(1)).unloadPlugin(pluginBundleDescriptor);
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldPassInCorrectDescriptorToAction.
@Test
void shouldPassInCorrectDescriptorToAction() {
final GoPluginDescriptor goPluginDescriptor = getPluginDescriptor(PLUGIN_ID, descriptorBundleDir);
final GoPluginBundleDescriptor bundleDescriptor = new GoPluginBundleDescriptor(goPluginDescriptor);
registry.loadPlugin(bundleDescriptor);
Bundle bundle = pluginOSGiFramework.loadPlugin(bundleDescriptor);
assertThat(bundle.getState()).isEqualTo(Bundle.ACTIVE);
ActionWithReturn<GoPlugin, Object> action = (plugin, pluginDescriptor) -> {
assertThat(pluginDescriptor).isEqualTo(goPluginDescriptor);
plugin.pluginIdentifier();
return null;
};
pluginOSGiFramework.doOn(GoPlugin.class, PLUGIN_ID, "notification", action);
}
Aggregations