Search in sources :

Example 71 with Configuration

use of com.thoughtworks.go.domain.config.Configuration in project gocd by gocd.

the class SCMTest method shouldNotOverwriteValuesIfTheyAreNotAvailableInConfigAttributesMap.

@Test
public void shouldNotOverwriteValuesIfTheyAreNotAvailableInConfigAttributesMap() throws Exception {
    SCMConfigurations scmConfigurations = new SCMConfigurations();
    scmConfigurations.add(new SCMConfiguration("KEY1"));
    scmConfigurations.add(new SCMConfiguration("Key2"));
    SCMPreference scmPreference = mock(SCMPreference.class);
    when(scmPreference.getScmConfigurations()).thenReturn(scmConfigurations);
    SCMMetadataStore.getInstance().setPreferenceFor("plugin-id", scmPreference);
    Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"), ConfigurationPropertyMother.create("Key2"));
    SCM scm = new SCM("scm-id", new PluginConfiguration("plugin-id", "1"), configuration);
    Map<String, String> attributeMap = DataStructureUtils.m("KEY1", "value1");
    scm.setConfigAttributes(attributeMap);
    assertThat(scm.getConfigAsMap().get("KEY1").get(SCM.VALUE_KEY), is("value1"));
    assertThat(scm.getConfigAsMap().get("Key2").get(SCM.VALUE_KEY), is(nullValue()));
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) SCMPreference(com.thoughtworks.go.plugin.access.scm.SCMPreference) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfigurations(com.thoughtworks.go.plugin.access.scm.SCMConfigurations) Test(org.junit.Test)

Example 72 with Configuration

use of com.thoughtworks.go.domain.config.Configuration in project gocd by gocd.

the class SCMTest method shouldIgnoreKeysPresentInConfigAttributesMapButNotPresentInConfigStore.

@Test
public void shouldIgnoreKeysPresentInConfigAttributesMapButNotPresentInConfigStore() throws Exception {
    SCMConfigurations scmConfigurations = new SCMConfigurations();
    scmConfigurations.add(new SCMConfiguration("KEY1"));
    SCMPreference scmPreference = mock(SCMPreference.class);
    when(scmPreference.getScmConfigurations()).thenReturn(scmConfigurations);
    SCMMetadataStore.getInstance().setPreferenceFor("plugin-id", scmPreference);
    Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
    SCM scm = new SCM("scm-id", new PluginConfiguration("plugin-id", "1"), configuration);
    Map<String, String> attributeMap = DataStructureUtils.m("KEY1", "value1", "Key2", "value2");
    scm.setConfigAttributes(attributeMap);
    assertThat(scm.getConfigAsMap().get("KEY1").get(SCM.VALUE_KEY), is("value1"));
    assertFalse(scm.getConfigAsMap().containsKey("Key2"));
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) SCMPreference(com.thoughtworks.go.plugin.access.scm.SCMPreference) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfigurations(com.thoughtworks.go.plugin.access.scm.SCMConfigurations) Test(org.junit.Test)

Example 73 with Configuration

use of com.thoughtworks.go.domain.config.Configuration in project gocd by gocd.

the class SCMTest method shouldGetConfigAsMap.

@Test
public void shouldGetConfigAsMap() throws Exception {
    PluginConfiguration pluginConfiguration = new PluginConfiguration("test-plugin-id", "13.4");
    GoCipher cipher = new GoCipher();
    List<String> keys = Arrays.asList("Avengers 1", "Avengers 2", "Avengers 3", "Avengers 4");
    List<String> values = Arrays.asList("Iron man", "Hulk", "Thor", "Captain America");
    Configuration configuration = new Configuration(new ConfigurationProperty(new ConfigurationKey(keys.get(0)), new ConfigurationValue(values.get(0))), new ConfigurationProperty(new ConfigurationKey(keys.get(1)), new ConfigurationValue(values.get(1))), new ConfigurationProperty(new ConfigurationKey(keys.get(2)), new ConfigurationValue(values.get(2))), new ConfigurationProperty(new ConfigurationKey(keys.get(3)), new ConfigurationValue(values.get(3)), new EncryptedConfigurationValue(cipher.encrypt(values.get(3))), cipher));
    SCM scm = new SCM("scm-id", pluginConfiguration, configuration);
    Map<String, Map<String, String>> configMap = scm.getConfigAsMap();
    assertThat(configMap.keySet().size(), is(keys.size()));
    assertThat(configMap.values().size(), is(values.size()));
    assertThat(configMap.keySet().containsAll(keys), is(true));
    for (int i = 0; i < keys.size(); i++) {
        assertThat(configMap.get(keys.get(i)).get(SCM.VALUE_KEY), is(values.get(i)));
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) GoCipher(com.thoughtworks.go.security.GoCipher) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) Test(org.junit.Test)

Example 74 with Configuration

use of com.thoughtworks.go.domain.config.Configuration in project gocd by gocd.

the class SCMTest method shouldAddConfigurationPropertiesForAnyPlugin.

@Test
public void shouldAddConfigurationPropertiesForAnyPlugin() {
    List<ConfigurationProperty> configurationProperties = Arrays.asList(ConfigurationPropertyMother.create("key", "value", "encValue"));
    Configuration configuration = new Configuration();
    SCM scm = SCMMother.create("id", "name", "does_not_exist", "1.1", configuration);
    assertThat(configuration.size(), is(0));
    scm.addConfigurations(configurationProperties);
    assertThat(configuration.size(), is(1));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) Test(org.junit.Test)

Example 75 with Configuration

use of com.thoughtworks.go.domain.config.Configuration in project gocd by gocd.

the class SCMsTest method shouldFailValidationIfMaterialWithDuplicateFingerprintIsFound.

@Test
public void shouldFailValidationIfMaterialWithDuplicateFingerprintIsFound() {
    String pluginId = "plugin-id";
    SCMPropertyConfiguration scmConfiguration = new SCMPropertyConfiguration();
    scmConfiguration.add(new SCMProperty("k1"));
    scmConfiguration.add(new SCMProperty("k2").with(REQUIRED, false).with(PART_OF_IDENTITY, false));
    SCMMetadataStore.getInstance().addMetadataFor(pluginId, new SCMConfigurations(scmConfiguration), null);
    SCM scm1 = SCMMother.create("1", "scm1", pluginId, "1.0", new Configuration(create("k1", false, "v1")));
    SCM scm2 = SCMMother.create("2", "scm2", pluginId, "1.0", new Configuration(create("k1", false, "v2")));
    SCM scm3 = SCMMother.create("3", "scm3", pluginId, "1.0", new Configuration(create("k1", false, "v1")));
    SCM scm4 = SCMMother.create("4", "scm4", pluginId, "1.0", new Configuration(create("k1", false, "V1")));
    SCM scm5 = SCMMother.create("5", "scm5", pluginId, "1.0", new Configuration(create("k1", false, "v1"), create("k2", false, "v2")));
    SCMs scms = new SCMs(scm1, scm2, scm3, scm4, scm5);
    scms.validate(null);
    assertThat(scm2.getFingerprint().equals(scm1.getFingerprint()), is(false));
    assertThat(scm3.getFingerprint().equals(scm1.getFingerprint()), is(true));
    assertThat(scm4.getFingerprint().equals(scm1.getFingerprint()), is(false));
    assertThat(scm5.getFingerprint().equals(scm1.getFingerprint()), is(true));
    String expectedErrorMessage = "Cannot save SCM, found duplicate SCMs. scm1, scm3, scm5";
    assertThat(scm1.errors().getAllOn(SCM.SCM_ID), is(asList(expectedErrorMessage)));
    assertThat(scm2.errors().getAllOn(SCM.SCM_ID), is(nullValue()));
    assertThat(scm3.errors().getAllOn(SCM.SCM_ID), is(asList(expectedErrorMessage)));
    assertThat(scm4.errors().getAllOn(SCM.SCM_ID), is(nullValue()));
    assertThat(scm5.errors().getAllOn(SCM.SCM_ID), is(asList(expectedErrorMessage)));
}
Also used : SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) Configuration(com.thoughtworks.go.domain.config.Configuration) SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) SCMConfigurations(com.thoughtworks.go.plugin.access.scm.SCMConfigurations) SCMProperty(com.thoughtworks.go.plugin.access.scm.SCMProperty) Test(org.junit.Test)

Aggregations

Configuration (com.thoughtworks.go.domain.config.Configuration)136 Test (org.junit.Test)114 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)97 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)34 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)29 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)20 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)18 SCM (com.thoughtworks.go.domain.scm.SCM)17 SCMConfiguration (com.thoughtworks.go.plugin.access.scm.SCMConfiguration)17 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)17 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)16 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)15 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)14 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)13 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)12 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)12 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)11 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)11 SCMConfigurations (com.thoughtworks.go.plugin.access.scm.SCMConfigurations)10 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)9