use of com.thoughtworks.go.plugin.api.GoPlugin in project gocd by gocd.
the class DefaultPluginManagerTest method shouldNotFindPluginIsOfGivenExtensionWhenReferenceNotFoundAndExtensionDoNotMatch.
@Test
public void shouldNotFindPluginIsOfGivenExtensionWhenReferenceNotFoundAndExtensionDoNotMatch() throws Exception {
final String pluginThatDoesNotImplement = "plugin-that-does-not-implement";
GoPluginIdentifier pluginIdentifier = new GoPluginIdentifier("another-extension-type", asList("1.0"));
final GoPlugin goPlugin = mock(GoPlugin.class);
final GoPluginDescriptor descriptor = mock(GoPluginDescriptor.class);
when(goPluginOSGiFramework.hasReferenceFor(GoPlugin.class, pluginThatDoesNotImplement)).thenReturn(true);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
ActionWithReturn<GoPlugin, GoPluginApiResponse> action = (ActionWithReturn<GoPlugin, GoPluginApiResponse>) invocationOnMock.getArguments()[2];
return action.execute(goPlugin, descriptor);
}
}).when(goPluginOSGiFramework).doOn(eq(GoPlugin.class), eq(pluginThatDoesNotImplement), any(ActionWithReturn.class));
when(goPlugin.pluginIdentifier()).thenReturn(pluginIdentifier);
DefaultPluginManager pluginManager = new DefaultPluginManager(monitor, registry, goPluginOSGiFramework, jarChangeListener, pluginRequestProcessorRegistry, pluginWriter, pluginValidator, systemEnvironment, pluginsZipUpdater, pluginsListListener);
assertFalse(pluginManager.isPluginOfType("extension-type", pluginThatDoesNotImplement));
verify(goPluginOSGiFramework).doOn(eq(GoPlugin.class), eq(pluginThatDoesNotImplement), any(ActionWithReturn.class));
}
use of com.thoughtworks.go.plugin.api.GoPlugin 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);
}
use of com.thoughtworks.go.plugin.api.GoPlugin in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldLoadAValidGoPluginOSGiBundle.
@Test
void shouldLoadAValidGoPluginOSGiBundle() throws Exception {
final GoPluginBundleDescriptor bundleDescriptor = new GoPluginBundleDescriptor(getPluginDescriptor(PLUGIN_ID, descriptorBundleDir));
registry.loadPlugin(bundleDescriptor);
Bundle bundle = pluginOSGiFramework.loadPlugin(bundleDescriptor);
assertThat(bundle.getState()).isEqualTo(Bundle.ACTIVE);
BundleContext context = bundle.getBundleContext();
ServiceReference<?>[] allServiceReferences = context.getServiceReferences(GoPlugin.class.getCanonicalName(), null);
assertThat(allServiceReferences.length).isEqualTo(1);
try {
GoPlugin service = (GoPlugin) context.getService(allServiceReferences[0]);
service.pluginIdentifier();
assertThat(getIntField(service, "loadCalled")).as("@Load should have been called").isEqualTo(1);
} catch (Exception e) {
fail(String.format("pluginIdentifier should have been called. Exception: %s", e.getMessage()));
}
}
use of com.thoughtworks.go.plugin.api.GoPlugin in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldUnloadALoadedPlugin.
@Test
void shouldUnloadALoadedPlugin() throws Exception {
GoPluginBundleDescriptor bundleDescriptor = new GoPluginBundleDescriptor(getPluginDescriptor(PLUGIN_ID, descriptorBundleDir));
registry.loadPlugin(bundleDescriptor);
Bundle bundle = pluginOSGiFramework.loadPlugin(bundleDescriptor);
BundleContext context = bundle.getBundleContext();
ServiceReference<?>[] allServiceReferences = context.getServiceReferences(GoPlugin.class.getCanonicalName(), null);
assertThat(allServiceReferences.length).isEqualTo(1);
GoPlugin service = (GoPlugin) context.getService(allServiceReferences[0]);
assertThat(getIntField(service, "loadCalled")).as("@Load should have been called").isEqualTo(1);
bundleDescriptor.setBundle(bundle);
pluginOSGiFramework.unloadPlugin(bundleDescriptor);
assertThat(bundle.getState()).isEqualTo(Bundle.UNINSTALLED);
assertThat(getIntField(service, "unloadCalled")).as("@UnLoad should have been called").isEqualTo(1);
}
use of com.thoughtworks.go.plugin.api.GoPlugin 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);
}
Aggregations