use of com.thoughtworks.go.domain.config.ConfigurationProperty 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.ConfigurationProperty 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.ConfigurationProperty 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.ConfigurationProperty in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method shouldSavePluggableSCMMaterialInstance.
@Test
public void shouldSavePluggableSCMMaterialInstance() {
PluggableSCMMaterial material = new PluggableSCMMaterial();
ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1");
ConfigurationProperty k2 = ConfigurationPropertyMother.create("k2", true, "v2");
material.setSCMConfig(SCMMother.create("scm-id", "scm-name", "plugin-id", "1.0", new Configuration(k1, k2)));
PluggableSCMMaterialInstance savedMaterialInstance = (PluggableSCMMaterialInstance) repo.findOrCreateFrom(material);
assertThat(savedMaterialInstance.getId() > 0, is(true));
assertThat(savedMaterialInstance.getFingerprint(), is(material.getFingerprint()));
assertThat(JsonHelper.fromJson(savedMaterialInstance.getConfiguration(), PluggableSCMMaterial.class).getScmConfig().getConfiguration(), is(material.getScmConfig().getConfiguration()));
assertThat(JsonHelper.fromJson(savedMaterialInstance.getConfiguration(), PluggableSCMMaterial.class).getScmConfig().getPluginConfiguration().getId(), is(material.getScmConfig().getPluginConfiguration().getId()));
}
use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.
the class PackageDefinitionTest method shouldValidateUniqueKeysInConfiguration.
@Test
public void shouldValidateUniqueKeysInConfiguration() {
ConfigurationProperty one = new ConfigurationProperty(new ConfigurationKey("one"), new ConfigurationValue("value1"));
ConfigurationProperty duplicate1 = new ConfigurationProperty(new ConfigurationKey("ONE"), new ConfigurationValue("value2"));
ConfigurationProperty duplicate2 = new ConfigurationProperty(new ConfigurationKey("ONE"), new ConfigurationValue("value3"));
ConfigurationProperty two = new ConfigurationProperty(new ConfigurationKey("two"), new ConfigurationValue());
PackageDefinition packageDefinition = new PackageDefinition();
packageDefinition.setConfiguration(new Configuration(one, duplicate1, duplicate2, two));
packageDefinition.setName("go-server");
packageDefinition.validate(null);
assertThat(one.errors().isEmpty(), is(false));
assertThat(one.errors().getAllOn(ConfigurationProperty.CONFIGURATION_KEY).contains("Duplicate key 'ONE' found for Package 'go-server'"), is(true));
assertThat(duplicate1.errors().isEmpty(), is(false));
assertThat(one.errors().getAllOn(ConfigurationProperty.CONFIGURATION_KEY).contains("Duplicate key 'ONE' found for Package 'go-server'"), is(true));
assertThat(duplicate2.errors().isEmpty(), is(false));
assertThat(one.errors().getAllOn(ConfigurationProperty.CONFIGURATION_KEY).contains("Duplicate key 'ONE' found for Package 'go-server'"), is(true));
assertThat(two.errors().isEmpty(), is(true));
}
Aggregations