Search in sources :

Example 86 with PackageRepository

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");
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) SecretResolutionFailureException(com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Example 87 with PackageRepository

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();
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Example 88 with PackageRepository

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Username(com.thoughtworks.go.server.domain.Username) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Example 89 with PackageRepository

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ContextConfiguration(org.springframework.test.context.ContextConfiguration) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Aggregations

PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)89 Test (org.junit.jupiter.api.Test)46 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)40 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)39 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)23 Packages (com.thoughtworks.go.domain.packagerepository.Packages)13 Username (com.thoughtworks.go.server.domain.Username)13 Test (org.junit.Test)13 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)9 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)7 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)7 BeforeEach (org.junit.jupiter.api.BeforeEach)6 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)5 UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)5 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)5 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)5 XsdValidationException (com.thoughtworks.go.util.XsdValidationException)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)4 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)4