use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class TaskExtensionTest method shouldTalkToPluginToValidatePluginSettings.
@Test
public void shouldTalkToPluginToValidatePluginSettings() throws Exception {
extension.registerHandler("1.0", pluginSettingsJSONMessageHandler);
extension.messageHandlerMap.put("1.0", jsonMessageHandler);
String requestBody = "expected-request";
when(pluginSettingsJSONMessageHandler.requestMessageForPluginSettingsValidation(pluginSettingsConfiguration)).thenReturn(requestBody);
String responseBody = "expected-response";
ValidationResult deserializedResponse = new ValidationResult();
when(pluginSettingsJSONMessageHandler.responseMessageForPluginSettingsValidation(responseBody)).thenReturn(deserializedResponse);
when(pluginManager.isPluginOfType(PLUGGABLE_TASK_EXTENSION, pluginId)).thenReturn(true);
when(pluginManager.submitTo(eq(pluginId), eq(PLUGGABLE_TASK_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody));
ValidationResult response = extension.validatePluginSettings(pluginId, pluginSettingsConfiguration);
assertRequest(requestArgumentCaptor.getValue(), PLUGGABLE_TASK_EXTENSION, "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 JsonMessageHandler1_0Test method shouldBuildValidationResultFromCheckSCMConfigurationValidResponse.
@Test
public void shouldBuildValidationResultFromCheckSCMConfigurationValidResponse() throws Exception {
String responseBody = "[{\"key\":\"key-one\",\"message\":\"incorrect value\"},{\"message\":\"general error\"}]";
ValidationResult validationResult = messageHandler.responseMessageForIsSCMConfigurationValid(responseBody);
assertValidationError(validationResult.getErrors().get(0), "key-one", "incorrect value");
assertValidationError(validationResult.getErrors().get(1), "", "general error");
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class SCMExtensionTest method shouldTalkToPluginToCheckIfSCMConfigurationIsValid.
@Test
public void shouldTalkToPluginToCheckIfSCMConfigurationIsValid() throws Exception {
when(jsonMessageHandler.requestMessageForIsSCMConfigurationValid(scmPropertyConfiguration)).thenReturn(requestBody);
ValidationResult deserializedResponse = new ValidationResult();
when(jsonMessageHandler.responseMessageForIsSCMConfigurationValid(responseBody)).thenReturn(deserializedResponse);
ValidationResult response = scmExtension.isSCMConfigurationValid(PLUGIN_ID, scmPropertyConfiguration);
assertRequest(requestArgumentCaptor.getValue(), SCM_EXTENSION, "1.0", SCMExtension.REQUEST_VALIDATE_SCM_CONFIGURATION, requestBody);
verify(jsonMessageHandler).requestMessageForIsSCMConfigurationValid(scmPropertyConfiguration);
verify(jsonMessageHandler).responseMessageForIsSCMConfigurationValid(responseBody);
assertSame(response, deserializedResponse);
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult 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, "{}");
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class ElasticAgentExtensionV3Test 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 = extensionV3.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("3.0", REQUEST_VALIDATE_PROFILE, "{}");
}
Aggregations