Search in sources :

Example 26 with ValidationResult

use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.

the class PackageRepositoryServiceTest method shouldInvokePluginValidationsBeforeSavingPackageRepository.

@Test
public void shouldInvokePluginValidationsBeforeSavingPackageRepository() throws Exception {
    String pluginId = "yum";
    PackageRepository packageRepository = new PackageRepository();
    RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, new PackageConfigurations());
    packageRepository.setPluginConfiguration(new PluginConfiguration(pluginId, "1.0"));
    packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("url", false, "junk-url"));
    ArgumentCaptor<RepositoryConfiguration> packageConfigurationsArgumentCaptor = ArgumentCaptor.forClass(RepositoryConfiguration.class);
    ValidationResult expectedValidationResult = new ValidationResult();
    expectedValidationResult.addError(new ValidationError("url", "url format incorrect"));
    when(pluginManager.getPluginDescriptorFor(pluginId)).thenReturn(new GoPluginDescriptor("yum", "1.0", null, null, null, true));
    when(packageRepositoryExtension.isRepositoryConfigurationValid(eq(pluginId), packageConfigurationsArgumentCaptor.capture())).thenReturn(expectedValidationResult);
    service = new PackageRepositoryService(pluginManager, packageRepositoryExtension, goConfigService, securityService, entityHashingService, mock(Localizer.class));
    service.performPluginValidationsFor(packageRepository);
    assertThat(packageRepository.getConfiguration().get(0).getConfigurationValue().errors().getAllOn("value"), is(Arrays.asList("url format incorrect")));
}
Also used : PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 27 with ValidationResult

use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.

the class PackageRepositoryServiceTest method shouldUpdatePluginVersionWhenValid.

@Test
public void shouldUpdatePluginVersionWhenValid() {
    String pluginId = "valid";
    RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, new PackageConfigurations());
    when(pluginManager.getPluginDescriptorFor(pluginId)).thenReturn(new GoPluginDescriptor(pluginId, "1.0", null, null, null, true));
    when(packageRepositoryExtension.isRepositoryConfigurationValid(eq(pluginId), any(RepositoryConfiguration.class))).thenReturn(new ValidationResult());
    PackageRepository packageRepository = new PackageRepository();
    packageRepository.setPluginConfiguration(new PluginConfiguration(pluginId, ""));
    service.performPluginValidationsFor(packageRepository);
    assertThat(packageRepository.getPluginConfiguration().getVersion(), is("1.0"));
}
Also used : PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 28 with ValidationResult

use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.

the class RoleConfigCreateCommandTest method shouldInvokePluginValidationsBeforeSave.

@Test
public void shouldInvokePluginValidationsBeforeSave() throws Exception {
    ValidationResult validationResult = new ValidationResult();
    validationResult.addError(new ValidationError("key", "error"));
    when(extension.validateRoleConfiguration(eq("aws"), Matchers.any())).thenReturn(validationResult);
    PluginRoleConfig role = new PluginRoleConfig("blackbird", "ldap");
    RoleConfigCreateCommand command = new RoleConfigCreateCommand(mock(GoConfigService.class), role, extension, null, new HttpLocalizedOperationResult());
    BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
    thrown.expect(RoleNotFoundException.class);
    thrown.expectMessage("Plugin role config `blackbird` does not exist.");
    command.isValid(cruiseConfig);
    command.update(cruiseConfig);
    assertThat(role.first().errors().size(), is(1));
    assertThat(role.first().errors().asString(), is("error"));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Test(org.junit.Test)

Example 29 with ValidationResult

use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult 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 30 with ValidationResult

use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.

the class PluggableTaskServiceTest method isValidShouldValidateTaskAgainstPlugin.

@Test
public void isValidShouldValidateTaskAgainstPlugin() {
    TaskConfig taskConfig = mock(TaskConfig.class);
    ValidationResult validationResult = mock(ValidationResult.class);
    PluggableTask pluggableTask = mock(PluggableTask.class);
    PluginConfiguration pluginConfiguration = new PluginConfiguration("plugin_id", "version");
    when(pluggableTask.isValid()).thenReturn(true);
    when(pluggableTask.getPluginConfiguration()).thenReturn(pluginConfiguration);
    when(pluggableTask.toTaskConfig()).thenReturn(taskConfig);
    when(taskExtension.validate(pluginConfiguration.getId(), taskConfig)).thenReturn(validationResult);
    when(validationResult.isSuccessful()).thenReturn(true);
    assertTrue(pluggableTaskService.isValid(pluggableTask));
}
Also used : PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.Test)

Aggregations

ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)61 Test (org.junit.Test)48 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)30 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)17 Configuration (com.thoughtworks.go.domain.config.Configuration)14 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)10 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)8 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)7 SCM (com.thoughtworks.go.domain.scm.SCM)7 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)5 PluginSettingsConfiguration (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration)5 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)5 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)5 PluginSettings (com.thoughtworks.go.server.domain.PluginSettings)4 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)3 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)3 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)3 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)3 DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)3 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)3