Search in sources :

Example 6 with StockEventProcessContext

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));
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto) ZonedDateTime(java.time.ZonedDateTime) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) StockEventProcessContext(org.openlmis.stockmanagement.util.StockEventProcessContext) Test(org.junit.Test)

Example 7 with StockEventProcessContext

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));
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) ProgramDto(org.openlmis.stockmanagement.dto.referencedata.ProgramDto) ArrayList(java.util.ArrayList) FacilityDto(org.openlmis.stockmanagement.dto.referencedata.FacilityDto) UUID(java.util.UUID) LotDto(org.openlmis.stockmanagement.dto.referencedata.LotDto) StockEventProcessContext(org.openlmis.stockmanagement.util.StockEventProcessContext)

Example 8 with StockEventProcessContext

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);
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) StockEventProcessContext(org.openlmis.stockmanagement.util.StockEventProcessContext) Test(org.junit.Test)

Example 9 with StockEventProcessContext

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);
}
Also used : StockEventProcessContext(org.openlmis.stockmanagement.util.StockEventProcessContext)

Aggregations

StockEventProcessContext (org.openlmis.stockmanagement.util.StockEventProcessContext)9 UUID (java.util.UUID)6 Test (org.junit.Test)4 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)4 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)3 ZonedDateTime (java.time.ZonedDateTime)2 FacilityDto (org.openlmis.stockmanagement.dto.referencedata.FacilityDto)2 LotDto (org.openlmis.stockmanagement.dto.referencedata.LotDto)2 ProgramDto (org.openlmis.stockmanagement.dto.referencedata.ProgramDto)2 Profiler (org.slf4j.profiler.Profiler)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID.randomUUID (java.util.UUID.randomUUID)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 StockCardLineItemReason (org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)1 Node (org.openlmis.stockmanagement.domain.sourcedestination.Node)1 ValidDestinationAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment)1 ValidSourceAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidSourceAssignment)1