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));
}
use of com.thoughtworks.go.domain.config.Configuration in project gocd by gocd.
the class PackageDefinitionTest method shouldAddFingerprintFieldErrorWhenPackageDefinitionWithSameFingerprintExist.
@Test
public void shouldAddFingerprintFieldErrorWhenPackageDefinitionWithSameFingerprintExist() throws Exception {
String expectedErrorMessage = "Cannot save package or repo, found duplicate packages. [Repo Name: 'repo-repo1', Package Name: 'pkg1'], [Repo Name: 'repo-repo1', Package Name: 'pkg3']";
PackageRepository repository = PackageRepositoryMother.create("repo1");
PackageDefinition definition1 = PackageDefinitionMother.create("1", "pkg1", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1"))), repository);
PackageDefinition definition2 = PackageDefinitionMother.create("2", "pkg2", new Configuration(new ConfigurationProperty(new ConfigurationKey("k2"), new ConfigurationValue("v2"))), repository);
PackageDefinition definition3 = PackageDefinitionMother.create("3", "pkg3", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1"))), repository);
HashMap<String, Packages> map = new HashMap<>();
map.put(definition1.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER), new Packages(definition1, definition3));
map.put(definition2.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER), new Packages(definition2));
definition1.validateFingerprintUniqueness(map);
definition2.validateFingerprintUniqueness(map);
definition3.validateFingerprintUniqueness(map);
assertThat(definition1.errors().getAllOn(PackageDefinition.ID), is(asList(expectedErrorMessage)));
assertThat(definition3.errors().getAllOn(PackageDefinition.ID), is(asList(expectedErrorMessage)));
assertThat(definition2.errors().getAllOn(PackageDefinition.ID), is(nullValue()));
}
use of com.thoughtworks.go.domain.config.Configuration in project gocd by gocd.
the class PackageRepositoriesTest method shouldFailValidationIfMaterialWithDuplicateFingerprintIsFound.
@Test
public void shouldFailValidationIfMaterialWithDuplicateFingerprintIsFound() {
com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration packageConfiguration = new com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration();
packageConfiguration.add(new PackageMaterialProperty("k1"));
packageConfiguration.add(new PackageMaterialProperty("k2").with(PART_OF_IDENTITY, false));
PackageMetadataStore.getInstance().addMetadataFor("plugin", new PackageConfigurations(packageConfiguration));
String expectedErrorMessage = "Cannot save package or repo, found duplicate packages. [Repo Name: 'repo-repo1', Package Name: 'pkg1'], [Repo Name: 'repo-repo1', Package Name: 'pkg3'], [Repo Name: 'repo-repo1', Package Name: 'pkg5']";
PackageRepository repository = PackageRepositoryMother.create("repo1");
PackageDefinition definition1 = PackageDefinitionMother.create("1", "pkg1", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1"))), repository);
PackageDefinition definition2 = PackageDefinitionMother.create("2", "pkg2", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v2"))), repository);
PackageDefinition definition3 = PackageDefinitionMother.create("3", "pkg3", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1"))), repository);
PackageDefinition definition4 = PackageDefinitionMother.create("4", "pkg4", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("V1"))), repository);
PackageDefinition definition5 = PackageDefinitionMother.create("5", "pkg5", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1")), new ConfigurationProperty(new ConfigurationKey("k2"), new ConfigurationValue("v2"))), repository);
repository.setPackages(new Packages(definition1, definition2, definition3, definition4, definition5));
PackageRepositories packageRepositories = new PackageRepositories(repository);
packageRepositories.validate(null);
assertThat(definition1.errors().getAllOn(PackageDefinition.ID), is(asList(expectedErrorMessage)));
assertThat(definition3.errors().getAllOn(PackageDefinition.ID), is(asList(expectedErrorMessage)));
assertThat(definition3.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER).equals(definition1.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER)), is(true));
assertThat(definition5.errors().getAllOn(PackageDefinition.ID), is(asList(expectedErrorMessage)));
assertThat(definition5.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER).equals(definition1.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER)), is(true));
assertThat(definition2.errors().getAllOn(PackageDefinition.ID), is(nullValue()));
assertThat(definition2.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER).equals(definition1.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER)), is(false));
assertThat(definition4.errors().getAllOn(PackageDefinition.ID), is(nullValue()));
assertThat(definition4.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER).equals(definition1.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER)), is(false));
}
use of com.thoughtworks.go.domain.config.Configuration in project gocd by gocd.
the class PackageRepositoryTest method shouldSetRepositoryOnAllAssociatedPackages.
@Test
public void shouldSetRepositoryOnAllAssociatedPackages() {
Configuration configuration = new Configuration();
PackageDefinition packageDefinition = new PackageDefinition();
PackageRepository packageRepository = createPackageRepository("plugin-id", "version", "id", "name", configuration, new Packages(packageDefinition));
packageRepository.setRepositoryReferenceOnPackages();
assertThat(packageDefinition.getRepository(), is(packageRepository));
}
use of com.thoughtworks.go.domain.config.Configuration in project gocd by gocd.
the class PackageRepositoryTest method shouldCheckForFieldAssignments.
@Test
public void shouldCheckForFieldAssignments() {
Configuration configuration = new Configuration();
Packages packages = new Packages(new PackageDefinition());
PackageRepository packageRepository = createPackageRepository("plugin-id", "version", "id", "name", configuration, packages);
assertThat(packageRepository.getPluginConfiguration().getId(), is("plugin-id"));
assertThat(packageRepository.getPluginConfiguration().getVersion(), is("version"));
assertThat(packageRepository.getId(), is("id"));
assertThat(packageRepository.getName(), is("name"));
}
Aggregations