use of org.openlmis.stockmanagement.util.StockEventProcessContext in project openlmis-stockmanagement by OpenLMIS.
the class StockCardLineItemTest method shouldCreateLineItemFromStockEvent.
@Test
public void shouldCreateLineItemFromStockEvent() throws Exception {
// given
StockCard stockCard = new StockCard();
stockCard.setLineItems(new ArrayList<>());
// when
UUID userId = randomUUID();
StockEventProcessContext context = new StockEventProcessContext();
context.setCurrentUserId(new LazyResource<>(() -> userId));
StockEventDto eventDto = createStockEventDto();
eventDto.setContext(context);
StockEventLineItemDto eventLineItem = eventDto.getLineItems().get(0);
eventLineItem.setStockAdjustments(singletonList(createStockAdjustment()));
UUID eventId = randomUUID();
StockCardLineItem cardLineItem = createLineItemFrom(eventDto, eventLineItem, stockCard, eventId);
// then
assertThat(cardLineItem.getSourceFreeText(), is(eventLineItem.getSourceFreeText()));
assertThat(cardLineItem.getDestinationFreeText(), is(eventLineItem.getDestinationFreeText()));
assertThat(cardLineItem.getReasonFreeText(), is(eventLineItem.getReasonFreeText()));
assertThat(cardLineItem.getDocumentNumber(), is(eventDto.getDocumentNumber()));
assertThat(cardLineItem.getSignature(), is(eventDto.getSignature()));
assertThat(cardLineItem.getQuantity(), is(eventLineItem.getQuantity()));
assertThat(cardLineItem.getReason().getId(), is(eventLineItem.getReasonId()));
assertThat(cardLineItem.getSource().getId(), is(eventLineItem.getSourceId()));
assertThat(cardLineItem.getDestination().getId(), is(eventLineItem.getDestinationId()));
assertThat(cardLineItem.getOccurredDate(), is(eventLineItem.getOccurredDate()));
assertThat(cardLineItem.getStockCard(), is(stockCard));
assertThat(cardLineItem.getOriginEvent().getId(), is(eventId));
assertThat(cardLineItem.getUserId(), is(userId));
assertEquals(cardLineItem.getStockAdjustments(), eventLineItem.stockAdjustments());
ZonedDateTime processedDate = cardLineItem.getProcessedDate();
long between = SECONDS.between(processedDate, ZonedDateTime.now());
assertThat(between, lessThan(2L));
}
use of org.openlmis.stockmanagement.util.StockEventProcessContext in project openlmis-stockmanagement by OpenLMIS.
the class StockEventProcessContextBuilderTest method testBuildContext.
private void testBuildContext(StockEventDto stockEventDto) {
// given
UUID lotId = UUID.randomUUID();
LotDto lot = new LotDto();
lot.setId(lotId);
StockEventDtoDataBuilder.createStockEventDto();
stockEventDto.getLineItems().get(0).setLotId(lotId);
ProgramDto programDto = new ProgramDto();
FacilityDto facilityDto = new FacilityDto();
ArrayList<OrderableDto> approvedProductDtos = new ArrayList<>();
when(programService.findOne(stockEventDto.getProgramId())).thenReturn(programDto);
when(facilityService.findOne(stockEventDto.getFacilityId())).thenReturn(facilityDto);
when(orderableReferenceDataService.findAll()).thenReturn(approvedProductDtos);
when(lotReferenceDataService.findOne(lotId)).thenReturn(lot);
// when
StockEventProcessContext context = contextBuilder.buildContext(stockEventDto);
// then
assertThat(context.getCurrentUserId(), is(userDto.getId()));
assertThat(context.getProgram(), is(programDto));
assertThat(context.getFacility(), is(facilityDto));
assertThat(context.getAllApprovedProducts(), is(approvedProductDtos));
assertThat(context.findLot(lotId), is(lot));
}
use of org.openlmis.stockmanagement.util.StockEventProcessContext in project openlmis-stockmanagement by OpenLMIS.
the class ApprovedOrderableValidatorTest method stockEventWithOrderableIdNotInApprovedListShouldNotPassValidation.
@Test(expected = ValidationMessageException.class)
public void stockEventWithOrderableIdNotInApprovedListShouldNotPassValidation() throws Exception {
// given:
StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
OrderableDto orderableDto = new OrderableDto();
orderableDto.setId(UUID.randomUUID());
StockEventProcessContext context = new StockEventProcessContext();
context.setAllApprovedProducts(new LazyList<>(() -> singletonList(orderableDto)));
stockEventDto.setContext(context);
// when:
approvedOrderableValidator.validate(stockEventDto);
}
use of org.openlmis.stockmanagement.util.StockEventProcessContext in project openlmis-stockmanagement by OpenLMIS.
the class BaseValidatorTest method setContext.
void setContext(StockEventDto event) {
StockEventProcessContext context = contextBuilder.buildContext(event);
event.setContext(context);
}
Aggregations