Search in sources :

Example 36 with PackageRepositories

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

the class CreatePackageConfigCommandTest method shouldValidateIfPackageNameIsNull.

@Test
public void shouldValidateIfPackageNameIsNull() {
    PackageDefinition pkg = new PackageDefinition("Id", null, new Configuration());
    PackageRepository repository = new PackageRepository(repoId, null, null, null);
    repository.addPackage(pkg);
    cruiseConfig.setPackageRepositories(new PackageRepositories(repository));
    CreatePackageConfigCommand command = new CreatePackageConfigCommand(goConfigService, pkg, repoId, currentUser, result, packageDefinitionService);
    assertFalse(command.isValid(cruiseConfig));
    assertThat(pkg.errors().getAllOn("name"), is(Arrays.asList("Package name is mandatory")));
}
Also used : 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)

Example 37 with PackageRepositories

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

the class CreatePackageConfigCommandTest method shouldValidateDuplicatePackageName.

@Test
public void shouldValidateDuplicatePackageName() throws Exception {
    PackageRepository repository = cruiseConfig.getPackageRepositories().find(repoId);
    PackageDefinition pkg = new PackageDefinition("Id", "prettyjson", new Configuration());
    pkg.setRepository(repository);
    repository.addPackage(pkg);
    cruiseConfig.setPackageRepositories(new PackageRepositories(repository));
    CreatePackageConfigCommand command = new CreatePackageConfigCommand(goConfigService, packageDefinition, repoId, currentUser, result, packageDefinitionService);
    command.update(cruiseConfig);
    assertFalse(command.isValid(cruiseConfig));
    assertThat(packageDefinition.errors().size(), is(1));
    assertThat(packageDefinition.errors().firstError(), is("You have defined multiple packages called 'prettyjson'. Package names are case-insensitive and must be unique within a repository."));
}
Also used : 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)

Example 38 with PackageRepositories

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

the class CreatePackageConfigCommandTest method shouldValidateDuplicateIdentity.

@Test
public void shouldValidateDuplicateIdentity() throws Exception {
    PackageRepository repository = cruiseConfig.getPackageRepositories().find(repoId);
    PackageDefinition pkg = new PackageDefinition("Id", "name", configuration);
    pkg.setRepository(repository);
    repository.addPackage(pkg);
    cruiseConfig.setPackageRepositories(new PackageRepositories(repository));
    CreatePackageConfigCommand command = new CreatePackageConfigCommand(goConfigService, packageDefinition, repoId, currentUser, result, packageDefinitionService);
    command.update(cruiseConfig);
    assertFalse(command.isValid(cruiseConfig));
    assertThat(packageDefinition.errors().size(), is(1));
    assertThat(packageDefinition.errors().firstError(), is("Cannot save package or repo, found duplicate packages. [Repo Name: 'repoName', Package Name: 'name'], [Repo Name: 'repoName', Package Name: 'prettyjson']"));
}
Also used : 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)

Example 39 with PackageRepositories

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

the class CreatePackageConfigCommandTest method shouldNotContinueIfTheRepositoryWithSpecifiedRepoIdDoesNotexist.

@Test
public void shouldNotContinueIfTheRepositoryWithSpecifiedRepoIdDoesNotexist() throws Exception {
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
    cruiseConfig.setPackageRepositories(new PackageRepositories());
    CreatePackageConfigCommand command = new CreatePackageConfigCommand(goConfigService, packageDefinition, repoId, currentUser, result, packageDefinitionService);
    HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
    expectedResult.unprocessableEntity(EntityType.PackageRepository.notFoundMessage(repoId));
    assertThat(command.canContinue(cruiseConfig), is(false));
    assertThat(result, is(expectedResult));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) Test(org.junit.jupiter.api.Test)

Example 40 with PackageRepositories

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

the class ConfigSaveValidationContextTest method shouldCheckForExistenceOfPackage.

@Test
void shouldCheckForExistenceOfPackage() throws Exception {
    BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
    cruiseConfig.setPackageRepositories(new PackageRepositories(PackageRepositoryMother.create("repo-id")));
    cruiseConfig.getPackageRepositories().find("repo-id").setPackages(new Packages(PackageDefinitionMother.create("package-id")));
    ValidationContext context = ConfigSaveValidationContext.forChain(cruiseConfig);
    assertThat(context.findPackageById("package-id").getId()).isEqualTo("repo-id");
}
Also used : Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) RulesValidationContext(com.thoughtworks.go.config.rules.RulesValidationContext) 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