Search in sources :

Example 81 with GoPluginDescriptor

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

the class AuthorizationPluginInfoBuilderTest method shouldBuildPluginInfoWithRoleSettings.

@Test
public void shouldBuildPluginInfoWithRoleSettings() throws Exception {
    GoPluginDescriptor descriptor = new GoPluginDescriptor("plugin1", null, null, null, null, false);
    List<PluginConfiguration> pluginConfigurations = Arrays.asList(new PluginConfiguration("group", new Metadata(true, false)), new PluginConfiguration("something_secure", new Metadata(true, true)));
    when(extension.getRoleConfigurationMetadata(descriptor.id())).thenReturn(pluginConfigurations);
    when(extension.getRoleConfigurationView(descriptor.id())).thenReturn("role_config");
    AuthorizationPluginInfo pluginInfo = new AuthorizationPluginInfoBuilder(extension).pluginInfoFor(descriptor);
    assertThat(pluginInfo.getRoleSettings(), is(new PluggableInstanceSettings(pluginConfigurations, new PluginView("role_config"))));
}
Also used : AuthorizationPluginInfo(com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.Test)

Example 82 with GoPluginDescriptor

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

the class AuthorizationPluginInfoBuilderTest method shouldBuildPluginInfoWithAuthSettings.

@Test
public void shouldBuildPluginInfoWithAuthSettings() throws Exception {
    GoPluginDescriptor descriptor = new GoPluginDescriptor("plugin1", null, null, null, null, false);
    List<PluginConfiguration> pluginConfigurations = Arrays.asList(new PluginConfiguration("username", new Metadata(true, false)), new PluginConfiguration("password", new Metadata(true, true)));
    when(extension.getAuthConfigMetadata(descriptor.id())).thenReturn(pluginConfigurations);
    when(extension.getAuthConfigView(descriptor.id())).thenReturn("auth_config");
    AuthorizationPluginInfo pluginInfo = new AuthorizationPluginInfoBuilder(extension).pluginInfoFor(descriptor);
    assertThat(pluginInfo.getAuthConfigSettings(), is(new PluggableInstanceSettings(pluginConfigurations, new PluginView("auth_config"))));
}
Also used : AuthorizationPluginInfo(com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.Test)

Example 83 with GoPluginDescriptor

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

the class PluginSettingsMetadataLoaderTest method shouldNotFailWhenAPluginWithMultipleExtensionsHasMoreThanOneExtensionRespondingWithSettings_BUT_OnlyOneIsValid.

@Test
public void shouldNotFailWhenAPluginWithMultipleExtensionsHasMoreThanOneExtensionRespondingWithSettings_BUT_OnlyOneIsValid() throws Exception {
    PluginSettingsConfiguration configuration = new PluginSettingsConfiguration();
    configuration.add(new PluginSettingsProperty("k1").with(Property.REQUIRED, true).with(Property.SECURE, false));
    String pluginID = "plugin-id";
    GoPluginDescriptor pluginDescriptor = new GoPluginDescriptor(pluginID, "1.0", null, null, null, true);
    setupSettingsResponses(notificationExtension, pluginID, configuration, null);
    setupSettingsResponses(packageRepositoryExtension, pluginID, configuration, "view");
    metadataLoader.fetchPluginSettingsMetaData(pluginDescriptor);
    assertThat(PluginSettingsMetadataStore.getInstance().hasPlugin(pluginID), is(true));
    assertThat(PluginSettingsMetadataStore.getInstance().configuration(pluginID), is(configuration));
    assertThat(PluginSettingsMetadataStore.getInstance().template(pluginID), is("view"));
    assertThat(PluginSettingsMetadataStore.getInstance().extensionWhichCanHandleSettings(pluginID), is(PluginConstants.PACKAGE_MATERIAL_EXTENSION));
}
Also used : GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.Test)

Example 84 with GoPluginDescriptor

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

the class PluginSettingsMetadataLoaderTest method shouldNotFailWhenAPluginWithMultipleExtensionsHasMoreThanOneExtensionRespondingWithSettings_BUT_OneIsValidAndOtherThrowsException.

@Test
public void shouldNotFailWhenAPluginWithMultipleExtensionsHasMoreThanOneExtensionRespondingWithSettings_BUT_OneIsValidAndOtherThrowsException() throws Exception {
    PluginSettingsConfiguration configuration = new PluginSettingsConfiguration();
    configuration.add(new PluginSettingsProperty("k1").with(Property.REQUIRED, true).with(Property.SECURE, false));
    String pluginID = "plugin-id";
    GoPluginDescriptor pluginDescriptor = new GoPluginDescriptor(pluginID, "1.0", null, null, null, true);
    setupSettingsResponses(notificationExtension, pluginID, configuration, "view");
    when(packageRepositoryExtension.canHandlePlugin(pluginID)).thenReturn(false);
    when(scmExtension.canHandlePlugin(pluginID)).thenReturn(true);
    when(scmExtension.getPluginSettingsConfiguration(pluginID)).thenThrow(new RuntimeException("Ouch!"));
    when(scmExtension.getPluginSettingsView(pluginID)).thenReturn("view");
    metadataLoader.fetchPluginSettingsMetaData(pluginDescriptor);
    assertThat(PluginSettingsMetadataStore.getInstance().hasPlugin(pluginID), is(true));
    verify(packageRepositoryExtension, never()).getPluginSettingsConfiguration(pluginID);
    verify(packageRepositoryExtension, never()).getPluginSettingsView(pluginID);
}
Also used : GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.Test)

Example 85 with GoPluginDescriptor

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

the class PluginSettingsMetadataLoaderTest method shouldFailWhenAPluginWithMultipleExtensionsHasMoreThanOneExtensionRespondingWithSettings.

@Test
public void shouldFailWhenAPluginWithMultipleExtensionsHasMoreThanOneExtensionRespondingWithSettings() throws Exception {
    PluginSettingsConfiguration configuration = new PluginSettingsConfiguration();
    configuration.add(new PluginSettingsProperty("k1").with(Property.REQUIRED, true).with(Property.SECURE, false));
    String pluginID = "plugin-id";
    GoPluginDescriptor pluginDescriptor = new GoPluginDescriptor(pluginID, "1.0", null, null, null, true);
    setupSettingsResponses(notificationExtension, pluginID, configuration, "view");
    setupSettingsResponses(packageRepositoryExtension, pluginID, configuration, "view");
    try {
        metadataLoader.fetchPluginSettingsMetaData(pluginDescriptor);
        fail("Should have failed since multiple extensions support plugin settings.");
    } catch (Exception e) {
        assertThat(e.getMessage(), containsString("Plugin with ID: plugin-id has more than one extension which supports plugin settings"));
        assertThat(PluginSettingsMetadataStore.getInstance().hasPlugin(pluginDescriptor.id()), is(false));
    }
}
Also used : 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