Search in sources :

Example 6 with ConfigurationValue

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()));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) Configuration(com.thoughtworks.go.domain.config.Configuration) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Test(org.junit.Test)

Example 7 with ConfigurationValue

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);
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Test(org.junit.Test)

Example 8 with ConfigurationValue

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"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Test(org.junit.Test)

Example 9 with ConfigurationValue

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));
}
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 10 with ConfigurationValue

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());
}
Also used : ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.Test)

Aggregations

ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)34 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)28 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)27 Test (org.junit.Test)27 Configuration (com.thoughtworks.go.domain.config.Configuration)20 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)16 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)14 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)9 GoCipher (com.thoughtworks.go.security.GoCipher)8 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)5 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)4 SCMConfiguration (com.thoughtworks.go.plugin.access.scm.SCMConfiguration)4 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)4 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)4 SCM (com.thoughtworks.go.domain.scm.SCM)3 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)3 HashMap (java.util.HashMap)3 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)2 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)2 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)2