entityManager.clear();
DomainEventStream events = testSubject.readEvents("test", aggregate1.getIdentifier());
List<DomainEventMessage> actualEvents = new ArrayList<DomainEventMessage>();
while (events.hasNext()) {
DomainEventMessage event = events.next();
event.getPayload();
event.getMetaData();
actualEvents.add(event);
}
assertEquals(aggregate1.getUncommittedEventCount(), actualEvents.size());
/// we make sure persisted events have the same MetaData alteration logic
DomainEventStream other = testSubject.readEvents("test", aggregate2.getIdentifier());
assertTrue(other.hasNext());
DomainEventMessage messageWithMetaData = other.next();
DomainEventMessage altered = messageWithMetaData.withMetaData(Collections.singletonMap("key2",
(Object) "value"));
DomainEventMessage combined = messageWithMetaData.andMetaData(Collections.singletonMap("key2",
(Object) "value"));
assertTrue(altered.getMetaData().containsKey("key2"));
altered.getPayload();
assertFalse(altered.getMetaData().containsKey("key"));
assertTrue(altered.getMetaData().containsKey("key2"));
assertTrue(combined.getMetaData().containsKey("key"));
assertTrue(combined.getMetaData().containsKey("key2"));
assertNotNull(messageWithMetaData.getPayload());
assertNotNull(messageWithMetaData.getMetaData());
assertFalse(messageWithMetaData.getMetaData().isEmpty());
}