@Test public void testDomainEventEntry_WrapEventsCorrectly() { Serializer serializer = new XStreamSerializer(); String payload = "Payload"; MetaData metaData = new MetaData(Collections.singletonMap("Key", "Value")); DomainEventMessage<String> event = new GenericDomainEventMessage<>( "type", randomUUID().toString(), 2L, payload, metaData, randomUUID().toString(), Instant.now()); DomainEventEntry eventEntry = new DomainEventEntry(event, serializer); assertEquals(event.getAggregateIdentifier(), eventEntry.getAggregateIdentifier()); assertEquals(event.getSequenceNumber(), eventEntry.getSequenceNumber()); assertEquals(event.getTimestamp(), eventEntry.getTimestamp()); assertEquals(payload, serializer.deserialize(eventEntry.getPayload())); assertEquals(metaData, serializer.deserialize(eventEntry.getMetaData())); assertEquals(byte[].class, eventEntry.getPayload().getContentType()); }
@Override public <S> Entry<S> loadSaga(Class<S> sagaType, String sagaIdentifier) { EntityManager entityManager = entityManagerProvider.getEntityManager(); List<SerializedSaga> serializedSagaList = entityManager .createNamedQuery(LOAD_SAGA_NAMED_QUERY, SerializedSaga.class) .setParameter("sagaId", sagaIdentifier) .setParameter("sagaType", getSagaTypeName(sagaType)) .setMaxResults(1) .getResultList(); if (serializedSagaList == null || serializedSagaList.isEmpty()) { return null; } SerializedSaga serializedSaga = serializedSagaList.get(0); S loadedSaga = serializer.deserialize(serializedSaga); if (injector != null) { injector.injectResources(loadedSaga); } Set<AssociationValue> associationValues = loadAssociationValues(entityManager, sagaType, sagaIdentifier); if (logger.isDebugEnabled()) { logger.debug( "Loaded saga id [{}] of type [{}]", sagaIdentifier, loadedSaga.getClass().getName()); } return new EntryImpl<>(associationValues, loadedSaga); }