Search in sources :

Example 96 with Configuration

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

the class SCMTest method shouldCheckEqualityOfSCM.

@Test
public void shouldCheckEqualityOfSCM() {
    Configuration configuration = new Configuration();
    SCM scm = SCMMother.create("id", "name", "plugin-id", "version", configuration);
    assertThat(scm, is(SCMMother.create("id", "name", "plugin-id", "version", configuration)));
}
Also used : 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 97 with Configuration

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

the class SCMTest method shouldCheckForFieldAssignments.

@Test
public void shouldCheckForFieldAssignments() {
    Configuration configuration = new Configuration();
    SCM scm = SCMMother.create("id", "name", "plugin-id", "version", configuration);
    assertThat(scm.getId(), is("id"));
    assertThat(scm.getName(), is("name"));
    assertThat(scm.getPluginConfiguration().getId(), is("plugin-id"));
    assertThat(scm.getPluginConfiguration().getVersion(), is("version"));
    assertThat(scm.getConfiguration().listOfConfigKeys().isEmpty(), is(true));
}
Also used : 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 98 with Configuration

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

the class SCMTest method shouldMakeConfigurationSecureBasedOnMetadata.

@Test
public void shouldMakeConfigurationSecureBasedOnMetadata() throws Exception {
    GoCipher goCipher = new GoCipher();
    //meta data of SCM
    SCMConfigurations scmConfiguration = new SCMConfigurations();
    scmConfiguration.add(new SCMConfiguration("key1").with(SECURE, true));
    scmConfiguration.add(new SCMConfiguration("key2").with(SECURE, false));
    SCMMetadataStore.getInstance().addMetadataFor("plugin-id", scmConfiguration, null);
    /*secure property is set based on metadata*/
    ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher);
    ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher);
    SCM scm = SCMMother.create("scm-id", "scm-name", "plugin-id", "1.0", new Configuration(secureProperty, nonSecureProperty));
    scm.applyPluginMetadata();
    //assert SCM properties
    assertThat(secureProperty.isSecure(), is(true));
    assertThat(secureProperty.getEncryptedConfigurationValue(), is(notNullValue()));
    assertThat(secureProperty.getEncryptedValue(), is(goCipher.encrypt("value1")));
    assertThat(nonSecureProperty.isSecure(), is(false));
    assertThat(nonSecureProperty.getValue(), is("value2"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) GoCipher(com.thoughtworks.go.security.GoCipher) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) 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) SCMConfigurations(com.thoughtworks.go.plugin.access.scm.SCMConfigurations) Test(org.junit.Test)

Example 99 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 100 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)134 Test (org.junit.Test)116 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)95 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)34 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)28 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