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