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"));
}
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"));
}
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());
}
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"));
}
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));
}
Aggregations