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()));
}
}
}
}
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());
}
}
}
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");
}
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);
}
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);
}
Aggregations