Search in sources :

Example 1 with StockCard

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));
}
Also used : StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) UUID(java.util.UUID) StockEventProcessContext(org.openlmis.stockmanagement.util.StockEventProcessContext) Test(org.junit.Test)

Example 2 with StockCard

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));
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto) OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with StockCard

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);
}
Also used : Random(java.util.Random) PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) Test(org.junit.Test)

Example 4 with StockCard

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;
}
Also used : StockCard(org.openlmis.stockmanagement.domain.card.StockCard)

Example 5 with StockCard

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();
    }
}
Also used : StockCard(org.openlmis.stockmanagement.domain.card.StockCard)

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