use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.
the class StockEventDtoTest method shouldConvertFromDtoToJpaModel.
@Test
public void shouldConvertFromDtoToJpaModel() throws Exception {
// given
UUID userId = UUID.randomUUID();
StockEventProcessContext context = new StockEventProcessContext();
context.setCurrentUserId(new LazyResource<>(() -> userId));
StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
stockEventDto.setContext(context);
// when
StockEvent event = stockEventDto.toEvent();
// then
assertThat(event.getDocumentNumber(), is(stockEventDto.getDocumentNumber()));
assertThat(event.getSignature(), is(stockEventDto.getSignature()));
assertThat(event.getLineItems(), hasSize(stockEventDto.getLineItems().size()));
assertThat(event.getProgramId(), is(stockEventDto.getProgramId()));
assertThat(event.getFacilityId(), is(stockEventDto.getFacilityId()));
assertThat(event.getUserId(), is(userId));
ZonedDateTime processedDate = event.getProcessedDate();
long between = SECONDS.between(processedDate, ZonedDateTime.now());
assertThat(between, lessThan(2L));
}
use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.
the class StockCardRepositoryIntegrationTest method generateInstance.
private StockCard generateInstance(UUID facility, UUID program, UUID product, UUID lot) {
StockEvent event = new StockEventDataBuilder().withoutId().withFacility(facility).withProgram(program).build();
event = stockEventsRepository.save(event);
StockCardLineItem lineItem = new StockCardLineItemDataBuilder().withoutId().withOriginEvent(event).build();
StockCard stockCard = new StockCardDataBuilder(event).withoutId().withOrderable(product).withLot(lot).withLineItem(lineItem).build();
lineItem.setStockCard(stockCard);
return stockCard;
}
use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.
the class StockCardServiceIntegrationTest method save.
private StockEvent save(StockEventDto eventDto, UUID userId) {
eventDto.setUserId(userId);
setContext(eventDto);
StockEvent event = eventDto.toEvent();
StockEvent savedEvent = stockEventsRepository.save(event);
stockCardService.saveFromEvent(eventDto, savedEvent.getId());
return savedEvent;
}
use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.
the class StockCardServiceIntegrationTest method shouldGetStockCardWithCalculatedSohWhenFindStockCard.
@Test
public void shouldGetStockCardWithCalculatedSohWhenFindStockCard() throws Exception {
// given
StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
stockEventDto.getLineItems().get(0).setSourceId(null);
stockEventDto.getLineItems().get(0).setDestinationId(null);
StockEvent savedEvent = save(stockEventDto, randomUUID());
// when
UUID cardId = stockCardRepository.findByOriginEvent(savedEvent).getId();
StockCardDto card = stockCardService.findStockCardById(cardId);
// then
assertThat(card.getStockOnHand(), is(stockEventDto.getLineItems().get(0).getQuantity()));
}
use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.
the class StockCardServiceIntegrationTest method shouldThrowPermissionExceptionIfUserHasNoPermissionToViewCard.
@Test(expected = PermissionMessageException.class)
public void shouldThrowPermissionExceptionIfUserHasNoPermissionToViewCard() throws Exception {
// given
StockEvent savedEvent = save(createStockEventDto(), randomUUID());
doThrow(new PermissionMessageException(new Message("some error"))).when(permissionService).canViewStockCard(savedEvent.getProgramId(), savedEvent.getFacilityId());
// when
UUID savedCardId = stockCardRepository.findByOriginEvent(savedEvent).getId();
stockCardService.findStockCardById(savedCardId);
}
Aggregations