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")));
}
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."));
}
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']"));
}
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));
}
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");
}
Aggregations