use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class ArtifactExtensionTestBase method shouldValidatePluggableArtifactConfig.
@Test
public void shouldValidatePluggableArtifactConfig() {
String responseBody = "[{\"message\":\"Filename must not be blank.\",\"key\":\"Filename\"}]";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
ValidationResult validationResult = artifactExtension.validatePluggableArtifactConfig(PLUGIN_ID, Collections.singletonMap("Filename", ""));
final GoPluginApiRequest request = requestArgumentCaptor.getValue();
assertThat(request.extension(), is(ARTIFACT_EXTENSION));
assertThat(request.requestName(), is(REQUEST_PUBLISH_ARTIFACT_VALIDATE));
assertThat(request.requestBody(), is("{\"Filename\":\"\"}"));
assertThat(validationResult.isSuccessful(), is(false));
assertThat(validationResult.getErrors(), containsInAnyOrder(new ValidationError("Filename", "Filename must not be blank.")));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class SecretsExtensionV1Test method shouldTalkToPlugin_toValidateSecretsConfig.
@Test
void shouldTalkToPlugin_toValidateSecretsConfig() {
String responseBody = "[{\"message\":\"Vault Url cannot be blank.\",\"key\":\"Url\"},{\"message\":\"Path cannot be blank.\",\"key\":\"Path\"}]";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(SECRETS_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody));
final ValidationResult result = secretsExtensionV1.validateSecretsConfig(PLUGIN_ID, singletonMap("username", "some_name"));
assertThat(result.isSuccessful()).isFalse();
assertThat(result.getErrors()).contains(new ValidationError("Url", "Vault Url cannot be blank."), new ValidationError("Path", "Path cannot be blank."));
assertExtensionRequest(REQUEST_VALIDATE_SECRETS_CONFIG, "{\"username\":\"some_name\"}");
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class JsonBasedTaskExtensionHandler_V1Test method shouldConvertJsonResponseToValidationResultWhenValidationFails.
@Test
public void shouldConvertJsonResponseToValidationResultWhenValidationFails() {
String jsonResponse = "{\"errors\":{\"key1\":\"err1\",\"key2\":\"err2\"}}";
TaskConfig configuration = new TaskConfig();
TaskConfigProperty property = new TaskConfigProperty("URL", "http://foo");
property.with(Property.SECURE, false);
property.with(Property.REQUIRED, true);
configuration.add(property);
ValidationResult result = new JsonBasedTaskExtensionHandler_V1().toValidationResult(jsonResponse);
assertThat(result.isSuccessful(), is(false));
ValidationError error1 = result.getErrors().get(0);
ValidationError error2 = result.getErrors().get(1);
assertThat(error1.getKey(), is("key1"));
assertThat(error1.getMessage(), is("err1"));
assertThat(error2.getKey(), is("key2"));
assertThat(error2.getMessage(), is("err2"));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class SecretConfigCreateCommandTest method shouldInvokePluginValidations.
@Test
public void shouldInvokePluginValidations() throws Exception {
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("key", "error"));
SecretConfig newSecretConfig = new SecretConfig("foo", "file", new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("val")));
RuleAwarePluginProfileCommand command = new SecretConfigCreateCommand(mock(GoConfigService.class), newSecretConfig, extension, null, new HttpLocalizedOperationResult());
when(extension.validateSecretsConfig(eq("file"), anyMap())).thenReturn(validationResult);
BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
assertThatThrownBy(() -> command.isValid(cruiseConfig)).isInstanceOf(RecordNotFoundException.class).hasMessageContaining(EntityType.SecretConfig.notFoundMessage(newSecretConfig.getId()));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class SecurityAuthConfigCreateCommandTest method shouldInvokePluginValidationsBeforeSave.
@Test
public void shouldInvokePluginValidationsBeforeSave() throws Exception {
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("key", "error"));
when(extension.validateAuthConfig(eq("aws"), anyMap())).thenReturn(validationResult);
SecurityAuthConfig newProfile = new SecurityAuthConfig("foo", "aws", new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("val")));
PluginProfileCommand command = new SecurityAuthConfigCreateCommand(mock(GoConfigService.class), newProfile, extension, null, new HttpLocalizedOperationResult());
BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
assertThatThrownBy(() -> command.isValid(cruiseConfig)).isInstanceOf(RecordNotFoundException.class).hasMessageContaining(EntityType.SecurityAuthConfig.notFoundMessage(newProfile.getId()));
}
Aggregations