use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory 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());
}
use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryServiceTest method shouldThrowExceptionWhenDeleteIfInventoryIsNotDraft.
@Test(expected = ValidationMessageException.class)
public void shouldThrowExceptionWhenDeleteIfInventoryIsNotDraft() throws Exception {
UUID physicalInventoryId = UUID.randomUUID();
PhysicalInventory physicalInventory = mock(PhysicalInventory.class);
when(physicalInventory.getIsDraft()).thenReturn(false);
when(physicalInventoryRepository.findOne(physicalInventoryId)).thenReturn(physicalInventory);
physicalInventoryService.deletePhysicalInventory(physicalInventoryId);
}
use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory 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());
}
use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryController method checkPermission.
private void checkPermission(UUID id) {
PhysicalInventory pi = repository.findOne(id);
if (pi == null) {
throw new ResourceNotFoundException(new Message(ERROR_PHYSICAL_INVENTORY_NOT_FOUND, id));
}
permissionService.canEditPhysicalInventory(pi.getProgramId(), pi.getFacilityId());
}
use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryValidator method validateDraft.
/**
* Check for physical inventory dto's validity.
* Throws {@link ValidationMessageException} if an error found.
* @param inventory physical inventory to validate.
*/
public void validateDraft(PhysicalInventoryDto inventory, UUID id) {
if (!inventory.getId().equals(id)) {
throw new ValidationMessageException(ERROR_PHYSICAL_INVENTORY_ID_MISMATCH);
}
PhysicalInventory foundInventory = physicalInventoriesRepository.findOne(id);
if (foundInventory != null && !foundInventory.getIsDraft()) {
throw new ValidationMessageException(ERROR_PHYSICAL_INVENTORY_IS_SUBMITTED);
}
List<PhysicalInventoryLineItemDto> lineItems = inventory.getLineItems();
validateLineItems(lineItems);
vvmValidator.validate(lineItems, ERROR_PHYSICAL_INVENTORY_ORDERABLE_DISABLED_VVM, false);
}
Aggregations