use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class StockCardServiceIntegrationTest method shouldSaveLineItemsWithProgramFacilityOrderableForNonFirstMovement.
@Test
public void shouldSaveLineItemsWithProgramFacilityOrderableForNonFirstMovement() throws Exception {
// given
// 1. there is an existing event that caused a stock card to exist
StockEventDto existingEventDto = createStockEventDto();
final StockEvent existingEvent = save(existingEventDto, randomUUID());
UUID orderableId = existingEventDto.getLineItems().get(0).getOrderableId();
// 2. and there is a new event coming
StockEventDto newEventDto = createStockEventDto();
newEventDto.setProgramId(existingEventDto.getProgramId());
newEventDto.setFacilityId(existingEventDto.getFacilityId());
newEventDto.getLineItems().get(0).setOrderableId(orderableId);
// when
long cardAmountBeforeSave = stockCardRepository.count();
UUID userId = randomUUID();
StockEvent savedNewEvent = save(newEventDto, userId);
long cardAmountAfterSave = stockCardRepository.count();
// then
StockCard savedCard = stockCardRepository.findByOriginEvent(existingEvent);
List<StockCardLineItem> lineItems = savedCard.getLineItems();
lineItems.sort(Comparator.comparing(StockCardLineItem::getProcessedDate));
StockCardLineItem latestLineItem = lineItems.get(lineItems.size() - 1);
assertThat(cardAmountAfterSave, is(cardAmountBeforeSave));
assertThat(latestLineItem.getOriginEvent().getId(), is(savedNewEvent.getId()));
assertThat(latestLineItem.getStockCard().getId(), is(savedCard.getId()));
assertThat(latestLineItem.getUserId(), is(userId));
}
use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class StockCardServiceIntegrationTest method shouldSaveStockCardLineItemsAndCreateStockCardForFirstMovement.
@Test
public void shouldSaveStockCardLineItemsAndCreateStockCardForFirstMovement() throws Exception {
// given
UUID userId = randomUUID();
StockEventDto stockEventDto = createStockEventDto();
StockEvent savedEvent = save(stockEventDto, userId);
// when
stockCardService.saveFromEvent(stockEventDto, savedEvent.getId());
// then
StockCard savedCard = stockCardRepository.findByOriginEvent(savedEvent);
StockCardLineItem firstLineItem = savedCard.getLineItems().get(0);
assertThat(firstLineItem.getUserId(), is(userId));
assertThat(firstLineItem.getSource().isRefDataFacility(), is(true));
assertThat(firstLineItem.getDestination().isRefDataFacility(), is(false));
assertThat(firstLineItem.getStockCard().getOriginEvent().getId(), is(savedEvent.getId()));
assertThat(firstLineItem.getStockCard().getFacilityId(), is(savedEvent.getFacilityId()));
assertThat(firstLineItem.getStockCard().getProgramId(), is(savedEvent.getProgramId()));
UUID orderableId = savedEvent.getLineItems().get(0).getOrderableId();
assertThat(firstLineItem.getStockCard().getOrderableId(), is(orderableId));
}
use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class StockCardServiceIntegrationTest method shouldReassignPhysicalInventoryReasonNames.
@Test
public void shouldReassignPhysicalInventoryReasonNames() throws Exception {
// given
StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
stockEventDto.getLineItems().get(0).setSourceId(null);
stockEventDto.getLineItems().get(0).setDestinationId(null);
stockEventDto.getLineItems().get(0).setReasonId(null);
StockEvent savedEvent = save(stockEventDto, randomUUID());
// when
UUID cardId = stockCardRepository.findByOriginEvent(savedEvent).getId();
StockCardDto card = stockCardService.findStockCardById(cardId);
// then
String reasonName = card.getLineItems().get(0).getLineItem().getReason().getName();
assertThat(reasonName, is("Overstock"));
}
use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class StockEventProcessorIntegrationTest method shouldSaveEventAndLineItemsAndCallNotificationsWhenValidationServicePasses.
@Test
public void shouldSaveEventAndLineItemsAndCallNotificationsWhenValidationServicePasses() throws Exception {
StockEventDto stockEventDto = createStockEventDto();
stockEventDto.setUserId(userId);
setContext(stockEventDto);
// when
stockEventProcessor.process(stockEventDto);
// then
assertSize(cardSize + 1, eventSize + 1, lineItemSize + 1);
verify(stockEventNotificationProcessor).callAllNotifications(stockEventDto);
}
use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class StockEventProcessorIntegrationTest method shouldSubmitPhysicalInventoryWhenEventIsAboutPhysicalInventory.
@Test
public void shouldSubmitPhysicalInventoryWhenEventIsAboutPhysicalInventory() throws Exception {
// given
StockEventDto stockEventDto = createStockEventDto();
stockEventDto.setUserId(userId);
stockEventDto.getLineItems().get(0).setReasonId(null);
stockEventDto.getLineItems().get(0).setSourceId(null);
stockEventDto.getLineItems().get(0).setDestinationId(null);
setContext(stockEventDto);
// when
stockEventProcessor.process(stockEventDto);
// then
verify(physicalInventoryService).submitPhysicalInventory(any(PhysicalInventoryDto.class), any(UUID.class));
}
Aggregations