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 PluggableScmServiceTest method shouldValidateSCM.
@Test
public void shouldValidateSCM() {
SCMConfiguration scmConfig = new SCMConfiguration(new SCMProperty("KEY2").with(Property.REQUIRED, false));
scmConfigurations.add(scmConfig);
Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
SCM modifiedSCM = new SCM("scm-id", new PluginConfiguration(pluginId, "1"), configuration);
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("KEY1", "error message"));
when(scmExtension.isSCMConfigurationValid(eq(modifiedSCM.getPluginConfiguration().getId()), any(SCMPropertyConfiguration.class))).thenReturn(validationResult);
pluggableScmService.validate(modifiedSCM);
assertFalse(modifiedSCM.getConfiguration().getProperty("KEY1").errors().isEmpty());
assertThat(modifiedSCM.getConfiguration().getProperty("KEY1").errors().firstError(), is("error message"));
verify(scmExtension).isSCMConfigurationValid(eq(modifiedSCM.getPluginConfiguration().getId()), any(SCMPropertyConfiguration.class));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class PluggableScmServiceTest method shouldValidateMandatoryAndSecureFieldsForSCM.
@Test
public void shouldValidateMandatoryAndSecureFieldsForSCM() {
SCMConfiguration scmConfig = new SCMConfiguration(new SCMProperty("KEY2").with(Property.REQUIRED, true).with(Property.SECURE, true));
scmConfigurations.add(scmConfig);
Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"), ConfigurationPropertyMother.create("KEY2", true, ""));
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);
pluggableScmService.validate(modifiedSCM);
final List<ValidationError> validationErrors = validationResult.getErrors();
assertFalse(validationErrors.isEmpty());
final ValidationError validationErrorForKey1 = getValidationErrorFor(validationErrors, "KEY1");
assertNotNull(validationErrorForKey1);
assertThat(validationErrorForKey1.getMessage(), is("This field is required"));
final ValidationError validationErrorForKey2 = getValidationErrorFor(validationErrors, "KEY2");
assertNotNull(validationErrorForKey2);
assertThat(validationErrorForKey2.getMessage(), is("This field is required"));
}
Aggregations