Search in sources :

Example 6 with PackageRepositories

use of com.thoughtworks.go.domain.packagerepository.PackageRepositories in project gocd by gocd.

the class UpdatePackageRepositoryCommand method update.

@Override
public void update(CruiseConfig modifiedConfig) {
    PackageRepository oldRepo = modifiedConfig.getPackageRepositories().find(newRepo.getRepoId());
    this.newRepo.setPackages(oldRepo.getPackages());
    PackageRepositories repositories = modifiedConfig.getPackageRepositories();
    repositories.replace(oldRepo, newRepo);
    modifiedConfig.setPackageRepositories(repositories);
    updatePackageRepositoryConfigurationOnAssociatedPipelines(modifiedConfig);
}
Also used : PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository)

Example 7 with PackageRepositories

use of com.thoughtworks.go.domain.packagerepository.PackageRepositories in project gocd by gocd.

the class PackageDefinitionServiceIntegrationTest method setup.

@BeforeEach
public void setup() throws Exception {
    cachedGoPartials.clear();
    configHelper = new GoConfigFileHelper();
    dbHelper.onSetUp();
    configHelper.usingCruiseConfigDao(goConfigDao);
    configHelper.onSetUp();
    goConfigService.forceNotifyListeners();
    user = new Username(new CaseInsensitiveString("current"));
    final PackageRepository npmRepo = new PackageRepository();
    PluginConfiguration pluginConfiguration = new PluginConfiguration();
    pluginConfiguration.setId("npm");
    pluginConfiguration.setVersion("1");
    npmRepo.setPluginConfiguration(pluginConfiguration);
    repoId = "repoId";
    npmRepo.setId(repoId);
    npmRepo.setName(repoId);
    Configuration configuration = new Configuration();
    configuration.add(new ConfigurationProperty(new ConfigurationKey("PACKAGE_ID"), new ConfigurationValue("prettyjson")));
    npmRepo.setConfiguration(configuration);
    goConfigService.updateConfig(new UpdateConfigCommand() {

        @Override
        public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
            cruiseConfig.setPackageRepositories(new PackageRepositories(npmRepo));
            return cruiseConfig;
        }
    });
    UpdateConfigCommand command = goConfigService.modifyAdminPrivilegesCommand(asList(user.getUsername().toString()), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.add));
    goConfigService.updateConfig(command);
}
Also used : ContextConfiguration(org.springframework.test.context.ContextConfiguration) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Username(com.thoughtworks.go.server.domain.Username) GoConfigFileHelper(com.thoughtworks.go.util.GoConfigFileHelper) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with PackageRepositories

use of com.thoughtworks.go.domain.packagerepository.PackageRepositories in project gocd by gocd.

the class PackageRepositoryServiceIntegrationTest method shouldReturnTheExactLocalizeMessageIfItFailsToDeletePackageRepository.

@Test
public void shouldReturnTheExactLocalizeMessageIfItFailsToDeletePackageRepository() throws Exception {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    String repoId = "npm";
    PackageRepository npmRepo = new PackageRepository();
    npmRepo.setId(repoId);
    goConfigService.getConfigForEditing().setPackageRepositories(new PackageRepositories(npmRepo));
    HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
    expectedResult.forbidden(EntityType.PackageRepository.forbiddenToDelete("npm", "UnauthorizedUser"), forbidden());
    assertThat(goConfigService.getConfigForEditing().getPackageRepositories().size(), is(1));
    assertThat(goConfigService.getConfigForEditing().getPackageRepositories().find(repoId), is(npmRepo));
    service.deleteRepository(new Username("UnauthorizedUser"), npmRepo, result);
    assertThat(result, is(expectedResult));
    assertThat(goConfigService.getConfigForEditing().getPackageRepositories().size(), is(1));
    assertThat(goConfigService.getConfigForEditing().getPackageRepositories().find(repoId), is(npmRepo));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) 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 9 with PackageRepositories

use of com.thoughtworks.go.domain.packagerepository.PackageRepositories in project gocd by gocd.

the class PackageRepositoryServiceIntegrationTest method shouldDeleteTheSpecifiedPackageRepository.

@Test
public void shouldDeleteTheSpecifiedPackageRepository() throws Exception {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    String repoId = "npm";
    PackageRepository npmRepo = new PackageRepository();
    npmRepo.setId(repoId);
    goConfigService.getConfigForEditing().setPackageRepositories(new PackageRepositories(npmRepo));
    assertThat(goConfigService.getConfigForEditing().getPackageRepositories().size(), is(1));
    assertThat(goConfigService.getConfigForEditing().getPackageRepositories().find(repoId), is(npmRepo));
    service.deleteRepository(username, npmRepo, result);
    HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
    expectedResult.setMessage(EntityType.PackageRepository.deleteSuccessful(npmRepo.getId()));
    assertThat(result, is(expectedResult));
    assertThat(goConfigService.getConfigForEditing().getPackageRepositories().size(), is(0));
    assertNull(goConfigService.getConfigForEditing().getPackageRepositories().find(repoId));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Example 10 with PackageRepositories

use of com.thoughtworks.go.domain.packagerepository.PackageRepositories in project gocd by gocd.

the class PackageRepositoryServiceIntegrationTest method shouldReturnTheExactLocalizeMessageIfItFailsToCreatePackageRepository.

@Test
public void shouldReturnTheExactLocalizeMessageIfItFailsToCreatePackageRepository() throws Exception {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    String repoId = "npm";
    PackageRepository npmRepo = new PackageRepository();
    npmRepo.setId(repoId);
    goConfigService.getConfigForEditing().setPackageRepositories(new PackageRepositories(npmRepo));
    HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
    expectedResult.forbidden(EntityType.PackageRepository.forbiddenToEdit("npm", "UnauthorizedUser"), forbidden());
    assertThat(goConfigService.getConfigForEditing().getPackageRepositories().size(), is(1));
    assertThat(goConfigService.getConfigForEditing().getPackageRepositories().find(repoId), is(npmRepo));
    service.createPackageRepository(npmRepo, new Username("UnauthorizedUser"), result);
    assertThat(result, is(expectedResult));
    assertThat(goConfigService.getConfigForEditing().getPackageRepositories().size(), is(1));
    assertThat(goConfigService.getConfigForEditing().getPackageRepositories().find(repoId), is(npmRepo));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) 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)

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