Search in sources :

Example 26 with StockCard

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

Example 27 with StockCard

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"));
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) PageRequest(org.springframework.data.domain.PageRequest) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 28 with StockCard

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;
}
Also used : HashMap(java.util.HashMap) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) UUID.fromString(java.util.UUID.fromString)

Example 29 with 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);
}
Also used : StockCard(org.openlmis.stockmanagement.domain.card.StockCard) StockEventProcessContext(org.openlmis.stockmanagement.util.StockEventProcessContext) Before(org.junit.Before)

Example 30 with StockCard

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);
}
Also used : StockCard(org.openlmis.stockmanagement.domain.card.StockCard) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Aggregations

StockCard (org.openlmis.stockmanagement.domain.card.StockCard)35 Test (org.junit.Test)20 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)12 UUID (java.util.UUID)11 StockCardLineItem (org.openlmis.stockmanagement.domain.card.StockCardLineItem)11 LocalDate (java.time.LocalDate)10 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)9 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)6 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)6 StockCardDto (org.openlmis.stockmanagement.dto.StockCardDto)6 List (java.util.List)5 FacilityDto (org.openlmis.stockmanagement.dto.referencedata.FacilityDto)5 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)5 UUID.randomUUID (java.util.UUID.randomUUID)4 StockEventLineItemDto (org.openlmis.stockmanagement.dto.StockEventLineItemDto)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Node (org.openlmis.stockmanagement.domain.sourcedestination.Node)3 LotDto (org.openlmis.stockmanagement.dto.referencedata.LotDto)3 ProgramDto (org.openlmis.stockmanagement.dto.referencedata.ProgramDto)3