use of com.thoughtworks.go.domain.packagerepository.PackageRepositories in project gocd by gocd.
the class PackageRepositoryServiceIntegrationTest method shouldReturnTheExactLocalizeMessageIfItFailsToUpdatePackageRepository.
@Test
public void shouldReturnTheExactLocalizeMessageIfItFailsToUpdatePackageRepository() throws Exception {
HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
expectedResult.forbidden(EntityType.PackageRepository.forbiddenToEdit("npm.org", "UnauthorizedUser"), forbidden());
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
String oldRepoId = "npmOrg";
String newRepoId = "npm.org";
PackageRepository oldPackageRepo = new PackageRepository();
PackageRepository newPackageRepo = new PackageRepository();
PluginConfiguration pluginConfiguration = new PluginConfiguration();
pluginConfiguration.setId("npm");
oldPackageRepo.setPluginConfiguration(pluginConfiguration);
oldPackageRepo.setId(oldRepoId);
oldPackageRepo.setName(oldRepoId);
newPackageRepo.setPluginConfiguration(pluginConfiguration);
newPackageRepo.setId(newRepoId);
newPackageRepo.setName(newRepoId);
Configuration configuration = new Configuration();
configuration.add(new ConfigurationProperty(new ConfigurationKey("foo"), new ConfigurationValue("bar")));
oldPackageRepo.setConfiguration(configuration);
newPackageRepo.setConfiguration(configuration);
goConfigService.getConfigForEditing().setPackageRepositories(new PackageRepositories(oldPackageRepo));
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().size(), is(1));
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().find(oldRepoId), is(oldPackageRepo));
assertNull(goConfigService.getConfigForEditing().getPackageRepositories().find(newRepoId));
service.updatePackageRepository(newPackageRepo, new Username("UnauthorizedUser"), "md5", result, oldRepoId);
assertThat(result, is(expectedResult));
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().size(), is(1));
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().find(oldRepoId), is(oldPackageRepo));
assertNull(goConfigService.getConfigForEditing().getPackageRepositories().find(newRepoId));
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepositories in project gocd by gocd.
the class PackageDefinitionServiceIntegrationTest method shouldDeletePackageDefinition.
@Test
public void shouldDeletePackageDefinition() throws Exception {
String packageUuid = "random-uuid";
String packageName = "prettyjson";
Configuration configuration = new Configuration();
configuration.add(new ConfigurationProperty(new ConfigurationKey("PACKAGE_ID"), new ConfigurationValue("prettyjson")));
PackageDefinition packageDefinition = new PackageDefinition(packageUuid, packageName, configuration);
PackageRepositories repositories = goConfigService.getConfigForEditing().getPackageRepositories();
PackageRepository repository = repositories.find(repoId);
repository.addPackage(packageDefinition);
repositories.removePackageRepository(repoId);
repositories.add(repository);
goConfigService.getConfigForEditing().setPackageRepositories(repositories);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
expectedResult.setMessage(EntityType.PackageDefinition.deleteSuccessful(packageDefinition.getId()));
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().find(repoId).getPackages().find(packageUuid), is(packageDefinition));
service.deletePackage(packageDefinition, user, result);
assertThat(result, is(expectedResult));
assertNull(goConfigService.getConfigForEditing().getPackageRepositories().find(repoId).getPackages().find(packageUuid));
}
Aggregations