Search in sources :

Example 1 with EventKey

use of com.kloia.eventapis.common.EventKey in project eventapis by kloiasoft.

the class CompositeRepositoryImplTest method shouldRecordAndPublishWithPublishedEvent.

@Test
public void shouldRecordAndPublishWithPublishedEvent() throws ConcurrentEventException, EventStoreException, JsonProcessingException {
    mockCommon(intermediateEvent);
    EventKey actual = compositeRepository.recordAndPublish(intermediateEvent);
    assertCommon(intermediateEvent);
    assertThat(actual, equalTo(eventKey));
    assertThat(previousEventKeyCaptor.getValue(), equalTo(Optional.empty()));
    assertThat(concurrencyResolverFactoryCaptor.getValue().apply(new EntityEvent()).getClass(), equalTo(DefaultConcurrencyResolver.class));
}
Also used : DefaultConcurrencyResolver(com.kloia.eventapis.cassandra.DefaultConcurrencyResolver) EntityEvent(com.kloia.eventapis.cassandra.EntityEvent) EventKey(com.kloia.eventapis.common.EventKey) Test(org.junit.Test)

Example 2 with EventKey

use of com.kloia.eventapis.common.EventKey in project eventapis by kloiasoft.

the class CompositeRepositoryImplTest method shouldRecordAndPublishWithPreviousEventAndPublishedEvent.

@Test
public void shouldRecordAndPublishWithPreviousEventAndPublishedEvent() throws JsonProcessingException, EventStoreException, ConcurrentEventException {
    mockCommon(intermediateEvent);
    Entity previousEntity = mock(Entity.class);
    EventKey previousEntityEventKey = new EventKey();
    when(previousEntity.getEventKey()).thenReturn(previousEntityEventKey);
    EventKey actual = compositeRepository.recordAndPublish(previousEntity, intermediateEvent);
    assertCommon(intermediateEvent);
    assertThat(actual, equalTo(eventKey));
    assertThat(previousEventKeyCaptor.getValue().isPresent(), equalTo(true));
    assertThat(previousEventKeyCaptor.getValue().get(), equalTo(previousEntityEventKey));
    assertThat(concurrencyResolverFactoryCaptor.getValue().apply(new EntityEvent()).getClass(), equalTo(DefaultConcurrencyResolver.class));
}
Also used : Entity(com.kloia.eventapis.view.Entity) DefaultConcurrencyResolver(com.kloia.eventapis.cassandra.DefaultConcurrencyResolver) EntityEvent(com.kloia.eventapis.cassandra.EntityEvent) EventKey(com.kloia.eventapis.common.EventKey) Test(org.junit.Test)

Example 3 with EventKey

use of com.kloia.eventapis.common.EventKey in project eventapis by kloiasoft.

the class CompositeRepositoryImplTest method shouldRecordAndPublishWithPreviousEventKeyAndPublishedEvent.

@Test
public void shouldRecordAndPublishWithPreviousEventKeyAndPublishedEvent() throws JsonProcessingException, EventStoreException, ConcurrentEventException {
    mockCommon(intermediateEvent);
    EventKey previousEntityEventKey = new EventKey();
    EventKey actual = compositeRepository.recordAndPublish(previousEntityEventKey, intermediateEvent);
    assertCommon(intermediateEvent);
    assertThat(actual, equalTo(eventKey));
    assertThat(previousEventKeyCaptor.getValue().isPresent(), equalTo(true));
    assertThat(previousEventKeyCaptor.getValue().get(), equalTo(previousEntityEventKey));
    assertThat(concurrencyResolverFactoryCaptor.getValue().apply(new EntityEvent()).getClass(), equalTo(DefaultConcurrencyResolver.class));
}
Also used : DefaultConcurrencyResolver(com.kloia.eventapis.cassandra.DefaultConcurrencyResolver) EntityEvent(com.kloia.eventapis.cassandra.EntityEvent) EventKey(com.kloia.eventapis.common.EventKey) Test(org.junit.Test)

Example 4 with EventKey

use of com.kloia.eventapis.common.EventKey in project eventapis by kloiasoft.

the class CompositeRepositoryImplTest method shouldRecordAndPublishWithPreviousEventKeyAndPublishedEventAndConcurrencyResolverFactory.

@Test
public void shouldRecordAndPublishWithPreviousEventKeyAndPublishedEventAndConcurrencyResolverFactory() throws JsonProcessingException, EventStoreException, ConcurrentEventException {
    mockCommon(intermediateEvent);
    EventKey previousEntityEventKey = new EventKey();
    ConcurrencyResolver concurrencyResolver = mock(ConcurrencyResolver.class);
    Function<EntityEvent, ConcurrencyResolver<ConcurrentEventException>> factory = entityEvent -> concurrencyResolver;
    EventKey actual = compositeRepository.recordAndPublish(previousEntityEventKey, intermediateEvent, factory);
    assertCommon(intermediateEvent);
    assertThat(actual, equalTo(eventKey));
    assertThat(previousEventKeyCaptor.getValue().isPresent(), equalTo(true));
    assertThat(previousEventKeyCaptor.getValue().get(), equalTo(previousEntityEventKey));
    assertThat(concurrencyResolverFactoryCaptor.getValue(), equalTo(factory));
}
Also used : ConcurrencyResolver(com.kloia.eventapis.cassandra.ConcurrencyResolver) SerializableConsumer(com.kloia.eventapis.kafka.SerializableConsumer) IdCreationStrategy(com.kloia.eventapis.api.IdCreationStrategy) Mock(org.mockito.Mock) EventKey(com.kloia.eventapis.common.EventKey) Entity(com.kloia.eventapis.view.Entity) DefaultConcurrencyResolver(com.kloia.eventapis.cassandra.DefaultConcurrencyResolver) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) EventRecorder(com.kloia.eventapis.common.EventRecorder) IOperationRepository(com.kloia.eventapis.kafka.IOperationRepository) Captor(org.mockito.Captor) Function(java.util.function.Function) Assert.assertThat(org.junit.Assert.assertThat) Mockito.doThrow(org.mockito.Mockito.doThrow) ArgumentCaptor(org.mockito.ArgumentCaptor) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) Matchers.anyLong(org.mockito.Matchers.anyLong) UUIDCreationStrategy(com.kloia.eventapis.api.impl.UUIDCreationStrategy) ExpectedException(org.junit.rules.ExpectedException) EventStoreException(com.kloia.eventapis.exception.EventStoreException) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) PublishedEvent(com.kloia.eventapis.common.PublishedEvent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConcurrentEventException(com.kloia.eventapis.cassandra.ConcurrentEventException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) EventState(com.kloia.eventapis.pojos.EventState) Mockito.when(org.mockito.Mockito.when) EventType(com.kloia.eventapis.common.EventType) Mockito.verify(org.mockito.Mockito.verify) Rule(org.junit.Rule) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) Views(com.kloia.eventapis.api.Views) Matchers.equalTo(org.hamcrest.Matchers.equalTo) EntityEvent(com.kloia.eventapis.cassandra.EntityEvent) Event(com.kloia.eventapis.pojos.Event) Optional(java.util.Optional) Mockito.mock(org.mockito.Mockito.mock) ConcurrencyResolver(com.kloia.eventapis.cassandra.ConcurrencyResolver) DefaultConcurrencyResolver(com.kloia.eventapis.cassandra.DefaultConcurrencyResolver) EntityEvent(com.kloia.eventapis.cassandra.EntityEvent) EventKey(com.kloia.eventapis.common.EventKey) Test(org.junit.Test)

Example 5 with EventKey

use of com.kloia.eventapis.common.EventKey in project eventapis by kloiasoft.

the class AddStockCommandHandler method execute.

@RequestMapping(value = "/stock/{stockId}/add", method = RequestMethod.POST)
@Command()
public EventKey execute(String stockId, @RequestBody AddStockCommandDto dto) throws Exception {
    dto.setStockId(stockId);
    Stock stock = stockQuery.queryEntity(dto.getStockId());
    if (dto.getStockToAdd() > 1000000)
        throw new IllegalArgumentException("Invalid Stock to Add");
    EventKey eventKey = eventRepository.recordAndPublish(stock.getEventKey(), new StockAddedEvent(dto.getStockToAdd()));
    return eventKey;
}
Also used : StockAddedEvent(com.kloia.sample.dto.event.StockAddedEvent) EventKey(com.kloia.eventapis.common.EventKey) Stock(com.kloia.sample.model.Stock) Command(com.kloia.eventapis.api.Command) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

EventKey (com.kloia.eventapis.common.EventKey)11 DefaultConcurrencyResolver (com.kloia.eventapis.cassandra.DefaultConcurrencyResolver)5 EntityEvent (com.kloia.eventapis.cassandra.EntityEvent)5 EventStoreException (com.kloia.eventapis.exception.EventStoreException)5 Test (org.junit.Test)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 Views (com.kloia.eventapis.api.Views)4 Entity (com.kloia.eventapis.view.Entity)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 Command (com.kloia.eventapis.api.Command)2 IdCreationStrategy (com.kloia.eventapis.api.IdCreationStrategy)2 UUIDCreationStrategy (com.kloia.eventapis.api.impl.UUIDCreationStrategy)2 ConcurrencyResolver (com.kloia.eventapis.cassandra.ConcurrencyResolver)2 ConcurrentEventException (com.kloia.eventapis.cassandra.ConcurrentEventException)2 EventRecorder (com.kloia.eventapis.common.EventRecorder)2 EventType (com.kloia.eventapis.common.EventType)2 PublishedEvent (com.kloia.eventapis.common.PublishedEvent)2 IOperationRepository (com.kloia.eventapis.kafka.IOperationRepository)2 SerializableConsumer (com.kloia.eventapis.kafka.SerializableConsumer)2