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));
}
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));
}
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));
}
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));
}
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;
}
Aggregations