use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class CreatePackageConfigCommandTest method shouldValidateDuplicateIdentity.
@Test
public void shouldValidateDuplicateIdentity() throws Exception {
PackageRepository repository = cruiseConfig.getPackageRepositories().find(repoId);
PackageDefinition pkg = new PackageDefinition("Id", "name", configuration);
pkg.setRepository(repository);
repository.addPackage(pkg);
cruiseConfig.setPackageRepositories(new PackageRepositories(repository));
CreatePackageConfigCommand command = new CreatePackageConfigCommand(goConfigService, packageDefinition, repoId, currentUser, result, packageDefinitionService);
command.update(cruiseConfig);
assertFalse(command.isValid(cruiseConfig));
assertThat(packageDefinition.errors().size(), is(1));
assertThat(packageDefinition.errors().firstError(), is("Cannot save package or repo, found duplicate packages. [Repo Name: 'repoName', Package Name: 'name'], [Repo Name: 'repoName', Package Name: 'prettyjson']"));
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class DeletePackageConfigCommandTest method setup.
@BeforeEach
public void setup() throws Exception {
currentUser = new Username(new CaseInsensitiveString("user"));
cruiseConfig = new GoConfigMother().defaultCruiseConfig();
packageUuid = "random-uuid";
configuration = new Configuration(new ConfigurationProperty(new ConfigurationKey("PACKAGE_ID"), new ConfigurationValue("prettyjson")));
packageDefinition = new PackageDefinition(packageUuid, "prettyjson", configuration);
result = new HttpLocalizedOperationResult();
PackageRepositories repositories = cruiseConfig.getPackageRepositories();
PackageRepository repository = new PackageRepository();
repository.addPackage(packageDefinition);
repositories.add(repository);
cruiseConfig.setPackageRepositories(repositories);
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class GoConfigMother method configWithPackageRepo.
public static CruiseConfig configWithPackageRepo(String... ids) throws Exception {
final CruiseConfig config = new BasicCruiseConfig();
PackageConfigurations configuration = new PackageConfigurations();
configuration.addConfiguration(new PackageConfiguration("key1"));
configuration.addConfiguration(new PackageConfiguration("key2").with(PackageConfiguration.SECURE, true));
RepositoryMetadataStore.getInstance().addMetadataFor("plugin-1", configuration);
for (String id : ids) {
PackageRepository packageRepository = new PackageRepository();
packageRepository.setId(id);
packageRepository.setName("name" + id);
packageRepository.setPluginConfiguration(new PluginConfiguration("plugin-1", "1.0.0"));
packageRepository.setPackages(new Packages(PackageDefinitionMother.create(id + "-pkg-1", packageRepository), PackageDefinitionMother.create(id + "-pkg-2", packageRepository)));
GoCipher cipher = new GoCipher();
ConfigurationProperty p1 = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"));
ConfigurationProperty p2 = new ConfigurationProperty(new ConfigurationKey("key2"), null, new EncryptedConfigurationValue(cipher.encrypt("value2")), cipher);
packageRepository.setConfiguration(new Configuration(p1, p2));
config.setPackageRepositories(new PackageRepositories(packageRepository));
}
return config;
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class DeletePackageConfigCommand method update.
@Override
public void update(CruiseConfig modifiedConfig) {
PackageRepositories repositories = modifiedConfig.getPackageRepositories();
PackageRepository packageRepository = repositories.findPackageRepositoryHaving(this.packageDefinition.getId());
packageRepository.removePackage(this.packageDefinition.getId());
modifiedConfig.setPackageRepositories(repositories);
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class PackageConfigCommand method isValid.
public boolean isValid(CruiseConfig preprocessedConfig, String repositoryId) {
PackageRepositories packageRepositories = preprocessedConfig.getPackageRepositories();
PackageRepository repository = packageRepositories.find(repositoryId);
Packages packages = repository.getPackages();
preprocessedPackageDefinition = packages.find(this.packageDefinition.getId());
preprocessedPackageDefinition.validate(null);
if (preprocessedPackageDefinition.getAllErrors().isEmpty()) {
packageRepositories.validate(null);
packages.validate(null);
packageDefinitionService.validatePackageConfiguration(preprocessedPackageDefinition);
BasicCruiseConfig.copyErrors(preprocessedPackageDefinition, packageDefinition);
return preprocessedPackageDefinition.getAllErrors().isEmpty() && result.isSuccessful();
}
BasicCruiseConfig.copyErrors(preprocessedPackageDefinition, packageDefinition);
return false;
}
Aggregations