Search in sources :

Example 1 with PackageRepository

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

Example 2 with PackageRepository

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));
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.Test)

Example 3 with PackageRepository

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));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with PackageRepository

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);
}
Also used : Username(com.thoughtworks.go.server.domain.Username) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) UpdateConfigFromUI(com.thoughtworks.go.config.update.UpdateConfigFromUI) Test(org.junit.Test)

Example 5 with 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);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) UpdateConfigFromUI(com.thoughtworks.go.config.update.UpdateConfigFromUI) Test(org.junit.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