Search in sources :

Example 36 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 37 with GoPluginDescriptor

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

the class FelixGoPluginOSGiFrameworkTest method shouldMarkThePluginAsInvalidIfAnyExceptionOccursAfterLoad.

@Test
public void shouldMarkThePluginAsInvalidIfAnyExceptionOccursAfterLoad() throws BundleException {
    final Bundle bundle = mock(Bundle.class);
    spy.addPluginChangeListener(new PluginChangeListener() {

        @Override
        public void pluginLoaded(GoPluginDescriptor pluginDescriptor) {
            throw new RuntimeException("some error");
        }

        @Override
        public void pluginUnLoaded(GoPluginDescriptor pluginDescriptor) {
        }
    });
    when(bundleContext.installBundle(any(String.class))).thenReturn(bundle);
    final GoPluginDescriptor goPluginDescriptor = new GoPluginDescriptor(TEST_SYMBOLIC_NAME, "1.0", null, "location", new File(""), false);
    spy.start();
    try {
        spy.loadPlugin(goPluginDescriptor);
        fail("should throw exception");
    } catch (Exception e) {
        assertTrue(goPluginDescriptor.getStatus().isInvalid());
    }
}
Also used : GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) File(java.io.File) Test(org.junit.Test)

Example 38 with GoPluginDescriptor

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

the class DefaultPluginInfoFinderTest method getDescriptor.

private GoPluginDescriptor getDescriptor(String pluginID) {
    GoPluginDescriptor.Vendor vendor = new GoPluginDescriptor.Vendor("vendor-name", "vendor-url");
    GoPluginDescriptor.About about = new GoPluginDescriptor.About("author", "1.0", "17.12", "some description", vendor, Collections.emptyList());
    return new GoPluginDescriptor(pluginID, "1.0", about, "/path/to/plugin", new File("/path/to/bundle"), false);
}
Also used : GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) File(java.io.File)

Example 39 with GoPluginDescriptor

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

the class TaskViewServiceTest method shouldGetViewModelsForPluggedInTasks_ButOnlyForExistingPlugins.

@Test
public void shouldGetViewModelsForPluggedInTasks_ButOnlyForExistingPlugins() throws Exception {
    String plugin1 = "task-plugin-1";
    String plugin2 = "task-plugin-2";
    when(pluginManager.getPluginDescriptorFor(plugin1)).thenReturn(new GoPluginDescriptor(plugin1, "1", null, null, null, false));
    when(pluginManager.getPluginDescriptorFor(plugin2)).thenReturn(new GoPluginDescriptor(plugin2, "1", null, null, null, false));
    storeTaskPreferences(plugin1, "key_1", "key_2");
    storeTaskPreferences(plugin2, "key_3", "key_4");
    when(registry.implementersOf(Task.class)).thenReturn(Arrays.<Class<? extends Task>>asList(ExecTask.class, PluggableTask.class));
    PluggableTask expectedPluggableTaskForPlugin1 = new PluggableTask(new PluginConfiguration(plugin1, "1"), new Configuration(create("key_1"), create("key_2")));
    PluggableTask expectedPluggableTaskForPlugin2 = new PluggableTask(new PluginConfiguration(plugin2, "1"), new Configuration(create("key_3"), create("key_4")));
    when(registry.getViewModelFor(new ExecTask(), "new")).thenReturn(viewModel(new ExecTask()));
    when(registry.getViewModelFor(expectedPluggableTaskForPlugin1, "new")).thenReturn(viewModel(expectedPluggableTaskForPlugin1));
    when(registry.getViewModelFor(expectedPluggableTaskForPlugin2, "new")).thenReturn(viewModel(expectedPluggableTaskForPlugin2));
    List<PluggableViewModel> viewModels = taskViewService.getTaskViewModels();
    assertThat(viewModels.size(), is(3));
    assertThat(viewModels.get(0).getModel(), instanceOf(ExecTask.class));
    assertThat(viewModels.get(1).getModel(), instanceOf(PluggableTask.class));
    assertThat(viewModels.get(2).getModel(), instanceOf(PluggableTask.class));
    assertThat(viewModels.get(1).getModel(), is(expectedPluggableTaskForPlugin1));
    assertThat(viewModels.get(2).getModel(), is(expectedPluggableTaskForPlugin2));
    verify(registry).getViewModelFor(expectedPluggableTaskForPlugin1, "new");
    verify(registry).getViewModelFor(expectedPluggableTaskForPlugin2, "new");
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) ExecTask(com.thoughtworks.go.config.ExecTask) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) PluggableViewModel(com.thoughtworks.go.plugins.presentation.PluggableViewModel) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.Test)

Example 40 with GoPluginDescriptor

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

the class TaskViewServiceTest method shouldStoreDefaultValuesGivenForPropertiesInAPluginWhenInitializingANewTaskPlugin.

@Test
public void shouldStoreDefaultValuesGivenForPropertiesInAPluginWhenInitializingANewTaskPlugin() throws Exception {
    String plugin = "task-plugin";
    when(pluginManager.getPluginDescriptorFor(plugin)).thenReturn(new GoPluginDescriptor(plugin, "1", null, null, null, false));
    Property taskConfigProperty1 = new TaskConfigProperty("key1", null);
    Property taskConfigProperty2 = new TaskConfigProperty("key2", null);
    Property taskConfigProperty3 = new TaskConfigProperty("key3", null);
    storeTaskPreferences(plugin, taskConfigProperty1.withDefault("default1"), taskConfigProperty2.withDefault("default2"), taskConfigProperty3);
    when(registry.implementersOf(Task.class)).thenReturn(Arrays.<Class<? extends Task>>asList(PluggableTask.class));
    PluggableTask pluggableTask = (PluggableTask) taskViewService.taskInstanceFor(new PluggableTask(new PluginConfiguration(plugin, "1"), new Configuration()).getTaskType());
    assertThat(pluggableTask.getConfiguration().getProperty("key1").getValue(), is("default1"));
    assertThat(pluggableTask.getConfiguration().getProperty("key2").getValue(), is("default2"));
    assertNull(pluggableTask.getConfiguration().getProperty("key3").getValue());
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) Property(com.thoughtworks.go.plugin.api.config.Property) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.Test)

Aggregations

GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)214 Test (org.junit.jupiter.api.Test)114 Test (org.junit.Test)53 ElasticAgentPluginInfo (com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo)20 File (java.io.File)19 PluginManager (com.thoughtworks.go.plugin.infra.PluginManager)16 PluggableInstanceSettings (com.thoughtworks.go.server.ui.plugins.PluggableInstanceSettings)14 AuthorizationPluginInfo (com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo)12 Capabilities (com.thoughtworks.go.plugin.domain.elastic.Capabilities)12 Before (org.junit.Before)12 AnalyticsPluginInfo (com.thoughtworks.go.plugin.domain.analytics.AnalyticsPluginInfo)11 GoPluginBundleDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor)11 PluginView (com.thoughtworks.go.server.ui.plugins.PluginView)11 Bundle (org.osgi.framework.Bundle)10 GoPlugin (com.thoughtworks.go.plugin.api.GoPlugin)9 PluginInfo (com.thoughtworks.go.server.ui.plugins.PluginInfo)9 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)8 TaskView (com.thoughtworks.go.plugin.api.task.TaskView)8 ArrayList (java.util.ArrayList)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)8