Search in sources :

Example 46 with GoPluginDescriptor

use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor in project gocd by gocd.

the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldNotifyListenersWhenPluginUnLoaded.

@Test
public void shouldNotifyListenersWhenPluginUnLoaded() {
    PluginChangeListener pluginChangeListener = mock(PluginChangeListener.class);
    pluginOSGiFramework.addPluginChangeListener(pluginChangeListener);
    GoPluginDescriptor pluginDescriptor = new GoPluginDescriptor(null, null, null, null, descriptorBundleDir, true);
    Bundle bundle = pluginOSGiFramework.loadPlugin(pluginDescriptor);
    pluginDescriptor.setBundle(bundle);
    pluginOSGiFramework.unloadPlugin(pluginDescriptor);
    verify(pluginChangeListener).pluginUnLoaded(pluginDescriptor);
}
Also used : GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.Test)

Example 47 with GoPluginDescriptor

use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor 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(GoPlugin.class.getCanonicalName(), null);
    assertThat(allServiceReferences.length, is(1));
    GoPlugin service = (GoPlugin) 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));
}
Also used : GoPlugin(com.thoughtworks.go.plugin.api.GoPlugin) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.Test)

Example 48 with GoPluginDescriptor

use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor in project gocd by gocd.

the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldNotifyListenersWhenPluginLoaded.

@Test
public void shouldNotifyListenersWhenPluginLoaded() {
    PluginChangeListener pluginChangeListener = mock(PluginChangeListener.class);
    pluginOSGiFramework.addPluginChangeListener(pluginChangeListener);
    GoPluginDescriptor pluginDescriptor = new GoPluginDescriptor(null, null, null, null, descriptorBundleDir, true);
    pluginOSGiFramework.loadPlugin(pluginDescriptor);
    verify(pluginChangeListener).pluginLoaded(pluginDescriptor);
}
Also used : GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.Test)

Example 49 with GoPluginDescriptor

use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor 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(GoPlugin.class.getCanonicalName(), null);
    assertThat(allServiceReferences.length, is(1));
    try {
        GoPlugin service = (GoPlugin) context.getService(allServiceReferences[0]);
        service.pluginIdentifier();
        assertThat("@Load should have been called", getIntField(service, "loadCalled"), is(1));
    } catch (Exception e) {
        fail(String.format("pluginIdentifier should have been called. Exception: %s", e.getMessage()));
    }
}
Also used : GoPlugin(com.thoughtworks.go.plugin.api.GoPlugin) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Test(org.junit.Test)

Example 50 with GoPluginDescriptor

use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor in project gocd by gocd.

the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldPassInCorrectDescriptorToAction.

@Test
public void shouldPassInCorrectDescriptorToAction() {
    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<GoPlugin, Object> action = new ActionWithReturn<GoPlugin, Object>() {

        @Override
        public Object execute(GoPlugin plugin, GoPluginDescriptor pluginDescriptor) {
            assertThat(pluginDescriptor, is(descriptor));
            plugin.pluginIdentifier();
            return null;
        }
    };
    pluginOSGiFramework.doOn(GoPlugin.class, "testplugin.descriptorValidator", "notification", action);
}
Also used : GoPlugin(com.thoughtworks.go.plugin.api.GoPlugin) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.Test)

Aggregations

GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)197 Test (org.junit.Test)155 File (java.io.File)17 PluginManager (com.thoughtworks.go.plugin.infra.PluginManager)16 TinyBundle (org.ops4j.pax.tinybundles.core.TinyBundle)15 PluggableInstanceSettings (com.thoughtworks.go.server.ui.plugins.PluggableInstanceSettings)14 Before (org.junit.Before)14 AnalyticsPluginInfo (com.thoughtworks.go.plugin.domain.analytics.AnalyticsPluginInfo)12 AuthorizationPluginInfo (com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo)12 ElasticAgentPluginInfo (com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo)11 PluginView (com.thoughtworks.go.server.ui.plugins.PluginView)11 GoPlugin (com.thoughtworks.go.plugin.api.GoPlugin)10 TaskView (com.thoughtworks.go.plugin.api.task.TaskView)9 PluginInfo (com.thoughtworks.go.server.ui.plugins.PluginInfo)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)9 Answer (org.mockito.stubbing.Answer)9 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)8 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)8 ArrayList (java.util.ArrayList)8 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)7