use of com.thoughtworks.go.plugin.api.info.PluginDescriptorAware in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldLoadAValidGoPluginOSGiBundle.
@Test
public void shouldLoadAValidGoPluginOSGiBundle() throws Exception {
Bundle bundle = pluginOSGiFramework.loadPlugin(new GoPluginDescriptor(null, null, null, null, descriptorBundleDir, true));
assertThat(bundle.getState(), is(Bundle.ACTIVE));
BundleContext context = bundle.getBundleContext();
ServiceReference<?>[] allServiceReferences = context.getServiceReferences(PluginDescriptorAware.class.getCanonicalName(), null);
assertThat(allServiceReferences.length, is(1));
try {
PluginDescriptorAware service = (PluginDescriptorAware) context.getService(allServiceReferences[0]);
service.setPluginDescriptor(getDescriptor());
assertThat("@Load should have been called", getIntField(service, "loadCalled"), is(1));
} catch (Exception e) {
fail(String.format("setPluginDescriptor should have been called. Exception: %s", e.getMessage()));
}
}
use of com.thoughtworks.go.plugin.api.info.PluginDescriptorAware in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldUnloadALoadedPlugin.
@Test
public void shouldUnloadALoadedPlugin() throws Exception {
GoPluginDescriptor pluginDescriptor = new GoPluginDescriptor(null, null, null, null, descriptorBundleDir, true);
Bundle bundle = pluginOSGiFramework.loadPlugin(pluginDescriptor);
BundleContext context = bundle.getBundleContext();
ServiceReference<?>[] allServiceReferences = context.getServiceReferences(PluginDescriptorAware.class.getCanonicalName(), null);
assertThat(allServiceReferences.length, is(1));
PluginDescriptorAware service = (PluginDescriptorAware) context.getService(allServiceReferences[0]);
assertThat("@Load should have been called", getIntField(service, "loadCalled"), is(1));
pluginDescriptor.setBundle(bundle);
pluginOSGiFramework.unloadPlugin(pluginDescriptor);
assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
assertThat("@UnLoad should have been called", getIntField(service, "unloadCalled"), is(1));
}
use of com.thoughtworks.go.plugin.api.info.PluginDescriptorAware in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldPassInCorrectDescriptorToAction.
@Test
public void shouldPassInCorrectDescriptorToAction() throws Exception {
final GoPluginDescriptor descriptor = new GoPluginDescriptor("testplugin.descriptorValidator", null, null, null, descriptorBundleDir, true);
Bundle bundle = pluginOSGiFramework.loadPlugin(descriptor);
registry.loadPlugin(descriptor);
assertThat(bundle.getState(), is(Bundle.ACTIVE));
ActionWithReturn<PluginDescriptorAware, Object> action = new ActionWithReturn<PluginDescriptorAware, Object>() {
@Override
public Object execute(PluginDescriptorAware descriptorAware, GoPluginDescriptor pluginDescriptor) {
assertThat(pluginDescriptor, is(descriptor));
descriptorAware.setPluginDescriptor(pluginDescriptor);
return null;
}
};
pluginOSGiFramework.doOn(PluginDescriptorAware.class, "testplugin.descriptorValidator", action);
}
use of com.thoughtworks.go.plugin.api.info.PluginDescriptorAware in project gocd by gocd.
the class DefaultPluginJarChangeListenerTest method pluginDescriptorAwareCallbackErrorShouldNotBeFatal.
@Test
public void pluginDescriptorAwareCallbackErrorShouldNotBeFatal() throws Exception {
String pluginJarFileName = "descriptor-aware-test-plugin.jar";
File pluginJarFile = new File(PLUGIN_DIR, pluginJarFileName);
copyPluginToTheDirectory(PLUGIN_DIR, pluginJarFileName);
GoPluginDescriptor descriptor = new GoPluginDescriptor("some.old.id", "1.0", new GoPluginDescriptor.About(null, null, null, null, null, null), null, new File(pluginJarFileName), false);
when(systemEnvironment.getOperatingSystemFamilyName()).thenReturn("Windows");
when(goPluginDescriptorBuilder.build(pluginJarFile, true)).thenReturn(descriptor);
when(osgiFramework.hasReferenceFor(PluginDescriptorAware.class, descriptor.id())).thenReturn(true);
doThrow(new RuntimeException("Exception in plugin descriptor")).when(osgiFramework).doOnAllForPlugin(eq(PluginDescriptorAware.class), eq(descriptor.id()), Matchers.<Action<PluginDescriptorAware>>anyObject());
listener = new DefaultPluginJarChangeListener(registry, osgiManifestGenerator, osgiFramework, goPluginDescriptorBuilder, systemEnvironment);
listener.pluginJarAdded(new PluginFileDetails(pluginJarFile, true));
verify(registry, times(1)).loadPlugin(descriptor);
verify(osgiFramework, times(1)).loadPlugin(descriptor);
verify(osgiFramework, times(1)).hasReferenceFor(PluginDescriptorAware.class, descriptor.id());
verify(osgiFramework, times(1)).doOnAllWithExceptionHandlingForPlugin(eq(PluginDescriptorAware.class), eq(descriptor.id()), Matchers.<Action<PluginDescriptorAware>>anyObject(), Matchers.<ExceptionHandler<PluginDescriptorAware>>anyObject());
}
use of com.thoughtworks.go.plugin.api.info.PluginDescriptorAware in project gocd by gocd.
the class DefaultPluginJarChangeListenerTest method shouldNotThrowExceptionIfThePluginImplementsDescriptorAwareIsNotAvailable.
@Test
public void shouldNotThrowExceptionIfThePluginImplementsDescriptorAwareIsNotAvailable() throws Exception {
String pluginJarFileName = "descriptor-aware-test-plugin.jar";
File pluginJarFile = new File(PLUGIN_DIR, pluginJarFileName);
copyPluginToTheDirectory(PLUGIN_DIR, pluginJarFileName);
GoPluginDescriptor descriptor = new GoPluginDescriptor("some.old.id", "1.0", new GoPluginDescriptor.About(null, null, null, null, null, null), null, new File(pluginJarFileName), false);
when(systemEnvironment.getOperatingSystemFamilyName()).thenReturn("Windows");
when(goPluginDescriptorBuilder.build(pluginJarFile, true)).thenReturn(descriptor);
when(osgiFramework.hasReferenceFor(PluginDescriptorAware.class, descriptor.id())).thenReturn(false);
doThrow(new GoPluginFrameworkException("Failed to find service reference")).when(osgiFramework).doOnAllForPlugin(eq(PluginDescriptorAware.class), eq(descriptor.id()), Matchers.<Action<PluginDescriptorAware>>anyObject());
listener = new DefaultPluginJarChangeListener(registry, osgiManifestGenerator, osgiFramework, goPluginDescriptorBuilder, systemEnvironment);
listener.pluginJarAdded(new PluginFileDetails(pluginJarFile, true));
verify(registry, times(1)).loadPlugin(descriptor);
verify(osgiFramework, times(1)).loadPlugin(descriptor);
verify(osgiFramework, times(1)).hasReferenceFor(PluginDescriptorAware.class, descriptor.id());
verify(osgiFramework, never()).doOnAllForPlugin(eq(PluginDescriptorAware.class), eq(descriptor.id()), Matchers.<Action<PluginDescriptorAware>>anyObject());
}
Aggregations