Search in sources :

Example 1 with Capabilities

use of com.thoughtworks.go.plugin.domain.configrepo.Capabilities in project gocd by gocd.

the class PluginSettingsTest method shouldAddConfigurationsToSettingsMapCorrectly.

@Test
public void shouldAddConfigurationsToSettingsMapCorrectly() throws CryptoException {
    ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>();
    pluginConfigurations.add(new PluginConfiguration("k1", new Metadata(true, false)));
    pluginConfigurations.add(new PluginConfiguration("k2", new Metadata(true, true)));
    ConfigRepoPluginInfo pluginInfo = new ConfigRepoPluginInfo(null, null, new PluggableInstanceSettings(pluginConfigurations), new Capabilities());
    ArrayList<ConfigurationProperty> configurationProperties = new ArrayList<>();
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1")));
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("k2"), new EncryptedConfigurationValue(new GoCipher().encrypt("v2"))));
    PluginSettings pluginSettings = new PluginSettings(PLUGIN_ID);
    pluginSettings.addConfigurations(pluginInfo, configurationProperties);
    PluginSettingsConfiguration pluginSettingsProperties = pluginSettings.toPluginSettingsConfiguration();
    assertThat(pluginSettingsProperties.size(), is(2));
    assertThat(pluginSettingsProperties.get("k1").getValue(), is("v1"));
    assertThat(pluginSettingsProperties.get("k2").getValue(), is("v2"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) GoCipher(com.thoughtworks.go.security.GoCipher) ArrayList(java.util.ArrayList) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Capabilities(com.thoughtworks.go.plugin.domain.configrepo.Capabilities) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) ConfigRepoPluginInfo(com.thoughtworks.go.plugin.domain.configrepo.ConfigRepoPluginInfo) PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) Test(org.junit.jupiter.api.Test)

Example 2 with Capabilities

use of com.thoughtworks.go.plugin.domain.configrepo.Capabilities in project gocd by gocd.

the class PluginSettingsTest method shouldEncryptedValuesForSecureProperties.

@Test
public void shouldEncryptedValuesForSecureProperties() throws CryptoException {
    ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>();
    pluginConfigurations.add(new PluginConfiguration("k1", new Metadata(true, false)));
    pluginConfigurations.add(new PluginConfiguration("k2", new Metadata(true, true)));
    ConfigRepoPluginInfo pluginInfo = new ConfigRepoPluginInfo(null, null, new PluggableInstanceSettings(pluginConfigurations), new Capabilities());
    ConfigurationProperty configProperty1 = new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1"));
    ConfigurationProperty configProperty2 = new ConfigurationProperty(new ConfigurationKey("k2"), new EncryptedConfigurationValue(new GoCipher().encrypt("v2")));
    ArrayList<ConfigurationProperty> configurationProperties = new ArrayList<>();
    configurationProperties.add(configProperty1);
    configurationProperties.add(configProperty2);
    PluginSettings pluginSettings = new PluginSettings(PLUGIN_ID);
    pluginSettings.addConfigurations(pluginInfo, configurationProperties);
    List<ConfigurationProperty> pluginSettingsProperties = pluginSettings.getPluginSettingsProperties();
    assertThat(pluginSettingsProperties.size(), is(2));
    assertThat(pluginSettingsProperties.get(0), is(configProperty1));
    assertThat(pluginSettingsProperties.get(1), is(configProperty2));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) GoCipher(com.thoughtworks.go.security.GoCipher) ArrayList(java.util.ArrayList) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Capabilities(com.thoughtworks.go.plugin.domain.configrepo.Capabilities) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) ConfigRepoPluginInfo(com.thoughtworks.go.plugin.domain.configrepo.ConfigRepoPluginInfo) Test(org.junit.jupiter.api.Test)

Example 3 with Capabilities

use of com.thoughtworks.go.plugin.domain.configrepo.Capabilities in project gocd by gocd.

the class ConfigRepoExtensionTest method shouldRequestCapabilitiesV1.

@Test
public void shouldRequestCapabilitiesV1() {
    Capabilities capabilities = new Capabilities(false, false, false, false);
    Capabilities res = extension.getCapabilities(PLUGIN_ID);
    assertThat(capabilities, is(res));
}
Also used : Capabilities(com.thoughtworks.go.plugin.domain.configrepo.Capabilities) Test(org.junit.jupiter.api.Test)

Example 4 with Capabilities

use of com.thoughtworks.go.plugin.domain.configrepo.Capabilities in project gocd by gocd.

the class ConfigRepoExtensionTest method shouldRequestCapabilities.

@Test
public void shouldRequestCapabilities() {
    Capabilities capabilities = new Capabilities(true, true, false, false);
    when(jsonMessageHandler2.getCapabilitiesFromResponse(responseBody)).thenReturn(capabilities);
    when(pluginManager.resolveExtensionVersion(PLUGIN_ID, CONFIG_REPO_EXTENSION, new ArrayList<>(Arrays.asList("1.0", "2.0", "3.0")))).thenReturn("2.0");
    Capabilities res = extension.getCapabilities(PLUGIN_ID);
    assertRequest(requestArgumentCaptor.getValue(), CONFIG_REPO_EXTENSION, "2.0", ConfigRepoExtension.REQUEST_CAPABILITIES, null);
    assertSame(capabilities, res);
}
Also used : Capabilities(com.thoughtworks.go.plugin.domain.configrepo.Capabilities) Test(org.junit.jupiter.api.Test)

Example 5 with Capabilities

use of com.thoughtworks.go.plugin.domain.configrepo.Capabilities in project gocd by gocd.

the class ConfigRepoPluginInfoBuilderTest method shouldBuildPluginInfo.

@Test
public void shouldBuildPluginInfo() throws Exception {
    GoPluginDescriptor descriptor = GoPluginDescriptor.builder().id("plugin1").build();
    when(extension.getPluginSettingsView("plugin1")).thenReturn("some-html");
    when(extension.getCapabilities("plugin1")).thenReturn(new Capabilities(true, true, true, true));
    ConfigRepoPluginInfo pluginInfo = new ConfigRepoPluginInfoBuilder(extension).pluginInfoFor(descriptor);
    List<PluginConfiguration> pluginConfigurations = Arrays.asList(new PluginConfiguration("username", new Metadata(true, false)), new PluginConfiguration("password", new Metadata(true, true)));
    PluginView pluginView = new PluginView("some-html");
    assertThat(pluginInfo.getDescriptor(), is(descriptor));
    assertThat(pluginInfo.getExtensionName(), is("configrepo"));
    assertThat(pluginInfo.getPluginSettings(), is(new PluggableInstanceSettings(pluginConfigurations, pluginView)));
    assertThat(pluginInfo.getCapabilities(), is(new Capabilities(true, true, true, true)));
}
Also used : PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) Capabilities(com.thoughtworks.go.plugin.domain.configrepo.Capabilities) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) PluginView(com.thoughtworks.go.plugin.domain.common.PluginView) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) ConfigRepoPluginInfo(com.thoughtworks.go.plugin.domain.configrepo.ConfigRepoPluginInfo) Test(org.junit.jupiter.api.Test)

Aggregations

Capabilities (com.thoughtworks.go.plugin.domain.configrepo.Capabilities)5 Test (org.junit.jupiter.api.Test)5 Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)3 PluggableInstanceSettings (com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings)3 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)3 ConfigRepoPluginInfo (com.thoughtworks.go.plugin.domain.configrepo.ConfigRepoPluginInfo)3 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)2 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)2 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)2 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)2 GoCipher (com.thoughtworks.go.security.GoCipher)2 ArrayList (java.util.ArrayList)2 PluginSettingsConfiguration (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration)1 PluginView (com.thoughtworks.go.plugin.domain.common.PluginView)1 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)1