@Test @DisplayName("validate event messages") void validateEventMessages() { Event eventWithDefaultMessage = Event .newBuilder() .setMessage(pack(ProjectCreated.getDefaultInstance())) .build(); EventValidator eventValidator = new EventValidator(); Optional<MessageInvalid> error = eventValidator.validate( EventEnvelope.of(eventWithDefaultMessage) ); assertTrue(error.isPresent()); Error actualError = error.get().asError(); assertEquals(EventValidationError.getDescriptor().getFullName(), actualError.getType()); }
@Override public Optional<MessageInvalid> validate(EventEnvelope event) { checkNotNull(event); Event outerObject = event.outerObject(); List<ConstraintViolation> violations = Validate.violationsOf(outerObject); if (violations.isEmpty()) { return Optional.empty(); } EventMessage message = event.message(); MessageInvalid result = onConstraintViolations(message, violations); return Optional.of(result); }
EventValidator implements EnvelopeValidator<EventEnvelope> { @Override public Optional<MessageInvalid> validate(EventEnvelope event) { checkNotNull(event); Event outerObject = event.outerObject(); List<ConstraintViolation> violations = Validate.violationsOf(outerObject); if (violations.isEmpty()) { return Optional.empty(); } EventMessage message = event.message(); MessageInvalid result = onConstraintViolations(message, violations); return Optional.of(result); } }
EventValidator implements EnvelopeValidator<EventEnvelope> { @Override public Optional<MessageInvalid> validate(EventEnvelope event) { checkNotNull(event); Event outerObject = event.outerObject(); List<ConstraintViolation> violations = Validate.violationsOf(outerObject); if (violations.isEmpty()) { return Optional.empty(); } EventMessage message = event.message(); MessageInvalid result = onConstraintViolations(message, violations); return Optional.of(result); }  }
EventValidator implements EnvelopeValidator<EventEnvelope> { @Override public Optional<MessageInvalid> validate(EventEnvelope event) { checkNotNull(event); Event outerObject = event.outerObject(); List<ConstraintViolation> violations = Validate.violationsOf(outerObject); if (violations.isEmpty()) { return Optional.empty(); } EventMessage message = event.message(); MessageInvalid result = onConstraintViolations(message, violations); return Optional.of(result); }  @Override Optional<MessageInvalid> validate(EventEnvelope event); }
EventValidator implements EnvelopeValidator<EventEnvelope> { @Override public Optional<MessageInvalid> validate(EventEnvelope event) { checkNotNull(event); Event outerObject = event.outerObject(); List<ConstraintViolation> violations = Validate.violationsOf(outerObject); if (violations.isEmpty()) { return Optional.empty(); } EventMessage message = event.message(); MessageInvalid result = onConstraintViolations(message, violations); return Optional.of(result); }  @Override Optional<MessageInvalid> validate(EventEnvelope event);  }