use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class PluggableTaskServiceTest method shouldValidateTask.
@Test
public void shouldValidateTask() {
Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
PluggableTask modifiedTask = new PluggableTask(new PluginConfiguration(pluginId, "1"), configuration);
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("KEY1", "error message"));
when(taskExtension.validate(eq(modifiedTask.getPluginConfiguration().getId()), any(TaskConfig.class))).thenReturn(validationResult);
pluggableTaskService.validate(modifiedTask);
assertThat(modifiedTask.getConfiguration().getProperty("KEY1").errors().isEmpty(), is(false));
assertThat(modifiedTask.getConfiguration().getProperty("KEY1").errors().firstError(), is("error message"));
verify(taskExtension).validate(eq(modifiedTask.getPluginConfiguration().getId()), any(TaskConfig.class));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class ExternalArtifactsServiceTest method isValidShouldMapPluginValidationErrorsToExternalArtifactForMissingConfigurations.
@Test
public void isValidShouldMapPluginValidationErrorsToExternalArtifactForMissingConfigurations() {
pluggableArtifactConfig.getConfiguration().clear();
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("configuration", "Either Image or BuildFile is required"));
ArtifactStore artifactStore = mock(ArtifactStore.class);
when(artifactStore.getPluginId()).thenReturn(pluginId);
when(artifactExtension.validatePluggableArtifactConfig(any(), any())).thenReturn(validationResult);
externalArtifactsService.validateExternalArtifactConfig(pluggableArtifactConfig, artifactStore, true);
assertThat(pluggableArtifactConfig.errors().getAllOn("configuration").get(0), is("Either Image or BuildFile is required"));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class PluginServiceTest method createPluginSettings_shouldValidatePluginSettingUsingExtensionAndReturnUnprocessableEntityWhenThereIsAValidationError.
@Test
public void createPluginSettings_shouldValidatePluginSettingUsingExtensionAndReturnUnprocessableEntityWhenThereIsAValidationError() {
setUpElasticPluginForTheTest(true);
when(pluginDao.findPlugin(elasticAgentPluginId)).thenReturn(new NullPlugin());
final ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("key-1", "error-message"));
when(pluginSettings.hasErrors()).thenReturn(true);
pluginService.createPluginSettings(pluginSettings, currentUser, result);
verify(pluginDao, times(0)).saveOrUpdate(any());
verify(elasticAgentExtension, times(0)).notifyPluginSettingsChange(eq(elasticAgentPluginId), anyMap());
verify(result, times(1)).unprocessableEntity("Save failed. There are errors in the plugin settings. Please fix them and resubmit.");
verifyNoMoreInteractions(result);
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class PluginServiceTest method validatePluginSettingsFor_shouldPopulateValidationErrorsInPluginSettingsObject.
@Test
public void validatePluginSettingsFor_shouldPopulateValidationErrorsInPluginSettingsObject() {
final ElasticAgentPluginInfo elasticAgentPluginInfo = mockElasticAgentPluginInfo(getPluggableInstanceSettings());
final ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("key-1", "m1"));
validationResult.addError(new ValidationError("key-3", "m3"));
addPluginSettingsMetadataToStore(elasticAgentPluginId, ELASTIC_AGENT_EXTENSION, getPluginSettingsConfiguration());
when(elasticAgentExtension.extensionName()).thenReturn(ELASTIC_AGENT_EXTENSION);
when(elasticAgentExtension.canHandlePlugin(elasticAgentPluginId)).thenReturn(true);
when(elasticAgentExtension.validatePluginSettings(eq(elasticAgentPluginId), any(PluginSettingsConfiguration.class))).thenReturn(validationResult);
PluginSettings pluginSettings = PluginSettings.from(getPlugin(elasticAgentPluginId), elasticAgentPluginInfo);
pluginService.validatePluginSettings(pluginSettings);
assertThat(pluginSettings.hasErrors(), is(true));
assertThat(pluginSettings.getErrorFor("key-1"), is(Arrays.asList("m1")));
assertThat(pluginSettings.getErrorFor("key-3"), is(Arrays.asList("m3")));
}
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());
}
Aggregations