use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class PluggableTaskServiceTest method isValidShouldMapPluginValidationErrorsToPluggableTaskConfigrations.
@Test
public void isValidShouldMapPluginValidationErrorsToPluggableTaskConfigrations() {
PluginConfiguration pluginConfiguration = new PluginConfiguration("plugin_id", "version");
Configuration configuration = new Configuration();
configuration.add(ConfigurationPropertyMother.create("source", false, "src_dir"));
configuration.add(ConfigurationPropertyMother.create("destination", false, "dest_dir"));
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("source", "source directory format is invalid"));
validationResult.addError(new ValidationError("destination", "destination directory format is invalid"));
PluggableTask pluggableTask = mock(PluggableTask.class);
when(pluggableTask.isValid()).thenReturn(true);
when(pluggableTask.getPluginConfiguration()).thenReturn(pluginConfiguration);
when(pluggableTask.getConfiguration()).thenReturn(configuration);
when(taskExtension.validate(any(String.class), any(TaskConfig.class))).thenReturn(validationResult);
assertFalse(pluggableTaskService.isValid(pluggableTask));
assertThat(configuration.getProperty("source").errors().get("source").get(0), is("source directory format is invalid"));
assertThat(configuration.getProperty("destination").errors().get("destination").get(0), is("destination directory format is invalid"));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class PluggableTaskServiceTest method shouldPassValidationIfAllRequiredFieldsHaveValues.
@Test
public void shouldPassValidationIfAllRequiredFieldsHaveValues() {
Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
configuration.getProperty("KEY1").setConfigurationValue(new ConfigurationValue("junk"));
PluggableTask modifiedTask = new PluggableTask(new PluginConfiguration(pluginId, "1"), configuration);
ValidationResult validationResult = new ValidationResult();
when(taskExtension.validate(eq(modifiedTask.getPluginConfiguration().getId()), any(TaskConfig.class))).thenReturn(validationResult);
pluggableTaskService.validate(modifiedTask);
final List<ValidationError> validationErrors = validationResult.getErrors();
assertTrue(validationErrors.isEmpty());
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class ElasticAgentExtensionTest method shouldValidateProfile.
@Test
public void shouldValidateProfile() throws JSONException {
String responseBody = "[{\"message\":\"Url must not be blank.\",\"key\":\"Url\"},{\"message\":\"SearchBase must not be blank.\",\"key\":\"SearchBase\"}]";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ELASTIC_AGENT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody));
final ValidationResult result = extension.validate(PLUGIN_ID, Collections.emptyMap());
MatcherAssert.assertThat(result.isSuccessful(), is(false));
MatcherAssert.assertThat(result.getErrors(), containsInAnyOrder(new ValidationError("Url", "Url must not be blank."), new ValidationError("SearchBase", "SearchBase must not be blank.")));
assertExtensionRequest("3.0", REQUEST_VALIDATE_PROFILE, "{}");
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class ElasticAgentExtensionV2Test method shouldValidateProfile.
@Test
public void shouldValidateProfile() throws JSONException {
String responseBody = "[{\"message\":\"Url must not be blank.\",\"key\":\"Url\"},{\"message\":\"SearchBase must not be blank.\",\"key\":\"SearchBase\"}]";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ELASTIC_AGENT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody));
final ValidationResult result = extensionV2.validateElasticProfile(PLUGIN_ID, Collections.emptyMap());
assertThat(result.isSuccessful(), is(false));
assertThat(result.getErrors(), containsInAnyOrder(new ValidationError("Url", "Url must not be blank."), new ValidationError("SearchBase", "SearchBase must not be blank.")));
assertExtensionRequest("2.0", REQUEST_VALIDATE_PROFILE, "{}");
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class ElasticAgentExtensionConverterV2Test method shouldHandleValidationResponse.
@Test
public void shouldHandleValidationResponse() {
String responseBody = "[{\"key\":\"key-one\",\"message\":\"error on key one\"}, {\"key\":\"key-two\",\"message\":\"error on key two\"}]";
ValidationResult result = converterV2.getElasticProfileValidationResultResponseFromBody(responseBody);
assertThat(result.isSuccessful(), is(false));
assertThat(result.getErrors().size(), is(2));
assertThat(result.getErrors().get(0).getKey(), is("key-one"));
assertThat(result.getErrors().get(0).getMessage(), is("error on key one"));
assertThat(result.getErrors().get(1).getKey(), is("key-two"));
assertThat(result.getErrors().get(1).getMessage(), is("error on key two"));
}
Aggregations