Search in sources :

Example 46 with PackageRepository

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

the class MagicalGoConfigXmlWriterTest method shouldNotAllowMultipleRepositoriesWithSameId.

@Test
public void shouldNotAllowMultipleRepositoriesWithSameId() throws Exception {
    Configuration packageConfiguration = new Configuration(getConfigurationProperty("name", false, "go-agent"));
    Configuration repositoryConfiguration = new Configuration(getConfigurationProperty("url", false, "http://go"));
    PackageRepository packageRepository = createPackageRepository("plugin-id-1", "version", "id", "name1", repositoryConfiguration, new Packages(new PackageDefinition("id", "name", packageConfiguration)));
    PackageRepository anotherPackageRepository = createPackageRepository("plugin-id-2", "version", "id", "name2", repositoryConfiguration, new Packages(new PackageDefinition("id", "name", packageConfiguration)));
    cruiseConfig.setPackageRepositories(new PackageRepositories(packageRepository, anotherPackageRepository));
    try {
        xmlWriter.write(cruiseConfig, output, false);
        fail("should not have allowed two repositories with same id");
    } catch (XsdValidationException e) {
        assertThat(e.getMessage(), anyOf(is("Duplicate unique value [id] declared for identity constraint of element \"repositories\"."), is("Duplicate unique value [id] declared for identity constraint \"uniqueRepositoryId\" of element \"repositories\".")));
    }
}
Also used : XsdValidationException(com.thoughtworks.go.util.XsdValidationException) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Example 47 with PackageRepository

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

the class MagicalGoConfigXmlWriterTest method shouldNotAllowMultiplePackagesWithSameId.

@Test
public void shouldNotAllowMultiplePackagesWithSameId() throws Exception {
    Configuration packageConfiguration = new Configuration(getConfigurationProperty("name", false, "go-agent"));
    Configuration repositoryConfiguration = new Configuration(getConfigurationProperty("url", false, "http://go"));
    PackageRepository packageRepository = createPackageRepository("plugin-id-1", "version", "id1", "name1", repositoryConfiguration, new Packages(new PackageDefinition("id", "name", packageConfiguration)));
    PackageRepository anotherPackageRepository = createPackageRepository("plugin-id-2", "version", "id2", "name2", repositoryConfiguration, new Packages(new PackageDefinition("id", "name", packageConfiguration)));
    cruiseConfig.setPackageRepositories(new PackageRepositories(packageRepository, anotherPackageRepository));
    try {
        xmlWriter.write(cruiseConfig, output, false);
        fail("should not have allowed two package repositories with same id");
    } catch (XsdValidationException e) {
        assertThat(e.getMessage(), anyOf(is("Duplicate unique value [id] declared for identity constraint of element \"cruise\"."), is("Duplicate unique value [id] declared for identity constraint \"uniquePackageId\" of element \"cruise\".")));
    }
}
Also used : XsdValidationException(com.thoughtworks.go.util.XsdValidationException) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Example 48 with PackageRepository

use of com.thoughtworks.go.domain.packagerepository.PackageRepository 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 49 with PackageRepository

use of com.thoughtworks.go.domain.packagerepository.PackageRepository 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 50 with PackageRepository

use of com.thoughtworks.go.domain.packagerepository.PackageRepository 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

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