Search in sources :

Example 66 with StockEventDto

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

the class ActiveStockCardsValidatorTest method shouldThrowExceptionIfExistingCardLotNotCovered.

@Test
public void shouldThrowExceptionIfExistingCardLotNotCovered() throws Exception {
    expectedEx.expectMessage(ERROR_PHYSICAL_INVENTORY_NOT_INCLUDE_ACTIVE_STOCK_CARD);
    // given
    StockEventDto stockEventDto = createNoSourceDestinationStockEventDto();
    stockEventDto.getLineItems().get(0).setReasonId(null);
    stockEventDto.getLineItems().get(0).setLotId(randomUUID());
    when(stockCardRepository.getIdentitiesBy(stockEventDto.getProgramId(), stockEventDto.getFacilityId())).thenReturn(singletonList(new OrderableLotIdentity(randomUUID(), randomUUID())));
    // when
    activeStockCardsValidator.validate(stockEventDto);
}
Also used : OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity) StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) Test(org.junit.Test)

Example 67 with StockEventDto

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

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

the class FreeTextValidatorTest method shouldFailWhenDestinationNodeIsRefdataWithFreeText.

@Test
public void shouldFailWhenDestinationNodeIsRefdataWithFreeText() throws Exception {
    UUID destinationId = fromString("0bd28568-43f1-4836-934d-ec5fb11398e8");
    StockEventDto eventDto = createNoSourceDestinationStockEventDto();
    eventDto.getLineItems().get(0).setDestinationId(destinationId);
    eventDto.getLineItems().get(0).setDestinationFreeText("destination free text");
    setContext(eventDto);
    mockNode(destinationId, eventDto);
    exception.expect(ValidationMessageException.class);
    exception.expectMessage(containsString(ERROR_DESTINATION_FREE_TEXT_NOT_ALLOWED));
    freeTextValidator.validate(eventDto);
}
Also used : StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 69 with StockEventDto

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

the class FreeTextValidatorTest method shouldFailWhenReasonFreeTextNotAllowedButExist.

@Test
public void shouldFailWhenReasonFreeTextNotAllowedButExist() throws Exception {
    StockCardLineItemReason mockReason = mock(StockCardLineItemReason.class);
    when(reasonRepository.findOne(any(UUID.class))).thenReturn(mockReason);
    when(mockReason.getIsFreeTextAllowed()).thenReturn(false);
    StockEventDto eventDto = createNoSourceDestinationStockEventDto();
    eventDto.getLineItems().get(0).setReasonId(fromString("e3fc3cf3-da18-44b0-a220-77c985202e06"));
    eventDto.getLineItems().get(0).setReasonFreeText("reason free text");
    setContext(eventDto);
    exception.expect(ValidationMessageException.class);
    exception.expectMessage(containsString(ERROR_REASON_FREE_TEXT_NOT_ALLOWED));
    freeTextValidator.validate(eventDto);
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 70 with StockEventDto

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

the class OrderableLotDuplicationValidatorTest method physicalInventoryEventWithSameOrderableAndLotAppearTwiceShouldNotPass.

@Test
public void physicalInventoryEventWithSameOrderableAndLotAppearTwiceShouldNotPass() throws Exception {
    // expect: exception
    expectedEx.expectMessage(ERROR_EVENT_ORDERABLE_LOT_DUPLICATION);
    StockEventDto eventDto = createStockEventDtoWithDuplicateOrderableLot(null);
    // when
    orderableLotDuplicationValidator.validate(eventDto);
}
Also used : StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) 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