public void testAddMetaDataOnEventDuringBeforeCommit() throws Exception {
UnitOfWork uow = DefaultUnitOfWork.startAndGet();
uow.registerListener(testSubject);
uow.publishEvent(GenericEventMessage.asEventMessage("test1"), mockEventBus);
StubAggregate aggregate = new StubAggregate();
uow.registerAggregate(aggregate, mockEventBus, mock(SaveAggregateCallback.class));
aggregate.doSomething();
uow.publishEvent(new GenericDomainEventMessage<Object>("id1", 1, "test1"), mockEventBus);
uow.commit();
assertEquals(3, publishedMessages.size());
assertTrue(publishedMessages.get(1) instanceof DomainEventMessage);
assertTrue(publishedMessages.get(2) instanceof DomainEventMessage);
assertEquals("test1", publishedMessages.get(0).getMetaData().get("test1"));
assertEquals("test2", publishedMessages.get(0).getMetaData().get("test2"));
assertEquals("test3", publishedMessages.get(0).getMetaData().get("test3"));
assertEquals("test1", publishedMessages.get(1).getMetaData().get("test1"));
assertEquals("test2", publishedMessages.get(1).getMetaData().get("test2"));
assertEquals("test3", publishedMessages.get(1).getMetaData().get("test3"));
assertSame(aggregate.getIdentifier(), ((DomainEventMessage) publishedMessages.get(1)).getAggregateIdentifier());
assertEquals("test1", publishedMessages.get(2).getMetaData().get("test1"));
assertEquals("test2", publishedMessages.get(2).getMetaData().get("test2"));
assertEquals("test3", publishedMessages.get(2).getMetaData().get("test3"));
}