use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class PluginProfileCommand method isValidForCreateOrUpdate.
protected boolean isValidForCreateOrUpdate(CruiseConfig preprocessedConfig) {
preprocessedProfile = findExistingProfile(preprocessedConfig);
preprocessedProfile.validate(null);
ValidationResult result = validateUsingExtension(preprocessedProfile.getPluginId(), profile.getConfigurationAsMap(true));
if (!result.isSuccessful()) {
for (ValidationError validationError : result.getErrors()) {
ConfigurationProperty property = preprocessedProfile.getProperty(validationError.getKey());
if (property == null) {
profile.addNewConfiguration(validationError.getKey(), false);
preprocessedProfile.addNewConfiguration(validationError.getKey(), false);
property = preprocessedProfile.getProperty(validationError.getKey());
}
property.addError(validationError.getKey(), validationError.getMessage());
}
}
if (preprocessedProfile.errors().isEmpty()) {
getPluginProfiles(preprocessedConfig).validate(null);
BasicCruiseConfig.copyErrors(preprocessedProfile, profile);
return preprocessedProfile.getAllErrors().isEmpty() && profile.errors().isEmpty();
}
BasicCruiseConfig.copyErrors(preprocessedProfile, profile);
return false;
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class AuthorizationExtensionTest method shouldTalkToPlugin_To_ValidatePluginConfiguration.
@Test
public void shouldTalkToPlugin_To_ValidatePluginConfiguration() throws Exception {
String responseBody = "[{\"message\":\"Url must not be blank.\",\"key\":\"Url\"},{\"message\":\"SearchBase must not be blank.\",\"key\":\"SearchBase\"}]";
when(pluginManager.submitTo(eq(PLUGIN_ID), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
ValidationResult validationResult = authorizationExtension.validatePluginConfiguration(PLUGIN_ID, Collections.emptyMap());
assertRequest(requestArgumentCaptor.getValue(), AuthorizationPluginConstants.EXTENSION_NAME, "1.0", REQUEST_VALIDATE_AUTH_CONFIG, "{}");
assertThat(validationResult.isSuccessful(), is(false));
assertThat(validationResult.getErrors(), containsInAnyOrder(new ValidationError("Url", "Url must not be blank."), new ValidationError("SearchBase", "SearchBase must not be blank.")));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class RoleConfigCreateCommandTest method shouldInvokePluginValidationsBeforeSave.
@Test
public void shouldInvokePluginValidationsBeforeSave() throws Exception {
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("key", "error"));
when(extension.validateRoleConfiguration(eq("aws"), Matchers.any())).thenReturn(validationResult);
PluginRoleConfig role = new PluginRoleConfig("blackbird", "ldap");
RoleConfigCreateCommand command = new RoleConfigCreateCommand(mock(GoConfigService.class), role, extension, null, new HttpLocalizedOperationResult());
BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
thrown.expect(RoleNotFoundException.class);
thrown.expectMessage("Plugin role config `blackbird` does not exist.");
command.isValid(cruiseConfig);
command.update(cruiseConfig);
assertThat(role.first().errors().size(), is(1));
assertThat(role.first().errors().asString(), is("error"));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class ElasticAgentExtensionTest 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 = extension.validate(PLUGIN_ID, Collections.emptyMap());
MatcherAssert.assertThat(result.isSuccessful(), is(false));
MatcherAssert.assertThat(result.getErrors(), containsInAnyOrder(new ValidationError("Url", "Url must not be blank."), new ValidationError("SearchBase", "SearchBase must not be blank.")));
assertExtensionRequest("3.0", REQUEST_VALIDATE_PROFILE, "{}");
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class ElasticAgentExtensionV2Test 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 = extensionV2.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("2.0", REQUEST_VALIDATE_PROFILE, "{}");
}
Aggregations