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"));
}
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"));
}
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));
}
}
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() + "'.");
}
}
}
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, "{}");
}
Aggregations