Search in sources :

Example 16 with ValidationResult

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

the class PluggableScmServiceTest method shouldValidateMandatoryFieldsForSCM.

@Test
public void shouldValidateMandatoryFieldsForSCM() {
    Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
    SCM modifiedSCM = new SCM("scm-id", new PluginConfiguration(pluginId, "1"), configuration);
    ValidationResult validationResult = new ValidationResult();
    when(scmExtension.isSCMConfigurationValid(eq(modifiedSCM.getPluginConfiguration().getId()), any(SCMPropertyConfiguration.class))).thenReturn(validationResult);
    when(localizer.localize("MANDATORY_CONFIGURATION_FIELD")).thenReturn("MANDATORY_CONFIGURATION_FIELD");
    pluggableScmService.validate(modifiedSCM);
    final List<ValidationError> validationErrors = validationResult.getErrors();
    assertFalse(validationErrors.isEmpty());
    final ValidationError validationError = getValidationErrorFor(validationErrors, "KEY1");
    assertNotNull(validationError);
    assertThat(validationError.getMessage(), is("MANDATORY_CONFIGURATION_FIELD"));
}
Also used : 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.Test)

Example 17 with ValidationResult

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

the class PluggableScmServiceTest method isValidShouldMapPluginValidationErrorsToPluggableSCMConfigurations.

@Test
public void isValidShouldMapPluginValidationErrorsToPluggableSCMConfigurations() {
    PluginConfiguration pluginConfiguration = new PluginConfiguration("plugin_id", "version");
    Configuration configuration = new Configuration();
    configuration.add(ConfigurationPropertyMother.create("url", false, "url"));
    configuration.add(ConfigurationPropertyMother.create("username", false, "admin"));
    ValidationResult validationResult = new ValidationResult();
    validationResult.addError(new ValidationError("url", "invalid"));
    validationResult.addError(new ValidationError("username", "invalid"));
    SCM scmConfig = mock(SCM.class);
    when(scmConfig.doesPluginExist()).thenReturn(true);
    when(scmConfig.getPluginConfiguration()).thenReturn(pluginConfiguration);
    when(scmConfig.getConfiguration()).thenReturn(configuration);
    when(scmExtension.isSCMConfigurationValid(any(String.class), any(SCMPropertyConfiguration.class))).thenReturn(validationResult);
    assertFalse(pluggableScmService.isValid(scmConfig));
    assertThat(configuration.getProperty("url").errors().get("url").get(0), is("invalid"));
    assertThat(configuration.getProperty("username").errors().get("username").get(0), is("invalid"));
}
Also used : 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) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) SCM(com.thoughtworks.go.domain.scm.SCM) Test(org.junit.Test)

Example 18 with ValidationResult

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

the class RoleConfigurationValidatorTest method setUp.

@Before
public void setUp() throws Exception {
    extension = mock(AuthorizationExtension.class);
    validator = new RoleConfigurationValidator(extension);
    stub(extension.validateRoleConfiguration(any(String.class), any(Map.class))).toReturn(new ValidationResult());
}
Also used : AuthorizationExtension(com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Map(java.util.Map) Before(org.junit.Before)

Example 19 with ValidationResult

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

the class RoleConfigurationValidatorTest method shouldMapValidationErrorsToRoleConfiguration.

@Test
public void shouldMapValidationErrorsToRoleConfiguration() 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("username", "username format is incorrect"));
    when(extension.validateRoleConfiguration("pluginId", Collections.singletonMap("username", "view"))).thenReturn(result);
    validator.validate(roleConfig, "pluginId");
    assertTrue(roleConfig.hasErrors());
    assertThat(roleConfig.getProperty("username").errors().get("username").get(0), is("username format is incorrect"));
}
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.Test)

Example 20 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)85 Test (org.junit.Test)69 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)43 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)17 Configuration (com.thoughtworks.go.domain.config.Configuration)14 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)11 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)11 PluginSettingsConfiguration (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration)10 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)10 PluginSettings (com.thoughtworks.go.server.domain.PluginSettings)9 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)7 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)7 SCM (com.thoughtworks.go.domain.scm.SCM)7 DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)5 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)5 Username (com.thoughtworks.go.server.domain.Username)5 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)4 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)3