use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class UpdatePackageConfigCommandTest 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));
UpdatePackageConfigCommand command = new UpdatePackageConfigCommand(goConfigService, packageUuid, newPackageDefinition, currentUser, "md5", this.entityHashingService, result, packageDefinitionService);
command.update(cruiseConfig);
assertFalse(command.isValid(cruiseConfig));
assertThat(newPackageDefinition.errors().size(), is(1));
assertThat(newPackageDefinition.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.PackageRepository in project gocd by gocd.
the class UpdatePackageConfigCommandTest method shouldContinueWithConfigSaveIfUserIsGroupAdmin.
@Test
public void shouldContinueWithConfigSaveIfUserIsGroupAdmin() {
when(goConfigService.isUserAdmin(currentUser)).thenReturn(false);
when(goConfigService.isGroupAdministrator(currentUser.getUsername())).thenReturn(true);
when(goConfigService.getConfigForEditing()).thenReturn(cruiseConfig);
when(this.entityHashingService.md5ForEntity(any(PackageDefinition.class))).thenReturn("md5");
newPackageDefinition.setRepository(new PackageRepository(oldPackageDefinition.getRepository().getId(), "name", null, null));
UpdatePackageConfigCommand command = new UpdatePackageConfigCommand(goConfigService, packageUuid, newPackageDefinition, currentUser, "md5", this.entityHashingService, result, packageDefinitionService);
assertThat(command.canContinue(cruiseConfig), is(true));
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class ErrorCollectorTest method shouldCollectErrorsWithLabel.
@Test
public void shouldCollectErrorsWithLabel() throws Exception {
PackageRepository packageRepository = new PackageRepository();
packageRepository.addError("name", "name is mandatory field");
packageRepository.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name"), new ConfigurationValue("value")));
packageRepository.getConfiguration().get(0).getConfigurationKey().addError("name", "url is mandatory field");
HashMap<String, List<String>> errorsMap = new HashMap<>();
ErrorCollector.collectFieldErrors(errorsMap, "package_repository", packageRepository);
List<String> nameErrors = new ArrayList<>();
nameErrors.add("name is mandatory field");
assertThat(errorsMap.get("package_repository[name]"), is(nameErrors));
List<String> urlErrors = new ArrayList<>();
urlErrors.add("url is mandatory field");
assertThat(errorsMap.get("package_repository[configuration][0][configurationKey][name]"), is(urlErrors));
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldUpdateSubjectWhenUpdateCalledOnCommand.
@Test
public void shouldUpdateSubjectWhenUpdateCalledOnCommand() throws Exception {
Username username = new Username(new CaseInsensitiveString("user"));
PackageRepository packageRepository = new PackageRepository();
UpdateConfigFromUI updateCommand = service.getPackageRepositoryUpdateCommand(packageRepository, username);
CruiseConfig cruiseConfig = mock(BasicCruiseConfig.class);
updateCommand.update(cruiseConfig);
verify(cruiseConfig).savePackageRepository(packageRepository);
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldCheckIfUserCanAccessAdminPagesWhileUpdatingPackageRepository.
@Test
public void shouldCheckIfUserCanAccessAdminPagesWhileUpdatingPackageRepository() throws Exception {
Username username = new Username(new CaseInsensitiveString("user"));
when(securityService.canViewAdminPage(username)).thenReturn(false);
UpdateConfigFromUI updateCommand = service.getPackageRepositoryUpdateCommand(new PackageRepository(), username);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
updateCommand.checkPermission(GoConfigMother.configWithPipelines("sample"), result);
assertThat(result.isSuccessful(), is(false));
assertThat(result.httpCode(), is(401));
verify(securityService).canViewAdminPage(username);
}
Aggregations