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 PackageDefinitionTest method shouldNotConsiderPropertiesMarkedAsNotPartOfIdentity_GetFingerprint.
@Test
public void shouldNotConsiderPropertiesMarkedAsNotPartOfIdentity_GetFingerprint() {
String pluginId = "plugin-id";
PackageConfigurations repositoryConfigurations = new PackageConfigurations();
repositoryConfigurations.add(new PackageConfiguration("rk1", "rv1").with(PackageConfiguration.PART_OF_IDENTITY, true));
repositoryConfigurations.add(new PackageConfiguration("rk2", "rv2").with(PackageConfiguration.PART_OF_IDENTITY, false));
RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, repositoryConfigurations);
PackageConfigurations packageConfigurations = new PackageConfigurations();
packageConfigurations.add(new PackageConfiguration("pk1", "pv1").with(PackageConfiguration.PART_OF_IDENTITY, false));
packageConfigurations.add(new PackageConfiguration("pk2", "pv2").with(PackageConfiguration.PART_OF_IDENTITY, true));
PackageMetadataStore.getInstance().addMetadataFor(pluginId, packageConfigurations);
PackageRepository repository = PackageRepositoryMother.create("repo-id", "repo", pluginId, "version", new Configuration(create("rk1", false, "rv1"), create("rk2", false, "rv2")));
PackageDefinition packageDefinition = PackageDefinitionMother.create("p-id", "name", new Configuration(create("pk1", false, "pv1"), create("pk2", false, "pv2")), repository);
String fingerprint = packageDefinition.getFingerprint(AbstractMaterial.FINGERPRINT_DELIMITER);
assertThat(fingerprint, is(CachedDigestUtils.sha256Hex("plugin-id=plugin-id<|>pk2=pv2<|>rk1=rv1")));
}
use of com.thoughtworks.go.domain.config.Configuration in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method shouldSavePackageMaterialInstance.
@Test
public void shouldSavePackageMaterialInstance() {
PackageMaterial material = new PackageMaterial();
PackageRepository repository = PackageRepositoryMother.create("repo-id", "repo", "pluginid", "version", new Configuration(ConfigurationPropertyMother.create("k1", false, "v1")));
material.setPackageDefinition(PackageDefinitionMother.create("p-id", "name", new Configuration(ConfigurationPropertyMother.create("k2", false, "v2")), repository));
PackageMaterialInstance savedMaterialInstance = (PackageMaterialInstance) repo.findOrCreateFrom(material);
assertThat(savedMaterialInstance.getId() > 0, is(true));
assertThat(savedMaterialInstance.getFingerprint(), is(material.getFingerprint()));
assertThat(JsonHelper.fromJson(savedMaterialInstance.getConfiguration(), PackageMaterial.class).getPackageDefinition().getConfiguration(), is(material.getPackageDefinition().getConfiguration()));
assertThat(JsonHelper.fromJson(savedMaterialInstance.getConfiguration(), PackageMaterial.class).getPackageDefinition().getRepository().getPluginConfiguration().getId(), is(material.getPackageDefinition().getRepository().getPluginConfiguration().getId()));
assertThat(JsonHelper.fromJson(savedMaterialInstance.getConfiguration(), PackageMaterial.class).getPackageDefinition().getRepository().getConfiguration(), is(material.getPackageDefinition().getRepository().getConfiguration()));
}
use of com.thoughtworks.go.domain.config.Configuration in project gocd by gocd.
the class ConfigConverterTest method shouldConvertPackageMaterial.
@Test
public void shouldConvertPackageMaterial() {
PackageRepositories repositories = new PackageRepositories();
PackageRepository packageRepository = new PackageRepository();
PackageDefinition definition = new PackageDefinition("package-id", "n", new Configuration());
packageRepository.addPackage(definition);
repositories.add(packageRepository);
BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
cruiseConfig.setPackageRepositories(repositories);
when(cachedGoConfig.currentConfig()).thenReturn(cruiseConfig);
CRPackageMaterial crPackageMaterial = new CRPackageMaterial("name", "package-id");
PackageMaterialConfig packageMaterialConfig = (PackageMaterialConfig) configConverter.toMaterialConfig(crPackageMaterial, context);
assertThat(packageMaterialConfig.getName().toLower(), is("name"));
assertThat(packageMaterialConfig.getPackageId(), is("package-id"));
assertThat(packageMaterialConfig.getPackageDefinition(), is(definition));
}
use of com.thoughtworks.go.domain.config.Configuration in project gocd by gocd.
the class PluggableTaskTest method shouldReturnFalseWhenPluginConfigurationForTwoPluggableTasksIsDifferent.
@Test
public void shouldReturnFalseWhenPluginConfigurationForTwoPluggableTasksIsDifferent() {
PluginConfiguration pluginConfiguration1 = new PluginConfiguration("test-plugin-1", "1.0");
PluginConfiguration pluginConfiguration2 = new PluginConfiguration("test-plugin-2", "1.0");
PluggableTask pluggableTask1 = new PluggableTask(pluginConfiguration1, new Configuration());
PluggableTask pluggableTask2 = new PluggableTask(pluginConfiguration2, new Configuration());
assertFalse(pluggableTask1.hasSameTypeAs(pluggableTask2));
}
Aggregations