Search in sources :

Example 6 with ValidationResult

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

the class PackageDefinitionService method performPluginValidationsFor.

public void performPluginValidationsFor(final PackageDefinition packageDefinition) {
    String pluginId = packageDefinition.getRepository().getPluginConfiguration().getId();
    ValidationResult validationResult = packageRepositoryExtension.isPackageConfigurationValid(pluginId, buildPackageConfigurations(packageDefinition), buildRepositoryConfigurations(packageDefinition.getRepository()));
    for (ValidationError error : validationResult.getErrors()) {
        packageDefinition.addConfigurationErrorFor(error.getKey(), error.getMessage());
    }
    for (ConfigurationProperty configurationProperty : packageDefinition.getConfiguration()) {
        String key = configurationProperty.getConfigurationKey().getName();
        if (PackageMetadataStore.getInstance().hasOption(packageDefinition.getRepository().getPluginConfiguration().getId(), key, PackageConfiguration.REQUIRED)) {
            if (configurationProperty.getValue().isEmpty() && configurationProperty.doesNotHaveErrorsAgainstConfigurationValue()) {
                configurationProperty.addErrorAgainstConfigurationValue(localizer.localize("MANDATORY_CONFIGURATION_FIELD_WITH_NAME", configurationProperty.getConfigurationKey().getName()));
            }
        }
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult)

Example 7 with ValidationResult

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

the class PluginService method validatePluginSettingsFor.

public void validatePluginSettingsFor(PluginSettings pluginSettings) {
    String pluginId = pluginSettings.getPluginId();
    PluginSettingsConfiguration configuration = pluginSettings.toPluginSettingsConfiguration();
    ValidationResult result = null;
    boolean anyExtensionSupportsPluginId = false;
    for (GoPluginExtension extension : extensions) {
        if (extension.canHandlePlugin(pluginId)) {
            result = extension.validatePluginSettings(pluginId, configuration);
            anyExtensionSupportsPluginId = true;
        }
    }
    if (!anyExtensionSupportsPluginId)
        throw new IllegalArgumentException(String.format("Plugin '%s' is not supported by any extension point", pluginId));
    if (!result.isSuccessful()) {
        for (ValidationError error : result.getErrors()) {
            pluginSettings.populateErrorMessageFor(error.getKey(), error.getMessage());
        }
    }
}
Also used : GoPluginExtension(com.thoughtworks.go.plugin.access.common.settings.GoPluginExtension) PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult)

Example 8 with ValidationResult

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

the class TaskExtensionTest method shouldValidateTask.

@Test
public void shouldValidateTask() {
    GoPluginApiResponse response = mock(GoPluginApiResponse.class);
    TaskExtension jsonBasedTaskExtension = new TaskExtension(pluginManager);
    TaskConfig taskConfig = mock(TaskConfig.class);
    when(response.responseCode()).thenReturn(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE);
    when(pluginManager.isPluginOfType(TaskExtension.TASK_EXTENSION, pluginId)).thenReturn(true);
    when(response.responseBody()).thenReturn("{\"errors\":{\"key\":\"error\"}}");
    when(pluginManager.submitTo(eq(pluginId), any(GoPluginApiRequest.class))).thenReturn(response);
    ValidationResult validationResult = jsonBasedTaskExtension.validate(pluginId, taskConfig);
    verify(pluginManager).submitTo(eq(pluginId), any(GoPluginApiRequest.class));
    assertFalse(validationResult.isSuccessful());
    assertEquals(validationResult.getErrors().get(0).getKey(), "key");
    assertEquals(validationResult.getErrors().get(0).getMessage(), "error");
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) GoPluginApiResponse(com.thoughtworks.go.plugin.api.response.GoPluginApiResponse) DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) Test(org.junit.Test)

Example 9 with ValidationResult

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

the class SCMExtensionTest method shouldTalkToPluginToGetValidatePluginSettings.

@Test
public void shouldTalkToPluginToGetValidatePluginSettings() throws Exception {
    when(pluginSettingsJSONMessageHandler.requestMessageForPluginSettingsValidation(pluginSettingsConfiguration)).thenReturn(requestBody);
    ValidationResult deserializedResponse = new ValidationResult();
    when(pluginSettingsJSONMessageHandler.responseMessageForPluginSettingsValidation(responseBody)).thenReturn(deserializedResponse);
    ValidationResult response = scmExtension.validatePluginSettings(PLUGIN_ID, pluginSettingsConfiguration);
    assertRequest(requestArgumentCaptor.getValue(), SCMExtension.EXTENSION_NAME, "1.0", PluginSettingsConstants.REQUEST_VALIDATE_PLUGIN_SETTINGS, requestBody);
    verify(pluginSettingsJSONMessageHandler).responseMessageForPluginSettingsValidation(responseBody);
    assertSame(response, deserializedResponse);
}
Also used : ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Test(org.junit.Test)

Example 10 with ValidationResult

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

the class NotificationExtensionTestBase method shouldTalkToPluginToValidatePluginSettings.

@Test
public void shouldTalkToPluginToValidatePluginSettings() throws Exception {
    String requestBody = "expected-request";
    when(pluginSettingsJSONMessageHandler().requestMessageForPluginSettingsValidation(pluginSettingsConfiguration)).thenReturn(requestBody);
    ValidationResult deserializedResponse = new ValidationResult();
    when(pluginSettingsJSONMessageHandler().responseMessageForPluginSettingsValidation(RESPONSE_BODY)).thenReturn(deserializedResponse);
    ValidationResult response = notificationExtension.validatePluginSettings(PLUGIN_ID, pluginSettingsConfiguration);
    assertRequest(requestArgumentCaptor.getValue(), NotificationExtension.EXTENSION_NAME, apiVersion(), PluginSettingsConstants.REQUEST_VALIDATE_PLUGIN_SETTINGS, requestBody);
    verify(pluginSettingsJSONMessageHandler()).responseMessageForPluginSettingsValidation(RESPONSE_BODY);
    assertSame(response, deserializedResponse);
}
Also used : ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Test(org.junit.Test)

Aggregations

ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)61 Test (org.junit.Test)48 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)30 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)17 Configuration (com.thoughtworks.go.domain.config.Configuration)14 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)10 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)8 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)7 SCM (com.thoughtworks.go.domain.scm.SCM)7 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)5 PluginSettingsConfiguration (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration)5 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)5 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)5 PluginSettings (com.thoughtworks.go.server.domain.PluginSettings)4 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)3 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)3 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)3 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)3 DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)3 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)3