use of org.openlmis.stockmanagement.domain.card.StockCard in project openlmis-stockmanagement by OpenLMIS.
the class StockCardServiceTest method shouldNotDuplicateCardsForOrderableLots.
@Test
public void shouldNotDuplicateCardsForOrderableLots() {
StockEventDto event = StockEventDtoDataBuilder.createStockEventDtoWithTwoLineItems();
event.setContext(mock(StockEventProcessContext.class));
UUID savedEventId = UUID.randomUUID();
stockCardService.saveFromEvent(event, savedEventId);
verify(cardRepository).save(cardCaptor.capture());
List<StockCard> saved = cardCaptor.getValue();
assertThat(saved, hasSize(1));
StockCard card = saved.get(0);
assertThat(card.getFacilityId(), equalTo(event.getFacilityId()));
assertThat(card.getProgramId(), equalTo(event.getProgramId()));
assertThat(card.getOrderableId(), equalTo(event.getLineItems().get(0).getOrderableId()));
assertThat(card.getLotId(), equalTo(event.getLineItems().get(0).getLotId()));
assertThat(card.getOrderableId(), equalTo(event.getLineItems().get(1).getOrderableId()));
assertThat(card.getLotId(), equalTo(event.getLineItems().get(1).getLotId()));
assertThat(card.getLineItems(), hasSize(2));
}
use of org.openlmis.stockmanagement.domain.card.StockCard in project openlmis-stockmanagement by OpenLMIS.
the class StockEventNotificationProcessorTest method shouldCallStockoutNotifierForEveryCard.
@Test
public void shouldCallStockoutNotifierForEveryCard() throws Exception {
// given
UUID anotherStockCardId = UUID.randomUUID();
UUID anotherOrderableId = UUID.randomUUID();
UUID anotherLotId = UUID.randomUUID();
StockCard anotherStockCard = new StockCard(null, facilityId, programId, orderableId, lotId, null, 0);
anotherStockCard.setId(anotherStockCardId);
StockEventLineItemDto secondLineItem = createStockEventLineItem();
secondLineItem.setOrderableId(anotherOrderableId);
secondLineItem.setLotId(anotherLotId);
secondLineItem.setQuantity(0);
stockEventDto.setLineItems(Arrays.asList(firstLineItem, secondLineItem));
when(context.findCard(new OrderableLotIdentity(orderableId, lotId))).thenReturn(stockCard);
when(context.findCard(new OrderableLotIdentity(anotherOrderableId, anotherLotId))).thenReturn(anotherStockCard);
// when
stockEventNotificationProcessor.callAllNotifications(stockEventDto);
// then
verify(stockoutNotifier, times(2)).notifyStockEditors(any(StockCard.class));
}
use of org.openlmis.stockmanagement.domain.card.StockCard in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryServiceTest method shouldSubmitPhysicalInventory.
@Test
public void shouldSubmitPhysicalInventory() throws Exception {
PhysicalInventoryDto physicalInventoryDto = newInventoryForSubmit();
int previousSoH = new Random().nextInt();
when(stockCardRepository.findByProgramIdAndFacilityId(physicalInventoryDto.getProgramId(), physicalInventoryDto.getFacilityId())).thenReturn(singletonList(stockCard));
StockCard cloneOfCard = mockCloneOfCard(previousSoH);
when(stockCard.getOrderableId()).thenReturn(lineItemDto.getOrderableId());
when(stockCard.getLotId()).thenReturn(lineItemDto.getLotId());
when(stockCard.shallowCopy()).thenReturn(cloneOfCard);
physicalInventoryService.submitPhysicalInventory(physicalInventoryDto, UUID.randomUUID());
verify(physicalInventoryRepository, times(1)).save(inventoryArgumentCaptor.capture());
verify(stockCard).shallowCopy();
verify(cloneOfCard).calculateStockOnHand();
verifyPhysicalInventorySavedWithSohAndAsDraft(previousSoH);
}
use of org.openlmis.stockmanagement.domain.card.StockCard in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryServiceTest method mockCloneOfCard.
private StockCard mockCloneOfCard(int previousSoH) {
StockCard cloneOfCard = mock(StockCard.class);
when(cloneOfCard.getStockOnHand()).thenReturn(previousSoH);
return cloneOfCard;
}
use of org.openlmis.stockmanagement.domain.card.StockCard in project openlmis-stockmanagement by OpenLMIS.
the class QuantityValidator method tryFindCard.
private StockCard tryFindCard(StockEventDto event, StockEventLineItemDto lineItem) {
StockCard foundCard = event.getContext().findCard(OrderableLotIdentity.identityOf(lineItem));
if (foundCard == null) {
StockCard emptyCard = new StockCard();
emptyCard.setLineItems(new ArrayList<>());
return emptyCard;
} else {
// Model will be modified so we need to copy stock card to avoid persistence of modified model.
return foundCard.shallowCopy();
}
}
Aggregations