Search in sources :

Example 1 with ValidationError

use of org.zalando.nakadi.validation.ValidationError in project nakadi by zalando.

the class EventPublisherTest method mockFaultValidation.

private void mockFaultValidation(final EventType eventType, final String error) throws Exception {
    final EventTypeValidator faultyValidator = mock(EventTypeValidator.class);
    Mockito.doReturn(eventType).when(cache).getEventType(eventType.getName());
    Mockito.doReturn(faultyValidator).when(cache).getValidator(eventType.getName());
    Mockito.doReturn(Optional.of(new ValidationError(error))).when(faultyValidator).validate(any());
}
Also used : EventTypeValidator(org.zalando.nakadi.validation.EventTypeValidator) ValidationError(org.zalando.nakadi.validation.ValidationError)

Example 2 with ValidationError

use of org.zalando.nakadi.validation.ValidationError in project nakadi by zalando.

the class EventPublisher method validateSchema.

private void validateSchema(final JSONObject event, final EventType eventType) throws EventValidationException, InternalNakadiException, NoSuchEventTypeException {
    final EventTypeValidator validator = eventTypeCache.getValidator(eventType.getName());
    final Optional<ValidationError> validationError = validator.validate(event);
    if (validationError.isPresent()) {
        throw new EventValidationException(validationError.get());
    }
}
Also used : EventValidationException(org.zalando.nakadi.exceptions.EventValidationException) EventTypeValidator(org.zalando.nakadi.validation.EventTypeValidator) ValidationError(org.zalando.nakadi.validation.ValidationError)

Aggregations

EventTypeValidator (org.zalando.nakadi.validation.EventTypeValidator)2 ValidationError (org.zalando.nakadi.validation.ValidationError)2 EventValidationException (org.zalando.nakadi.exceptions.EventValidationException)1