Search in sources :

Example 31 with ValidationError

use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.

the class ArtifactStoreServiceTest method shouldInvokePluginValidationsBeforeAddingTheArtifactStore.

@Test
public void shouldInvokePluginValidationsBeforeAddingTheArtifactStore() {
    ArtifactStore artifactStore = new ArtifactStore("docker", "cd.go.artifact.docker", create("key", false, "val"));
    ValidationResult validationResult = new ValidationResult();
    validationResult.addError(new ValidationError("key", "some-error"));
    when(extension.validateArtifactStoreConfig(eq("cd.go.artifact.docker"), anyMap())).thenReturn(validationResult);
    artifactStoreService.create(new Username("admin"), artifactStore, new HttpLocalizedOperationResult());
    MatcherAssert.assertThat(artifactStore.first().errors().size(), is(1));
    MatcherAssert.assertThat(artifactStore.first().errors().on("key"), is("some-error"));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArtifactStore(com.thoughtworks.go.config.ArtifactStore) Username(com.thoughtworks.go.server.domain.Username) 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 32 with ValidationError

use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.

the class ArtifactStoreServiceTest method shouldInvokePluginValidationsBeforeUpdatingTheArtifactStore.

@Test
public void shouldInvokePluginValidationsBeforeUpdatingTheArtifactStore() {
    ArtifactStore artifactStore = new ArtifactStore("docker", "cd.go.artifact.docker", create("key", false, "val"));
    ValidationResult validationResult = new ValidationResult();
    validationResult.addError(new ValidationError("key", "some-error"));
    when(extension.validateArtifactStoreConfig(eq("cd.go.artifact.docker"), anyMap())).thenReturn(validationResult);
    artifactStoreService.update(new Username("admin"), "md5", artifactStore, new HttpLocalizedOperationResult());
    MatcherAssert.assertThat(artifactStore.first().errors().size(), is(1));
    MatcherAssert.assertThat(artifactStore.first().errors().on("key"), is("some-error"));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArtifactStore(com.thoughtworks.go.config.ArtifactStore) Username(com.thoughtworks.go.server.domain.Username) 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 33 with ValidationError

use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.

the class RoleConfigurationValidator method validate.

public void validate(PluginRoleConfig role, String pluginId) {
    try {
        ValidationResult result = authorizationExtension.validateRoleConfiguration(pluginId, role.getConfigurationAsMap(true));
        if (!result.isSuccessful()) {
            for (ValidationError error : result.getErrors()) {
                ConfigurationProperty property = role.getProperty(error.getKey());
                if (property == null) {
                    role.addNewConfiguration(error.getKey(), false);
                    property = role.getProperty(error.getKey());
                }
                property.addError(error.getKey(), error.getMessage());
            }
        }
    } catch (RecordNotFoundException e) {
        role.addError("pluginRole", String.format("Unable to validate `pluginRole` configuration, missing plugin: %s", pluginId));
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult)

Example 34 with ValidationError

use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.

the class RoleConfigCommand method validate.

private void validate(CruiseConfig preprocessedConfig) {
    if (role instanceof PluginRoleConfig) {
        PluginRoleConfig role = (PluginRoleConfig) this.role;
        PluginRoleConfig preprocessedRole = (PluginRoleConfig) this.preprocessedRole;
        SecurityAuthConfig securityAuthConfig = preprocessedConfig.server().security().securityAuthConfigs().find(role.getAuthConfigId());
        if (securityAuthConfig == null) {
            role.addError("authConfigId", "No such security auth configuration present " + role.getAuthConfigId());
            return;
        }
        try {
            ValidationResult result = extension.validateRoleConfiguration(securityAuthConfig.getPluginId(), role.getConfigurationAsMap(true));
            if (!result.isSuccessful()) {
                for (ValidationError validationError : result.getErrors()) {
                    ConfigurationProperty property = preprocessedRole.getProperty(validationError.getKey());
                    if (property == null) {
                        role.addNewConfiguration(validationError.getKey(), false);
                        preprocessedRole.addNewConfiguration(validationError.getKey(), false);
                        property = preprocessedRole.getProperty(validationError.getKey());
                    }
                    property.addError(validationError.getKey(), validationError.getMessage());
                }
            }
        } catch (PluginNotFoundException e) {
            role.addError("authConfigId", "Could not find a security authorization config with id '" + role.getAuthConfigId() + "'.");
        }
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) PluginNotFoundException(com.thoughtworks.go.plugin.access.PluginNotFoundException) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult)

Example 35 with ValidationError

use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.

the class ElasticAgentExtensionV1Test 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 = extensionV1.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("1.0", REQUEST_VALIDATE_PROFILE, "{}");
}
Also used : ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Test(org.junit.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