use of org.openlmis.stockmanagement.domain.card.StockCard in project openlmis-stockmanagement by OpenLMIS.
the class StockCardSummariesServiceTest method shouldFindStockCards.
@Test
public void shouldFindStockCards() throws Exception {
OrderableDto orderable = new OrderableDtoDataBuilder().build();
OrderableDto orderable2 = new OrderableDtoDataBuilder().build();
OrderableDto orderable3 = new OrderableDtoDataBuilder().build();
StockCardSummariesV2SearchParams params = new StockCardSummariesV2SearchParamsDataBuilder().withOrderableIds(asList(orderable.getId(), orderable2.getId())).build();
when(approvedProductReferenceDataService.getApprovedProducts(eq(params.getFacilityId()), eq(params.getProgramId()), eq(params.getOrderableIds()))).thenReturn(new PageImpl<>(asList(orderable, orderable2, orderable3), new PageRequest(0, Integer.MAX_VALUE), 3));
Map<UUID, OrderableFulfillDto> fulfillMap = new HashMap<>();
fulfillMap.put(orderable.getId(), new OrderableFulfillDtoDataBuilder().withCanFulfillForMe(asList(orderable2.getId(), orderable3.getId())).build());
fulfillMap.put(orderable2.getId(), new OrderableFulfillDtoDataBuilder().withCanFulfillForMe(asList(orderable.getId(), orderable3.getId())).build());
when(orderableFulfillReferenceDataService.findByIds(asList(orderable.getId(), orderable2.getId(), orderable3.getId()))).thenReturn(fulfillMap);
StockEvent event = new StockEventDataBuilder().withFacility(params.getFacilityId()).withProgram(params.getProgramId()).build();
StockCard stockCard = new StockCardDataBuilder(event).withOrderable(orderable.getId()).withStockOnHand(12).build();
StockCard stockCard1 = new StockCardDataBuilder(event).withOrderable(orderable3.getId()).withStockOnHand(26).build();
List<StockCard> stockCards = asList(stockCard, stockCard1);
when(cardRepository.findByProgramIdAndFacilityId(params.getProgramId(), params.getFacilityId())).thenReturn(stockCards);
StockCardSummaries result = stockCardSummariesService.findStockCards(params);
assertEquals(3, result.getPageOfApprovedProducts().size());
}
use of org.openlmis.stockmanagement.domain.card.StockCard in project openlmis-stockmanagement by OpenLMIS.
the class StockCardSummariesServiceTest method shouldReturnPageOfStockCards.
@Test
public void shouldReturnPageOfStockCards() throws Exception {
// given
UUID programId = randomUUID();
UUID facilityId = randomUUID();
PageRequest pageRequest = new PageRequest(0, 1);
UUID orderableId = randomUUID();
OrderableDto orderable = createOrderableDto(orderableId, "");
StockCard card = createStockCard(orderableId, randomUUID());
when(cardRepository.findByProgramIdAndFacilityId(programId, facilityId, pageRequest)).thenReturn(new PageImpl<>(singletonList(card), pageRequest, 10));
when(orderableReferenceDataService.findAll()).thenReturn(singletonList(orderable));
when(lotReferenceDataService.getAllLotsOf(any(UUID.class))).thenReturn(emptyList());
// when
Page<StockCardDto> stockCards = stockCardSummariesService.findStockCards(programId, facilityId, pageRequest);
// then
assertThat(stockCards.getContent().size(), is(1));
assertThat(stockCards.getTotalElements(), is(10L));
assertThat(stockCards.getContent().get(0).getExtraData().get("vvmStatus"), is("STAGE_2"));
}
use of org.openlmis.stockmanagement.domain.card.StockCard in project openlmis-stockmanagement by OpenLMIS.
the class StockCardSummariesServiceTest method createStockCard.
private StockCard createStockCard(UUID orderableId, UUID cardId) {
StockCard stockCard = new StockCard();
stockCard.setOrderableId(orderableId);
stockCard.setId(cardId);
Map<String, String> oldExtraData = new HashMap<>();
oldExtraData.put("vvmStatus", "STAGE_1");
Map<String, String> newExtraData = new HashMap<>();
newExtraData.put("vvmStatus", "STAGE_2");
StockCardLineItem lineItem1 = StockCardLineItem.builder().occurredDate(LocalDate.of(2017, 3, 17)).processedDate(of(2017, 3, 17, 15, 10, 31, 100, UTC)).quantity(1).extraData(oldExtraData).build();
StockCardLineItem lineItem2 = StockCardLineItem.builder().occurredDate(LocalDate.of(2017, 3, 18)).processedDate(of(2017, 3, 18, 15, 10, 31, 100, UTC)).quantity(1).extraData(newExtraData).build();
stockCard.setLineItems(asList(lineItem1, lineItem2, lineItem1));
return stockCard;
}
use of org.openlmis.stockmanagement.domain.card.StockCard in project openlmis-stockmanagement by OpenLMIS.
the class StockEventNotificationProcessorTest method setUp.
@Before
public void setUp() {
stockCard = new StockCard(null, facilityId, programId, orderableId, lotId, null, 0);
stockCard.setId(stockCardId);
context = mock(StockEventProcessContext.class);
stockEventDto = createStockEventDto();
stockEventDto.setUserId(userId);
stockEventDto.setProgramId(programId);
stockEventDto.setFacilityId(facilityId);
firstLineItem = stockEventDto.getLineItems().get(0);
firstLineItem.setOrderableId(orderableId);
firstLineItem.setLotId(lotId);
firstLineItem.setQuantity(0);
stockEventDto.setContext(context);
}
use of org.openlmis.stockmanagement.domain.card.StockCard in project openlmis-stockmanagement by OpenLMIS.
the class QuantityValidatorTest method shouldRejectWhenQuantityMakesStockOnHandBelowZero.
@Test
public void shouldRejectWhenQuantityMakesStockOnHandBelowZero() {
// expect
expectedException.expect(ValidationMessageException.class);
expectedException.expectMessage(ERROR_EVENT_DEBIT_QUANTITY_EXCEED_SOH);
// given
LocalDate firstDate = dateFromYear(2015);
StockCard card = new StockCard();
card.setLineItems(newArrayList(createCreditLineItem(firstDate.plusDays(1), 5), createDebitLineItem(firstDate.plusDays(3), 1), createCreditLineItem(firstDate.plusDays(4), 2)));
StockEventDto event = createDebitEventDto(firstDate.plusDays(2), 5);
mockCardFound(event, card);
// when
quantityValidator.validate(event);
}
Aggregations