use of io.spine.validate.MessageValidator in project core-java by SpineEventEngine.
the class EventBusShould method call_onError_if_event_is_invalid.
@Test
public void call_onError_if_event_is_invalid() {
final MessageValidator validator = mock(MessageValidator.class);
doReturn(newArrayList(ConstraintViolation.getDefaultInstance())).when(validator).validate(any(Message.class));
final EventBus eventBus = EventBus.newBuilder().setStorageFactory(storageFactory).setEventValidator(validator).build();
eventBus.register(new ProjectCreatedSubscriber());
final boolean isValid = eventBus.validate(Given.EventMessage.projectCreated(), responseObserver);
assertFalse(isValid);
assertReturnedExceptionAndNoResponse(InvalidEventException.class, responseObserver);
}
use of io.spine.validate.MessageValidator in project core-java by SpineEventEngine.
the class EventBusBuilderShould method allow_custom_message_validators.
@Test
public void allow_custom_message_validators() {
final StorageFactory storageFactory = StorageFactorySwitch.newInstance(newName("test"), false).get();
final MessageValidator validator = mock(MessageValidator.class);
final EventBus eventBus = builder().setEventValidator(validator).setStorageFactory(storageFactory).build();
assertEquals(validator, eventBus.getMessageValidator());
}
use of io.spine.validate.MessageValidator in project core-java by SpineEventEngine.
the class EventValidatorShould method validate_event_messages.
@Test
public void validate_event_messages() {
final MessageValidator messageValidator = mock(MessageValidator.class);
when(messageValidator.validate(any(Message.class))).thenReturn(newArrayList(ConstraintViolation.getDefaultInstance(), ConstraintViolation.getDefaultInstance()));
final Event event = eventFactory.createEvent(Sample.messageOfType(ProjectCreated.class));
final EventValidator eventValidator = new EventValidator(messageValidator);
final Optional<MessageInvalid> error = eventValidator.validate(EventEnvelope.of(event));
assertTrue(error.isPresent());
final Error actualError = error.get().asError();
assertEquals(EventValidationError.getDescriptor().getFullName(), actualError.getType());
}
use of io.spine.validate.MessageValidator in project core-java by SpineEventEngine.
the class EventBusBuilderShould method return_set_EventValidator.
@Test
public void return_set_EventValidator() {
final MessageValidator validator = MessageValidator.newInstance();
assertEquals(validator, builder().setEventValidator(validator).getEventValidator().get());
}
Aggregations