Search in sources :

Example 1 with OrderableFulfillDto

use of org.openlmis.stockmanagement.dto.referencedata.OrderableFulfillDto 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());
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) HashMap(java.util.HashMap) StockCardDataBuilder(org.openlmis.stockmanagement.testutils.StockCardDataBuilder) OrderableFulfillDtoDataBuilder(org.openlmis.stockmanagement.testutils.OrderableFulfillDtoDataBuilder) OrderableFulfillDto(org.openlmis.stockmanagement.dto.referencedata.OrderableFulfillDto) PageRequest(org.springframework.data.domain.PageRequest) StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) OrderableDtoDataBuilder(org.openlmis.stockmanagement.testutils.OrderableDtoDataBuilder) StockEventDataBuilder(org.openlmis.stockmanagement.testutils.StockEventDataBuilder) StockCardSummariesV2SearchParamsDataBuilder(org.openlmis.stockmanagement.testutils.StockCardSummariesV2SearchParamsDataBuilder) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 UUID.randomUUID (java.util.UUID.randomUUID)1 Test (org.junit.Test)1 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)1 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)1 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)1 OrderableFulfillDto (org.openlmis.stockmanagement.dto.referencedata.OrderableFulfillDto)1 OrderableDtoDataBuilder (org.openlmis.stockmanagement.testutils.OrderableDtoDataBuilder)1 OrderableFulfillDtoDataBuilder (org.openlmis.stockmanagement.testutils.OrderableFulfillDtoDataBuilder)1 StockCardDataBuilder (org.openlmis.stockmanagement.testutils.StockCardDataBuilder)1 StockCardSummariesV2SearchParamsDataBuilder (org.openlmis.stockmanagement.testutils.StockCardSummariesV2SearchParamsDataBuilder)1 StockEventDataBuilder (org.openlmis.stockmanagement.testutils.StockEventDataBuilder)1 PageRequest (org.springframework.data.domain.PageRequest)1