Search in sources :

Example 16 with PhysicalInventory

use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryServiceTest method createInventoryDraft.

private PhysicalInventory createInventoryDraft(UUID orderableId, UUID programId, UUID facilityId) {
    PhysicalInventory inventory = createInventoryDto(programId, facilityId).toPhysicalInventoryForDraft();
    inventory.getLineItems().get(0).setOrderableId(orderableId);
    return inventory;
}
Also used : PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory)

Example 17 with PhysicalInventory

use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryServiceTest method shouldReturnDraftIfSavedDraftIsFound.

@Test
public void shouldReturnDraftIfSavedDraftIsFound() throws Exception {
    PhysicalInventory inventory = createInventoryDraft(orderableId, programId, facilityId);
    shouldSearchBasedOnIsDraft(inventory, true);
}
Also used : PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory) Test(org.junit.Test)

Example 18 with PhysicalInventory

use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryServiceTest method shouldCreateNewDraft.

@Test
public void shouldCreateNewDraft() throws Exception {
    // given
    UUID programId = UUID.randomUUID();
    UUID facilityId = UUID.randomUUID();
    PhysicalInventoryDto piDto = createInventoryDto(programId, facilityId);
    when(physicalInventoryRepository.save(any(PhysicalInventory.class))).thenAnswer(new SaveAnswer<PhysicalInventory>());
    // when
    PhysicalInventoryDto newDraft = physicalInventoryService.createNewDraft(piDto);
    // then
    assertNotNull(newDraft.getId());
    verify(physicalInventoryRepository, times(1)).save(inventoryArgumentCaptor.capture());
    PhysicalInventory captured = inventoryArgumentCaptor.getValue();
    assertEquals(programId, captured.getProgramId());
    assertEquals(facilityId, captured.getFacilityId());
    assertEquals(true, captured.getIsDraft());
    assertEquals(null, captured.getLineItems());
    verify(homeFacilityPermissionService, times(1)).checkProgramSupported(programId);
    verify(permissionService, times(1)).canEditPhysicalInventory(programId, facilityId);
    verify(validator, times(1)).validateEmptyDraft(piDto);
}
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)

Example 19 with PhysicalInventory

use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryServiceTest method verifyPhysicalInventorySavedWithSohAndAsDraft.

private void verifyPhysicalInventorySavedWithSohAndAsDraft(int previousSoH) {
    PhysicalInventory captured = inventoryArgumentCaptor.getValue();
    Integer previousStockOnHand = captured.getLineItems().get(0).getPreviousStockOnHandWhenSubmitted();
    assertNotNull(previousStockOnHand);
    assertEquals(previousSoH, previousStockOnHand.intValue());
    assertFalse(captured.getIsDraft());
}
Also used : PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory)

Example 20 with PhysicalInventory

use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryServiceTest method shouldDeleteDraftWhenPassValidations.

@Test
public void shouldDeleteDraftWhenPassValidations() throws Exception {
    // given
    UUID programId = UUID.randomUUID();
    UUID facilityId = UUID.randomUUID();
    PhysicalInventory physicalInventory = createInventoryDraft(UUID.randomUUID(), programId, facilityId);
    physicalInventory.setId(UUID.randomUUID());
    when(physicalInventoryRepository.findOne(physicalInventory.getId())).thenReturn(physicalInventory);
    // when
    physicalInventoryService.deletePhysicalInventory(physicalInventory.getId());
    // then
    verify(physicalInventoryRepository, times(1)).delete(physicalInventory);
    verify(homeFacilityPermissionService, times(1)).checkProgramSupported(programId);
    verify(permissionService, times(1)).canEditPhysicalInventory(programId, facilityId);
}
Also used : PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Aggregations

PhysicalInventory (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory)23 Test (org.junit.Test)12 UUID (java.util.UUID)7 PhysicalInventoryDto (org.openlmis.stockmanagement.dto.PhysicalInventoryDto)7 UUID.randomUUID (java.util.UUID.randomUUID)6 ResourceNotFoundException (org.openlmis.stockmanagement.exception.ResourceNotFoundException)3 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)3 Message (org.openlmis.stockmanagement.util.Message)3 PhysicalInventoryLineItemDto (org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto)2 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)1 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)1 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)1 PhysicalInventoryLineItem (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItem)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 ERROR_PHYSICAL_INVENTORY_NOT_FOUND (org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_PHYSICAL_INVENTORY_NOT_FOUND)1