Search in sources :

Example 61 with ValidationError

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

the class PluggableScmServiceTest method shouldHandleIncorrectKeyForValidateSCM.

@Test
public void shouldHandleIncorrectKeyForValidateSCM() {
    Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
    configuration.getProperty("KEY1").setConfigurationValue(new ConfigurationValue("junk"));
    SCM modifiedSCM = new SCM("scm-id", new PluginConfiguration(pluginId, "1"), configuration);
    ValidationResult validationResult = new ValidationResult();
    validationResult.addError(new ValidationError("NON-EXISTENT-KEY", "error message"));
    when(scmExtension.isSCMConfigurationValid(eq(modifiedSCM.getPluginConfiguration().getId()), any(SCMPropertyConfiguration.class))).thenReturn(validationResult);
    pluggableScmService.validate(modifiedSCM);
    assertTrue(modifiedSCM.errors().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) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) SCM(com.thoughtworks.go.domain.scm.SCM) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 62 with ValidationError

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

the class RoleConfigurationValidatorTest method shouldAddConfigurationAndMapErrorsInAbsenceOfConfiguration.

@Test
public void shouldAddConfigurationAndMapErrorsInAbsenceOfConfiguration() throws Exception {
    ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("username"), new ConfigurationValue("view"));
    PluginRoleConfig roleConfig = new PluginRoleConfig("admin", "auth_id", property);
    ValidationResult result = new ValidationResult();
    result.addError(new ValidationError("password", "password is required"));
    when(extension.validateRoleConfiguration("pluginId", Collections.singletonMap("username", "view"))).thenReturn(result);
    validator.validate(roleConfig, "pluginId");
    assertTrue(roleConfig.hasErrors());
    assertThat(roleConfig.getProperty("password").errors().get("password").get(0), is("password is required"));
    assertNull(roleConfig.getProperty("password").getValue());
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 63 with ValidationError

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

the class PluggableTaskServiceTest method isValidShouldMapPluginValidationErrorsToPluggableTaskForMissingConfigurations.

@Test
public void isValidShouldMapPluginValidationErrorsToPluggableTaskForMissingConfigurations() {
    PluginConfiguration pluginConfiguration = new PluginConfiguration("plugin_id", "version");
    ValidationResult validationResult = new ValidationResult();
    validationResult.addError(new ValidationError("source", "source is mandatory"));
    PluggableTask pluggableTask = mock(PluggableTask.class);
    when(pluggableTask.isValid()).thenReturn(true);
    when(pluggableTask.toTaskConfig()).thenReturn(new TaskConfig());
    when(pluggableTask.getPluginConfiguration()).thenReturn(pluginConfiguration);
    when(pluggableTask.getConfiguration()).thenReturn(new Configuration());
    when(taskExtension.validate(any(String.class), any(TaskConfig.class))).thenReturn(validationResult);
    assertFalse(pluggableTaskService.isValid(pluggableTask));
    verify(pluggableTask).addError("source", "source is mandatory");
}
Also used : PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) Configuration(com.thoughtworks.go.domain.config.Configuration) 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.jupiter.api.Test)

Aggregations

ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)63 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)61 Test (org.junit.jupiter.api.Test)35 Configuration (com.thoughtworks.go.domain.config.Configuration)15 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)15 Test (org.junit.Test)14 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)13 DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)9 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)7 SCM (com.thoughtworks.go.domain.scm.SCM)7 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)7 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)6 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)6 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)5 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)5 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)5 PluginSettingsConfiguration (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration)5 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)4 PluginSettings (com.thoughtworks.go.server.domain.PluginSettings)4 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)4