Search in sources :

Example 51 with PackageRepositories

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));
}
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 52 with PackageRepositories

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));
}
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

PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)52 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)40 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)29 Test (org.junit.jupiter.api.Test)29 Packages (com.thoughtworks.go.domain.packagerepository.Packages)14 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)9 Test (org.junit.Test)8 Username (com.thoughtworks.go.server.domain.Username)7 BeforeEach (org.junit.jupiter.api.BeforeEach)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)4 XsdValidationException (com.thoughtworks.go.util.XsdValidationException)4 ArrayList (java.util.ArrayList)4 Arrays.asList (java.util.Arrays.asList)4 List (java.util.List)4 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)3 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)3 ContextConfiguration (org.springframework.test.context.ContextConfiguration)3 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)2 GoCipher (com.thoughtworks.go.security.GoCipher)2