use of com.thoughtworks.go.plugin.domain.common.ValidationError in project gocd by gocd.
the class SecurityAuthConfigServiceTest method verifyConnection_shouldFailForAInvalidAuthConfig.
@Test
public void verifyConnection_shouldFailForAInvalidAuthConfig() throws Exception {
SecurityAuthConfig ldap = new SecurityAuthConfig("ldap", "cd.go.ldap", new ConfigurationProperty(new ConfigurationKey("username"), new ConfigurationValue()));
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("password", "Password cannot be blank"));
validationResult.addError(new ValidationError("username", "Username cannot be blank"));
VerifyConnectionResponse validationFailed = new VerifyConnectionResponse("validation-failed", "Connection check passed", validationResult);
when(extension.verifyConnection("cd.go.ldap", ldap.getConfigurationAsMap(true))).thenReturn(validationFailed);
VerifyConnectionResponse response = securityAuthConfigService.verifyConnection(ldap);
assertThat(response, is(validationFailed));
assertThat(ldap.getProperty("username").errors().get("username").get(0), is("Username cannot be blank"));
assertThat(ldap.getProperty("password").errors().get("password").get(0), is("Password cannot be blank"));
}
use of com.thoughtworks.go.plugin.domain.common.ValidationError in project gocd by gocd.
the class SecurityAuthConfigService method mapErrors.
private void mapErrors(VerifyConnectionResponse response, SecurityAuthConfig authConfig) {
com.thoughtworks.go.plugin.domain.common.ValidationResult validationResult = response.getValidationResult();
if (validationResult == null) {
return;
}
for (ValidationError error : validationResult.getErrors()) {
ConfigurationProperty property = authConfig.getProperty(error.getKey());
if (property == null) {
authConfig.addNewConfiguration(error.getKey(), false);
property = authConfig.getProperty(error.getKey());
}
property.addError(error.getKey(), error.getMessage());
}
}
Aggregations