Search in sources :

Example 46 with StockEventDto

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

the class AdjustmentReasonValidatorIntegrationTest method shouldNotThrowExceptionIfEventHasNoSourceDestinationReasonId.

@Test
public void shouldNotThrowExceptionIfEventHasNoSourceDestinationReasonId() throws Exception {
    // given
    StockEventDto stockEventDto = StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto();
    stockEventDto.getLineItems().get(0).setReasonId(null);
    setContext(stockEventDto);
    // when
    adjustmentReasonValidator.validate(stockEventDto);
}
Also used : StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) BaseIntegrationTest(org.openlmis.stockmanagement.BaseIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 47 with StockEventDto

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

the class AdjustmentReasonValidatorIntegrationTest method shouldNotThrowErrorForEventWithNoReasonId.

@Test
public void shouldNotThrowErrorForEventWithNoReasonId() throws Exception {
    // given
    StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
    stockEventDto.getLineItems().get(0).setReasonId(null);
    setContext(stockEventDto);
    // when
    adjustmentReasonValidator.validate(stockEventDto);
}
Also used : StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) BaseIntegrationTest(org.openlmis.stockmanagement.BaseIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 48 with StockEventDto

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

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

the class OrderableLotDuplicationValidator method validate.

@Override
public void validate(StockEventDto stockEventDto) {
    // duplication is not allow in physical inventory, but is allowed in adjustment
    if (!stockEventDto.hasLineItems() || !stockEventDto.isPhysicalInventory()) {
        return;
    }
    Set<OrderableLotIdentity> nonDuplicates = new HashSet<>();
    Set<OrderableLotIdentity> duplicates = stockEventDto.getLineItems().stream().map(OrderableLotIdentity::identityOf).filter(lotIdentity -> !nonDuplicates.add(lotIdentity)).collect(toSet());
    if (duplicates.size() > 0) {
        throw new ValidationMessageException(new Message(ERROR_EVENT_ORDERABLE_LOT_DUPLICATION, duplicates));
    }
}
Also used : HashSet(java.util.HashSet) ERROR_EVENT_ORDERABLE_LOT_DUPLICATION(org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_EVENT_ORDERABLE_LOT_DUPLICATION) OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity) Message(org.openlmis.stockmanagement.util.Message) Component(org.springframework.stereotype.Component) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) Set(java.util.Set) Collectors.toSet(java.util.stream.Collectors.toSet) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity) HashSet(java.util.HashSet)

Example 50 with StockEventDto

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

the class StockEventProcessContextBuilderTest method shouldBuildContextWithUserIdFromDtoWhenClientAuthentication.

@Test
public void shouldBuildContextWithUserIdFromDtoWhenClientAuthentication() throws Exception {
    StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
    stockEventDto.setUserId(userDto.getId());
    when(authentication.isClientOnly()).thenReturn(true);
    testBuildContext(stockEventDto);
}
Also used : StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)72 Test (org.junit.Test)65 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)44 UUID (java.util.UUID)24 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)15 StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto)14 BaseIntegrationTest (org.openlmis.stockmanagement.BaseIntegrationTest)13 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)11 UUID.randomUUID (java.util.UUID.randomUUID)10 StockEventLineItemDto (org.openlmis.stockmanagement.dto.StockEventLineItemDto)8 StockCardLineItem (org.openlmis.stockmanagement.domain.card.StockCardLineItem)7 Message (org.openlmis.stockmanagement.util.Message)7 LocalDate (java.time.LocalDate)6 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)5 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)4 StockCardDto (org.openlmis.stockmanagement.dto.StockCardDto)4 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)4 StockEventProcessContext (org.openlmis.stockmanagement.util.StockEventProcessContext)4 StockCardLineItemReason (org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)3 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)3