Search in sources :

Example 1 with EntityEvent

use of com.kloia.eventapis.cassandra.EntityEvent 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 EntityEvent

use of com.kloia.eventapis.cassandra.EntityEvent 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 EntityEvent

use of com.kloia.eventapis.cassandra.EntityEvent 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 EntityEvent

use of com.kloia.eventapis.cassandra.EntityEvent 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 EntityEvent

use of com.kloia.eventapis.cassandra.EntityEvent in project eventapis by kloiasoft.

the class CompositeRepositoryImplTest method shouldRecordAndPublishWithPreviousEventAndPublishedEventAndConcurrencyResolverFactory.

@Test
public void shouldRecordAndPublishWithPreviousEventAndPublishedEventAndConcurrencyResolverFactory() throws JsonProcessingException, EventStoreException, ConcurrentEventException {
    mockCommon(intermediateEvent);
    Entity previousEntity = mock(Entity.class);
    EventKey previousEntityEventKey = new EventKey();
    when(previousEntity.getEventKey()).thenReturn(previousEntityEventKey);
    ConcurrencyResolver concurrencyResolver = mock(ConcurrencyResolver.class);
    Function<EntityEvent, ConcurrencyResolver<ConcurrentEventException>> factory = entityEvent -> concurrencyResolver;
    EventKey actual = compositeRepository.recordAndPublish(previousEntity, 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) Entity(com.kloia.eventapis.view.Entity) 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)

Aggregations

DefaultConcurrencyResolver (com.kloia.eventapis.cassandra.DefaultConcurrencyResolver)5 EntityEvent (com.kloia.eventapis.cassandra.EntityEvent)5 EventKey (com.kloia.eventapis.common.EventKey)5 Test (org.junit.Test)5 Entity (com.kloia.eventapis.view.Entity)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 IdCreationStrategy (com.kloia.eventapis.api.IdCreationStrategy)2 Views (com.kloia.eventapis.api.Views)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 EventStoreException (com.kloia.eventapis.exception.EventStoreException)2 IOperationRepository (com.kloia.eventapis.kafka.IOperationRepository)2 SerializableConsumer (com.kloia.eventapis.kafka.SerializableConsumer)2 Event (com.kloia.eventapis.pojos.Event)2