Search in sources :

Example 26 with PhysicalInventoryDto

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

the class PhysicalInventoryServiceTest method newInventoryForSubmit.

private PhysicalInventoryDto newInventoryForSubmit() {
    PhysicalInventoryDto inventory = new PhysicalInventoryDto();
    inventory.setId(randomUUID());
    inventory.setProgramId(randomUUID());
    inventory.setFacilityId(randomUUID());
    inventory.setIsDraft(true);
    lineItemDto = generateLineItem();
    inventory.setLineItems(Collections.singletonList(lineItemDto));
    return inventory;
}
Also used : PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto)

Example 27 with PhysicalInventoryDto

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

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

the class PhysicalInventoryServiceTest method shouldSaveDraftWhenPassValidations.

@Test
public void shouldSaveDraftWhenPassValidations() throws Exception {
    // given
    UUID programId = UUID.randomUUID();
    UUID facilityId = UUID.randomUUID();
    PhysicalInventoryDto piDto = createInventoryDto(programId, facilityId);
    UUID physicalInventoryId = randomUUID();
    // when
    physicalInventoryService.saveDraft(piDto, physicalInventoryId);
    // then
    verify(physicalInventoryRepository, times(1)).save(inventoryArgumentCaptor.capture());
    PhysicalInventory captured = inventoryArgumentCaptor.getValue();
    verifyLineItems(piDto.getLineItems(), captured.getLineItems());
    assertEquals(programId, captured.getProgramId());
    assertEquals(facilityId, captured.getFacilityId());
    assertEquals(true, captured.getIsDraft());
    verify(homeFacilityPermissionService, times(1)).checkProgramSupported(programId);
    verify(permissionService, times(1)).canEditPhysicalInventory(programId, facilityId);
    verify(validator, times(1)).validateDraft(piDto, physicalInventoryId);
}
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