Search in sources :

Example 1 with PhysicalInventoryDto

use of org.openlmis.stockmanagement.dto.PhysicalInventoryDto 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 2 with PhysicalInventoryDto

use of org.openlmis.stockmanagement.dto.PhysicalInventoryDto in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryServiceTest method shouldThrowExceptionWhenCreateNewDraftIfExistsAlready.

@Test(expected = ValidationMessageException.class)
public void shouldThrowExceptionWhenCreateNewDraftIfExistsAlready() throws Exception {
    UUID programId = UUID.randomUUID();
    UUID facilityId = UUID.randomUUID();
    PhysicalInventoryDto piDto = createInventoryDto(programId, facilityId);
    when(physicalInventoryRepository.findByProgramIdAndFacilityIdAndIsDraft(programId, facilityId, true)).thenReturn(Collections.singletonList(mock(PhysicalInventory.class)));
    physicalInventoryService.createNewDraft(piDto);
}
Also used : PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 3 with PhysicalInventoryDto

use of org.openlmis.stockmanagement.dto.PhysicalInventoryDto in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryServiceTest method shouldReturnAllSavedInventories.

@Test
public void shouldReturnAllSavedInventories() throws Exception {
    PhysicalInventory inventory = createInventoryDraft(orderableId, programId, facilityId);
    // given
    when(physicalInventoryRepository.findByProgramIdAndFacilityId(programId, facilityId)).thenReturn(Collections.singletonList(inventory));
    // when
    List<PhysicalInventoryDto> foundDraft = physicalInventoryService.findPhysicalInventory(programId, facilityId, null);
    // then
    assertEquals(1, foundDraft.size());
    assertEquals(programId, foundDraft.get(0).getProgramId());
    assertEquals(facilityId, foundDraft.get(0).getFacilityId());
    PhysicalInventoryLineItemDto lineItemDto = foundDraft.get(0).getLineItems().get(0);
    assertEquals(orderableId, lineItemDto.getOrderableId());
    assertEquals(null, lineItemDto.getQuantity());
}
Also used : PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory) PhysicalInventoryLineItemDto(org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto) PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto) Test(org.junit.Test)

Example 4 with PhysicalInventoryDto

use of org.openlmis.stockmanagement.dto.PhysicalInventoryDto in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryServiceTest method shouldSearchBasedOnIsDraft.

private void shouldSearchBasedOnIsDraft(PhysicalInventory inventory, boolean isDraft) {
    // given
    inventory.setIsDraft(isDraft);
    when(physicalInventoryRepository.findByProgramIdAndFacilityIdAndIsDraft(programId, facilityId, isDraft)).thenReturn(Collections.singletonList(inventory));
    // when
    List<PhysicalInventoryDto> foundDraft = physicalInventoryService.findPhysicalInventory(programId, facilityId, isDraft);
    // then
    assertEquals(1, foundDraft.size());
    assertEquals(programId, foundDraft.get(0).getProgramId());
    assertEquals(facilityId, foundDraft.get(0).getFacilityId());
    assertEquals(isDraft, foundDraft.get(0).getIsDraft());
    PhysicalInventoryLineItemDto lineItemDto = foundDraft.get(0).getLineItems().get(0);
    assertEquals(orderableId, lineItemDto.getOrderableId());
    assertEquals(null, lineItemDto.getQuantity());
}
Also used : PhysicalInventoryLineItemDto(org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto) PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto)

Example 5 with PhysicalInventoryDto

use of org.openlmis.stockmanagement.dto.PhysicalInventoryDto in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryServiceTest method shouldThrowExceptionWhenSaveDraftIfExistsAlready.

@Test(expected = ValidationMessageException.class)
public void shouldThrowExceptionWhenSaveDraftIfExistsAlready() throws Exception {
    UUID programId = UUID.randomUUID();
    UUID facilityId = UUID.randomUUID();
    PhysicalInventoryDto piDto = createInventoryDto(programId, facilityId);
    PhysicalInventory mock = mock(PhysicalInventory.class);
    when(mock.getId()).thenReturn(UUID.randomUUID());
    when(physicalInventoryRepository.findByProgramIdAndFacilityIdAndIsDraft(programId, facilityId, true)).thenReturn(Collections.singletonList(mock));
    physicalInventoryService.saveDraft(piDto, piDto.getId());
}
Also used : PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory) PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Aggregations

PhysicalInventoryDto (org.openlmis.stockmanagement.dto.PhysicalInventoryDto)28 Test (org.junit.Test)20 UUID (java.util.UUID)11 PhysicalInventory (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory)7 UUID.randomUUID (java.util.UUID.randomUUID)5 PhysicalInventoryLineItemDto (org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto)3 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)3 List (java.util.List)2 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)2 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Random (java.util.Random)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)1 PhysicalInventoryLineItem (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItem)1 ResourceNotFoundException (org.openlmis.stockmanagement.exception.ResourceNotFoundException)1 ERROR_PHYSICAL_INVENTORY_DRAFT_EXISTS (org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_PHYSICAL_INVENTORY_DRAFT_EXISTS)1 ERROR_PHYSICAL_INVENTORY_IS_SUBMITTED (org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_PHYSICAL_INVENTORY_IS_SUBMITTED)1