use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class ElasticAgentExtensionConverterV1Test method shouldHandleValidationResponse.
@Test
public void shouldHandleValidationResponse() {
String responseBody = "[{\"key\":\"key-one\",\"message\":\"error on key one\"}, {\"key\":\"key-two\",\"message\":\"error on key two\"}]";
ValidationResult result = converterV1.getElasticProfileValidationResultResponseFromBody(responseBody);
assertThat(result.isSuccessful(), is(false));
assertThat(result.getErrors().size(), is(2));
assertThat(result.getErrors().get(0).getKey(), is("key-one"));
assertThat(result.getErrors().get(0).getMessage(), is("error on key one"));
assertThat(result.getErrors().get(1).getKey(), is("key-two"));
assertThat(result.getErrors().get(1).getMessage(), is("error on key two"));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class ArtifactExtensionTest method shouldValidateArtifactStoreConfig.
@Test
public void shouldValidateArtifactStoreConfig() {
String responseBody = "[{\"message\":\"ACCESS_KEY must not be blank.\",\"key\":\"ACCESS_KEY\"}]";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
ValidationResult validationResult = artifactExtension.validateArtifactStoreConfig(PLUGIN_ID, Collections.singletonMap("ACCESS_KEY", ""));
final GoPluginApiRequest request = requestArgumentCaptor.getValue();
assertThat(request.extension(), is(ARTIFACT_EXTENSION));
assertThat(request.requestName(), is(REQUEST_STORE_CONFIG_VALIDATE));
assertThat(request.requestBody(), is("{\"ACCESS_KEY\":\"\"}"));
assertThat(validationResult.isSuccessful(), is(false));
assertThat(validationResult.getErrors(), containsInAnyOrder(new ValidationError("ACCESS_KEY", "ACCESS_KEY must not be blank.")));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class ArtifactExtensionTest method shouldValidateFetchArtifactConfig.
@Test
public void shouldValidateFetchArtifactConfig() {
String responseBody = "[{\"message\":\"Filename must not be blank.\",\"key\":\"Filename\"}]";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
ValidationResult validationResult = artifactExtension.validateFetchArtifactConfig(PLUGIN_ID, Collections.singletonMap("Filename", ""));
final GoPluginApiRequest request = requestArgumentCaptor.getValue();
assertThat(request.extension(), is(ARTIFACT_EXTENSION));
assertThat(request.requestName(), is(REQUEST_FETCH_ARTIFACT_VALIDATE));
assertThat(request.requestBody(), is("{\"Filename\":\"\"}"));
assertThat(validationResult.isSuccessful(), is(false));
assertThat(validationResult.getErrors(), containsInAnyOrder(new ValidationError("Filename", "Filename must not be blank.")));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class AuthorizationExtensionTest method shouldTalkToPlugin_To_ValidateRoleConfiguration.
@Test
public void shouldTalkToPlugin_To_ValidateRoleConfiguration() throws Exception {
String responseBody = "[{\"message\":\"memberOf must not be blank.\",\"key\":\"memberOf\"}]";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(AUTHORIZATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
ValidationResult validationResult = authorizationExtension.validateRoleConfiguration(PLUGIN_ID, Collections.emptyMap());
assertRequest(requestArgumentCaptor.getValue(), AUTHORIZATION_EXTENSION, "1.0", REQUEST_VALIDATE_ROLE_CONFIG, "{}");
assertThat(validationResult.isSuccessful(), is(false));
assertThat(validationResult.getErrors(), containsInAnyOrder(new ValidationError("memberOf", "memberOf must not be blank.")));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class AuthorizationExtensionTest method shouldTalkToPlugin_To_ValidateAuthConfig.
@Test
public void shouldTalkToPlugin_To_ValidateAuthConfig() 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), eq(AUTHORIZATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
ValidationResult validationResult = authorizationExtension.validateAuthConfig(PLUGIN_ID, Collections.emptyMap());
assertRequest(requestArgumentCaptor.getValue(), AUTHORIZATION_EXTENSION, "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.")));
}
Aggregations