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)));
}
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));
}
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"));
}
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)));
}
}
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)));
}
Aggregations