use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldSetResultAsUnprocessableEntityIfSecretResolutionFailsForCheckConnection.
@Test
void shouldSetResultAsUnprocessableEntityIfSecretResolutionFailsForCheckConnection() {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
doThrow(new SecretResolutionFailureException("some secret resolution message")).when(secretParamResolver).resolve(any(PackageRepository.class));
service.checkConnection(packageRepository("some-plugin"), result);
assertThat(result.isSuccessful()).isFalse();
assertThat(result.httpCode()).isEqualTo(HttpStatus.SC_UNPROCESSABLE_ENTITY);
assertThat(result.message()).isEqualTo("Could not connect to package repository. Reason(s): some secret resolution message");
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class GoConfigMigrationIntegrationTest method shouldAddAttributeAutoUpdateOnPackage_AsPartOfMigration68.
@Test
public void shouldAddAttributeAutoUpdateOnPackage_AsPartOfMigration68() throws Exception {
String configString = "<cruise schemaVersion='67'>" + "<repositories>" + " <repository id='2ef830d7-dd66-42d6-b393-64a84646e557' name='GoYumRepo'>" + " <pluginConfiguration id='yum' version='1' />" + " <configuration>" + " <property>" + " <key>REPO_URL</key>" + " <value>http://random-yum-repo/go/yum/no-arch</value>" + " </property>" + " </configuration>" + " <packages>" + " <package id='88a3beca-cbe2-4c4d-9744-aa0cda3f371c' name='1'>" + " <configuration>" + " <property>" + " <key>REPO_URL</key>" + " <value>http://random-yum-repo/go/yum/no-arch</value>" + " </property>" + " </configuration>" + " </package>" + " </packages>" + " </repository>" + "</repositories>" + "</cruise>";
String migratedContent = migrateXmlString(configString, 67);
GoConfigHolder holder = loader.loadConfigHolder(migratedContent);
PackageRepository packageRepository = holder.config.getPackageRepositories().find("2ef830d7-dd66-42d6-b393-64a84646e557");
PackageDefinition aPackage = packageRepository.findPackage("88a3beca-cbe2-4c4d-9744-aa0cda3f371c");
assertThat(aPackage.isAutoUpdate()).isTrue();
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository 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.PackageRepository 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