Package org.axonframework.domain

Examples of org.axonframework.domain.DomainEventMessage


                                                      Collections.singletonMap("key", (Object) "Value"))));

        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(20, actualEvents.size());
        for (int t = 0; t < 20; t = t + 2) {
View Full Code Here


            return next != null && next.getSequenceNumber() <= lastSequenceNumber;
        }

        @Override
        public DomainEventMessage next() {
            DomainEventMessage itemToReturn = next;
            initializeNextItem();
            return itemToReturn;
        }
View Full Code Here

    @Override
    public DBObject[] createDocuments(String type, Serializer eventSerializer, List<DomainEventMessage> messages) {
        DBObject[] dbObjects = new DBObject[messages.size()];
        for (int i = 0, messagesSize = messages.size(); i < messagesSize; i++) {
            DomainEventMessage message = messages.get(i);
            dbObjects[i] = new EventEntry(type, message, eventSerializer).asDBObject();
        }
        return dbObjects;
    }
View Full Code Here

            storedEvents.put(key, lastEvent);
        }

        @Override
        public DomainEventStream readEvents(String type, Object identifier) {
            DomainEventMessage message = storedEvents.get(identifier.toString());
            if (message == null) {
                throw new EventStreamNotFoundException(type, identifier);
            }
            return new SimpleDomainEventStream(Collections.singletonList(message));
        }
View Full Code Here

            @Override
            public boolean matches(Object argument) {
                if (!(argument instanceof DomainEventMessage)) {
                    return false;
                }
                DomainEventMessage event = (DomainEventMessage) argument;
                return aggregateIdentifier.equals(event.getAggregateIdentifier())
                        && event.getSequenceNumber() == i;
            }
        };
    }
View Full Code Here

        protected Map<Object, List<DomainEventMessage>> store = new HashMap<Object, List<DomainEventMessage>>();

        @Override
        public void appendEvents(String identifier, DomainEventStream events) {
            while (events.hasNext()) {
                DomainEventMessage next = events.next();
                if (!store.containsKey(next.getAggregateIdentifier())) {
                    store.put(next.getAggregateIdentifier(), new ArrayList<DomainEventMessage>());
                }
                List<DomainEventMessage> eventList = store.get(next.getAggregateIdentifier());
                eventList.add(next);
            }
        }
View Full Code Here

    }

    @Test
    public void testCreateSnapshot() {
        UUID aggregateIdentifier = UUID.randomUUID();
        DomainEventMessage firstEvent = new GenericDomainEventMessage<String>(aggregateIdentifier, (long) 0,
                                                                              "Mock contents", MetaData.emptyInstance()
        );
        SimpleDomainEventStream eventStream = new SimpleDomainEventStream(firstEvent);
        EventSourcedAggregateRoot aggregate = mock(EventSourcedAggregateRoot.class);
        when(aggregate.getIdentifier()).thenReturn(aggregateIdentifier);
        when(mockAggregateFactory.createAggregate(aggregateIdentifier, firstEvent)).thenReturn(aggregate);

        DomainEventMessage snapshot =  testSubject.createSnapshot("test", aggregateIdentifier, eventStream);

        verify(mockAggregateFactory).createAggregate(aggregateIdentifier, firstEvent);
        assertSame(aggregate, snapshot.getPayload());
    }
View Full Code Here

        aggregate.commitEvents();

        DomainEventMessage<StubAggregate> first =
                new GenericDomainEventMessage<StubAggregate>(
                        aggregate.getIdentifier(), aggregate.getVersion(), aggregate);
        DomainEventMessage secondEvent = new GenericDomainEventMessage<String>(aggregateIdentifier, (long) 0,
                                                                               "Mock contents", MetaData.emptyInstance()
        );
        SimpleDomainEventStream eventStream = new SimpleDomainEventStream(first, secondEvent);

        when(mockAggregateFactory.createAggregate(any(), any(DomainEventMessage.class)))
                .thenAnswer(new Answer<Object>() {
                    @Override
                    public Object answer(InvocationOnMock invocation) throws Throwable {
                        return ((DomainEventMessage)invocation.getArguments()[1]).getPayload();
                    }
                });

        DomainEventMessage snapshot = testSubject.createSnapshot("test", aggregateIdentifier, eventStream);
        assertSame("Snapshotter did not recognize the aggregate snapshot", aggregate, snapshot.getPayload());

        verify(mockAggregateFactory).createAggregate(any(), any(DomainEventMessage.class));
    }
View Full Code Here

        testSubject.dispatch(new GenericCommandMessage<Object>(new CreateCommand(aggregateIdentifier)));

        testSubject.stop();

        DomainEventMessage lastEvent = inMemoryEventStore.storedEvents.get(aggregateIdentifier);

        // we expect 2 events, 1 from aggregate constructor, one from doSomething method invocation
        assertEquals(1, lastEvent.getSequenceNumber());
        // check that both events are published in a single call
        verify(eventBus).publish(isA(EventMessage.class), isA(EventMessage.class));
        assertEquals(aggregateIdentifier, lastEvent.getAggregateIdentifier());
    }
View Full Code Here

            storedEvents.put(key, lastEvent);
        }

        @Override
        public DomainEventStream readEvents(String type, Object identifier) {
            DomainEventMessage message = storedEvents.get(identifier.toString());
            if (message == null) {
                throw new EventStreamNotFoundException(type, identifier);
            }
            return new SimpleDomainEventStream(Collections.singletonList(message));
        }
View Full Code Here

TOP

Related Classes of org.axonframework.domain.DomainEventMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.