use of com.thoughtworks.go.domain.config.Configuration in project gocd by gocd.
the class SCMConfigXmlLoaderTest method shouldBeAbleToResolveSecureConfigPropertiesForSCMs.
@Test
public void shouldBeAbleToResolveSecureConfigPropertiesForSCMs() throws Exception {
String encryptedValue = new GoCipher().encrypt("secure-two");
String xml = "<cruise schemaVersion='" + GoConstants.CONFIG_SCHEMA_VERSION + "'>\n" + "<scms>\n" + " <scm id='scm-id' name='name'>\n" + " <pluginConfiguration id='plugin-id' version='1.0'/>\n" + " <configuration>\n" + " <property>\n" + " <key>plain</key>\n" + " <value>value</value>\n" + " </property>\n" + " <property>\n" + " <key>secure-one</key>\n" + " <value>secure-value</value>\n" + " </property>\n" + " <property>\n" + " <key>secure-two</key>\n" + " <encryptedValue>" + encryptedValue + "</encryptedValue>\n" + " </property>\n" + " </configuration>\n" + " </scm>\n" + " </scms>" + "<pipelines group=\"group_name\">\n" + " <pipeline name=\"new_name\">\n" + " <materials>\n" + " <scm ref='scm-id' />\n" + " </materials>\n" + " <stage name=\"stage_name\">\n" + " <jobs>\n" + " <job name=\"job_name\" />\n" + " </jobs>\n" + " </stage>\n" + " </pipeline>\n" + "</pipelines></cruise>";
//meta data of scm
SCMPropertyConfiguration scmConfiguration = new SCMPropertyConfiguration();
scmConfiguration.add(new SCMProperty("plain"));
scmConfiguration.add(new SCMProperty("secure-one").with(SCMConfiguration.SECURE, true));
scmConfiguration.add(new SCMProperty("secure-two").with(SCMConfiguration.SECURE, true));
SCMMetadataStore.getInstance().addMetadataFor("plugin-id", new SCMConfigurations(scmConfiguration), null);
GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(xml);
SCM scmConfig = goConfigHolder.config.getSCMs().first();
PipelineConfig pipelineConfig = goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("new_name"));
PluggableSCMMaterialConfig pluggableSCMMaterialConfig = (PluggableSCMMaterialConfig) pipelineConfig.materialConfigs().get(0);
assertThat(pluggableSCMMaterialConfig.getSCMConfig(), is(scmConfig));
Configuration configuration = pluggableSCMMaterialConfig.getSCMConfig().getConfiguration();
assertThat(configuration.get(0).getConfigurationValue().getValue(), is("value"));
assertThat(configuration.get(1).getEncryptedValue(), is(new GoCipher().encrypt("secure-value")));
assertThat(configuration.get(2).getEncryptedValue(), is(encryptedValue));
}
use of com.thoughtworks.go.domain.config.Configuration in project gocd by gocd.
the class PackageDefinitionTest method shouldNotDisplayEmptyValuesInGetConfigForDisplay.
@Test
public void shouldNotDisplayEmptyValuesInGetConfigForDisplay() throws Exception {
RepositoryMetadataStore.getInstance().addMetadataFor("some-plugin", new PackageConfigurations());
PackageMetadataStore.getInstance().addMetadataFor("some-plugin", new PackageConfigurations());
PackageRepository repository = PackageRepositoryMother.create("repo-id", "repo", "some-plugin", "version", new Configuration(create("rk1", false, "rv1")));
PackageDefinition packageDefinition = PackageDefinitionMother.create("p-id", "name", new Configuration(create("pk1", false, ""), create("pk2", false, "pack_value_2"), create("pk3", false, null)), repository);
packageDefinition.setRepository(repository);
assertThat(packageDefinition.getConfigForDisplay(), is("Repository: [rk1=rv1] - Package: [pk2=pack_value_2]"));
}
use of com.thoughtworks.go.domain.config.Configuration in project gocd by gocd.
the class PackageDefinitionTest method shouldCheckForEqualityOfPackageDefinition.
@Test
public void shouldCheckForEqualityOfPackageDefinition() {
Configuration configuration = new Configuration();
PackageDefinition packageDefinition = new PackageDefinition("id", "name", configuration);
assertThat(packageDefinition, is(new PackageDefinition("id", "name", configuration)));
}
use of com.thoughtworks.go.domain.config.Configuration in project gocd by gocd.
the class PackageDefinitionTest method shouldConvertKeysToLowercaseInGetConfigForDisplay.
@Test
public void shouldConvertKeysToLowercaseInGetConfigForDisplay() throws Exception {
RepositoryMetadataStore.getInstance().addMetadataFor("some-plugin", new PackageConfigurations());
PackageMetadataStore.getInstance().addMetadataFor("some-plugin", new PackageConfigurations());
PackageRepository repository = PackageRepositoryMother.create("repo-id", "repo", "some-plugin", "version", new Configuration(create("rk1", false, "rv1")));
PackageDefinition packageDefinition = PackageDefinitionMother.create("p-id", "name", new Configuration(create("pack_key_1", false, "pack_value_1"), create("PACK_KEY_2", false, "PACK_VALUE_2"), create("pacK_KeY3", false, "pacKValue_3")), repository);
packageDefinition.setRepository(repository);
assertThat(packageDefinition.getConfigForDisplay(), is("Repository: [rk1=rv1] - Package: [pack_key_1=pack_value_1, pack_key_2=PACK_VALUE_2, pack_key3=pacKValue_3]"));
}
use of com.thoughtworks.go.domain.config.Configuration in project gocd by gocd.
the class PackageDefinitionTest method shouldValidateUniqueKeysInConfiguration.
@Test
public void shouldValidateUniqueKeysInConfiguration() {
ConfigurationProperty one = new ConfigurationProperty(new ConfigurationKey("one"), new ConfigurationValue("value1"));
ConfigurationProperty duplicate1 = new ConfigurationProperty(new ConfigurationKey("ONE"), new ConfigurationValue("value2"));
ConfigurationProperty duplicate2 = new ConfigurationProperty(new ConfigurationKey("ONE"), new ConfigurationValue("value3"));
ConfigurationProperty two = new ConfigurationProperty(new ConfigurationKey("two"), new ConfigurationValue());
PackageDefinition packageDefinition = new PackageDefinition();
packageDefinition.setConfiguration(new Configuration(one, duplicate1, duplicate2, two));
packageDefinition.setName("go-server");
packageDefinition.validate(null);
assertThat(one.errors().isEmpty(), is(false));
assertThat(one.errors().getAllOn(ConfigurationProperty.CONFIGURATION_KEY).contains("Duplicate key 'ONE' found for Package 'go-server'"), is(true));
assertThat(duplicate1.errors().isEmpty(), is(false));
assertThat(one.errors().getAllOn(ConfigurationProperty.CONFIGURATION_KEY).contains("Duplicate key 'ONE' found for Package 'go-server'"), is(true));
assertThat(duplicate2.errors().isEmpty(), is(false));
assertThat(one.errors().getAllOn(ConfigurationProperty.CONFIGURATION_KEY).contains("Duplicate key 'ONE' found for Package 'go-server'"), is(true));
assertThat(two.errors().isEmpty(), is(true));
}
Aggregations