use of com.thoughtworks.go.domain.config.ConfigurationValue in project gocd by gocd.
the class CruiseConfigTestBase method shouldAddPackageDefinitionToGivenRepository.
@Test
public void shouldAddPackageDefinitionToGivenRepository() throws Exception {
String repoId = "repo-id";
PackageRepository packageRepository = PackageRepositoryMother.create(repoId, "repo-name", "plugin-id", "1.0", new Configuration());
PackageDefinition existing = PackageDefinitionMother.create("pkg-1", "pkg1-name", new Configuration(), packageRepository);
packageRepository.setPackages(new Packages(existing));
cruiseConfig.setPackageRepositories(new PackageRepositories(packageRepository));
Configuration configuration = new Configuration();
configuration.add(new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("value")));
configuration.add(new ConfigurationProperty(new ConfigurationKey("key-with-no-value"), new ConfigurationValue("")));
PackageDefinition packageDefinition = PackageDefinitionMother.create(null, "pkg2-name", configuration, packageRepository);
cruiseConfig.savePackageDefinition(packageDefinition);
assertThat(cruiseConfig.getPackageRepositories().size(), is(1));
assertThat(cruiseConfig.getPackageRepositories().get(0).getId(), is(repoId));
assertThat(cruiseConfig.getPackageRepositories().get(0).getPackages().size(), is(2));
assertThat(cruiseConfig.getPackageRepositories().get(0).getPackages().get(0).getId(), is(existing.getId()));
PackageDefinition createdPkgDef = cruiseConfig.getPackageRepositories().get(0).getPackages().get(1);
assertThat(createdPkgDef.getId(), is(notNullValue()));
assertThat(createdPkgDef.getConfiguration().getProperty("key"), is(Matchers.notNullValue()));
assertThat(createdPkgDef.getConfiguration().getProperty("key-with-no-value"), is(nullValue()));
}
use of com.thoughtworks.go.domain.config.ConfigurationValue in project gocd by gocd.
the class PluginProfileCommandTest method shouldValidateIfSecurityAuthConfigIdIsNull.
@Test
public void shouldValidateIfSecurityAuthConfigIdIsNull() {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig(null, "some-plugin", new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("value")));
cruiseConfig.server().security().securityAuthConfigs().add(securityAuthConfig);
PluginProfileCommand command = new StubSecurityAuthConfigCommand(goConfigService, securityAuthConfig, currentUser, result);
thrown.expectMessage("some foo object id cannot be null.");
command.isValid(cruiseConfig);
}
use of com.thoughtworks.go.domain.config.ConfigurationValue in project gocd by gocd.
the class ElasticAgentProfileCreateCommandTest method shouldInvokePluginValidationsBeforeSave.
@Test
public void shouldInvokePluginValidationsBeforeSave() throws Exception {
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("key", "error"));
when(extension.validate(eq("aws"), Matchers.<Map<String, String>>any())).thenReturn(validationResult);
ElasticProfile newProfile = new ElasticProfile("foo", "aws", new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("val")));
PluginProfileCommand command = new ElasticAgentProfileCreateCommand(mock(GoConfigService.class), newProfile, extension, null, new HttpLocalizedOperationResult());
BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
thrown.expect(PluginProfileNotFoundException.class);
thrown.expectMessage("Elastic agent profile `foo` does not exist.");
command.isValid(cruiseConfig);
command.update(cruiseConfig);
assertThat(newProfile.first().errors().size(), is(1));
assertThat(newProfile.first().errors().asString(), is("error"));
}
use of com.thoughtworks.go.domain.config.ConfigurationValue 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.config.ConfigurationValue in project gocd by gocd.
the class PluggableTaskServiceTest method shouldPassValidationIfAllRequiredFieldsHaveValues.
@Test
public void shouldPassValidationIfAllRequiredFieldsHaveValues() {
Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
configuration.getProperty("KEY1").setConfigurationValue(new ConfigurationValue("junk"));
PluggableTask modifiedTask = new PluggableTask(new PluginConfiguration(pluginId, "1"), configuration);
ValidationResult validationResult = new ValidationResult();
when(taskExtension.validate(eq(modifiedTask.getPluginConfiguration().getId()), any(TaskConfig.class))).thenReturn(validationResult);
pluggableTaskService.validate(modifiedTask);
final List<ValidationError> validationErrors = validationResult.getErrors();
assertTrue(validationErrors.isEmpty());
}
Aggregations