use of org.graylog2.plugin.database.validators.ValidationResult in project graylog2-server by Graylog2.
the class NotificationDtoTest method testValidateEmailWithEmptyConfigParameters.
@Test
public void testValidateEmailWithEmptyConfigParameters() {
final EmailEventNotificationConfig emptyConfig = EmailEventNotificationConfig.Builder.create().sender("").subject("").bodyTemplate("").htmlBodyTemplate("").build();
final NotificationDto emptyNotification = getEmailNotification().toBuilder().config(emptyConfig).build();
final ValidationResult validationResult = emptyNotification.validate();
assertThat(validationResult.failed()).isTrue();
assertThat(validationResult.getErrors().size()).isEqualTo(3);
assertThat(validationResult.getErrors()).containsOnlyKeys("subject", "body", "recipients");
}
use of org.graylog2.plugin.database.validators.ValidationResult in project graylog2-server by Graylog2.
the class NotificationDtoTest method testValidHttpNotification.
@Test
public void testValidHttpNotification() {
final NotificationDto validNotification = getHttpNotification();
final ValidationResult validationResult = validNotification.validate();
assertThat(validationResult.failed()).isFalse();
assertThat(validationResult.getErrors().size()).isEqualTo(0);
}
use of org.graylog2.plugin.database.validators.ValidationResult in project graylog2-server by Graylog2.
the class ValidationExceptionMapperTest method testToResponse.
@Test
public void testToResponse() throws Exception {
final ExceptionMapper<ValidationException> mapper = new ValidationExceptionMapper();
final Map<String, List<ValidationResult>> validationErrors = ImmutableMap.of("foo", ImmutableList.of(new ValidationResult.ValidationFailed("foo failed")), "bar", ImmutableList.of(new ValidationResult.ValidationFailed("bar failed"), new ValidationResult.ValidationFailed("baz failed")));
@SuppressWarnings("ThrowableInstanceNeverThrown") final ValidationException exception = new ValidationException(validationErrors);
final Response response = mapper.toResponse(exception);
assertThat(response.getStatusInfo()).isEqualTo(Response.Status.BAD_REQUEST);
assertThat(response.getMediaType()).isEqualTo(MediaType.APPLICATION_JSON_TYPE);
assertThat(response.hasEntity()).isTrue();
assertThat(response.getEntity()).isInstanceOf(ValidationApiError.class);
final ValidationApiError responseEntity = (ValidationApiError) response.getEntity();
assertThat(responseEntity.message()).startsWith("Validation failed!");
assertThat(responseEntity.validationErrors()).containsKeys("foo", "bar");
assertThat(responseEntity.validationErrors().get("foo")).hasSize(1);
assertThat(responseEntity.validationErrors().get("bar")).hasSize(2);
}
use of org.graylog2.plugin.database.validators.ValidationResult in project graylog2-server by Graylog2.
the class UserImplTest method testLastNameLengthValidation.
@Test
public void testLastNameLengthValidation() {
user = new UserImpl(null, null, null);
ValidationResult result = user.getValidations().get(UserImpl.LAST_NAME).validate(StringUtils.repeat("*", 10));
assertTrue(result.passed());
result = user.getValidations().get(UserImpl.LAST_NAME).validate(StringUtils.repeat("*", 210));
assertFalse(result.passed());
}
use of org.graylog2.plugin.database.validators.ValidationResult in project graylog2-server by Graylog2.
the class UserImplTest method testFirstNameLengthValidation.
@Test
public void testFirstNameLengthValidation() {
user = new UserImpl(null, null, null);
ValidationResult result = user.getValidations().get(UserImpl.FIRST_NAME).validate(StringUtils.repeat("*", 10));
assertTrue(result.passed());
result = user.getValidations().get(UserImpl.FIRST_NAME).validate(StringUtils.repeat("*", 210));
assertFalse(result.passed());
}
Aggregations