use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class GoConfigFileHelper method addPackageDefinition.
public void addPackageDefinition(PackageMaterialConfig packageMaterialConfig) {
CruiseConfig config = loadForEdit();
PackageRepository repository = packageMaterialConfig.getPackageDefinition().getRepository();
config.getPackageRepositories().add(repository);
writeConfigFile(config);
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class PackageDefinitionServiceIntegrationTest method setup.
@BeforeEach
public void setup() throws Exception {
cachedGoPartials.clear();
configHelper = new GoConfigFileHelper();
dbHelper.onSetUp();
configHelper.usingCruiseConfigDao(goConfigDao);
configHelper.onSetUp();
goConfigService.forceNotifyListeners();
user = new Username(new CaseInsensitiveString("current"));
final PackageRepository npmRepo = new PackageRepository();
PluginConfiguration pluginConfiguration = new PluginConfiguration();
pluginConfiguration.setId("npm");
pluginConfiguration.setVersion("1");
npmRepo.setPluginConfiguration(pluginConfiguration);
repoId = "repoId";
npmRepo.setId(repoId);
npmRepo.setName(repoId);
Configuration configuration = new Configuration();
configuration.add(new ConfigurationProperty(new ConfigurationKey("PACKAGE_ID"), new ConfigurationValue("prettyjson")));
npmRepo.setConfiguration(configuration);
goConfigService.updateConfig(new UpdateConfigCommand() {
@Override
public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
cruiseConfig.setPackageRepositories(new PackageRepositories(npmRepo));
return cruiseConfig;
}
});
UpdateConfigCommand command = goConfigService.modifyAdminPrivilegesCommand(asList(user.getUsername().toString()), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.add));
goConfigService.updateConfig(command);
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class UpdatePackageConfigCommandTest method shouldContinueWithConfigSaveIfUserIsAdmin.
@Test
public void shouldContinueWithConfigSaveIfUserIsAdmin() {
when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
when(goConfigService.isGroupAdministrator(currentUser.getUsername())).thenReturn(false);
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 UpdatePackageConfigCommandTest method shouldValidateIfPackageNameIsInvalid.
@Test
public void shouldValidateIfPackageNameIsInvalid() throws Exception {
PackageRepository repository = cruiseConfig.getPackageRepositories().find("repoId");
PackageDefinition pkg = new PackageDefinition("Id", "!$#", new Configuration());
pkg.setRepository(repository);
repository.addPackage(pkg);
cruiseConfig.setPackageRepositories(new PackageRepositories(repository));
UpdatePackageConfigCommand command = new UpdatePackageConfigCommand(goConfigService, packageUuid, pkg, currentUser, "md5", this.entityHashingService, result, packageDefinitionService);
command.update(cruiseConfig);
assertFalse(command.isValid(cruiseConfig));
assertThat(pkg.errors().size(), is(1));
assertThat(pkg.errors().firstError(), is("Invalid Package name '!$#'. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters."));
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class UpdatePackageConfigCommandTest method shouldValidateDuplicatePropertiesInConfiguration.
@Test
public void shouldValidateDuplicatePropertiesInConfiguration() throws Exception {
PackageRepository repository = cruiseConfig.getPackageRepositories().find("repoId");
ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("value"));
Configuration configuration = new Configuration();
configuration.add(property);
configuration.add(property);
PackageDefinition pkg = new PackageDefinition("Id", newPackageName, configuration);
pkg.setRepository(repository);
repository.addPackage(pkg);
cruiseConfig.setPackageRepositories(new PackageRepositories(repository));
UpdatePackageConfigCommand command = new UpdatePackageConfigCommand(goConfigService, packageUuid, pkg, currentUser, "md5", this.entityHashingService, result, packageDefinitionService);
command.update(cruiseConfig);
assertFalse(command.isValid(cruiseConfig));
assertThat(pkg.getAllErrors().toString(), containsString("Duplicate key 'key' found for Package 'prettyjson'"));
}
Aggregations