Search in sources :

Example 51 with ValidationError

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.")));
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 52 with ValidationError

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\"}");
}
Also used : ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 53 with ValidationError

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"));
}
Also used : ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 54 with ValidationError

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()));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) SecretConfig(com.thoughtworks.go.config.SecretConfig) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Test(org.junit.jupiter.api.Test)

Example 55 with ValidationError

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()));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)63 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)61 Test (org.junit.jupiter.api.Test)35 Configuration (com.thoughtworks.go.domain.config.Configuration)15 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)15 Test (org.junit.Test)14 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)13 DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)9 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)7 SCM (com.thoughtworks.go.domain.scm.SCM)7 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)7 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)6 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)6 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)5 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)5 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)5 PluginSettingsConfiguration (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration)5 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)4 PluginSettings (com.thoughtworks.go.server.domain.PluginSettings)4 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)4