Search in sources :

Example 26 with StockEventDto

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

the class ActiveStockCardsValidatorTest method shouldThrowExceptionIfExistingCardOrderableNotCovered.

@Test
public void shouldThrowExceptionIfExistingCardOrderableNotCovered() throws Exception {
    expectedEx.expectMessage(ERROR_PHYSICAL_INVENTORY_NOT_INCLUDE_ACTIVE_STOCK_CARD);
    // given
    StockEventDto stockEventDto = createNoSourceDestinationStockEventDto();
    stockEventDto.getLineItems().get(0).setReasonId(null);
    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 27 with StockEventDto

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

the class ApprovedOrderableValidatorTest method stockEventWithOrderableIdInApprovedListShouldPass.

@Test
public void stockEventWithOrderableIdInApprovedListShouldPass() throws Exception {
    // given:
    String orderableIdString = "d8290082-f9fa-4a37-aefb-a3d76ff805a8";
    UUID orderableId = UUID.fromString(orderableIdString);
    StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
    stockEventDto.getLineItems().get(0).setOrderableId(orderableId);
    OrderableDto orderableDto = new OrderableDto();
    orderableDto.setId(UUID.fromString(orderableIdString));
    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) UUID(java.util.UUID) StockEventProcessContext(org.openlmis.stockmanagement.util.StockEventProcessContext) Test(org.junit.Test)

Example 28 with StockEventDto

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

the class ApprovedOrderableValidatorTest method shouldNotThrowValidationExceptionIfEventHasNoProgramAndFacilityId.

@Test
public void shouldNotThrowValidationExceptionIfEventHasNoProgramAndFacilityId() throws Exception {
    // given
    StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
    stockEventDto.setProgramId(null);
    // when
    approvedOrderableValidator.validate(stockEventDto);
    // given
    stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
    stockEventDto.setFacilityId(null);
    // when
    approvedOrderableValidator.validate(stockEventDto);
}
Also used : StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) Test(org.junit.Test)

Example 29 with StockEventDto

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

the class FreeTextValidatorTest method shouldFailWhenEventHasBothSourceAndDestinationFreeText.

@Test
public void shouldFailWhenEventHasBothSourceAndDestinationFreeText() throws Exception {
    StockEventDto eventDto = createStockEventDto();
    eventDto.getLineItems().get(0).setReasonId(randomUUID());
    eventDto.getLineItems().get(0).setDestinationId(randomUUID());
    eventDto.getLineItems().get(0).setSourceFreeText("source free text");
    eventDto.getLineItems().get(0).setDestinationFreeText("destination free text");
    setContext(eventDto);
    exception.expect(ValidationMessageException.class);
    exception.expectMessage(containsString(ERROR_SOURCE_DESTINATION_FREE_TEXT_BOTH_PRESENT));
    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) Test(org.junit.Test)

Example 30 with StockEventDto

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

the class FreeTextValidatorTest method shouldFailWhenDestinationNotExistButDestinationFreeTextExist.

@Test
public void shouldFailWhenDestinationNotExistButDestinationFreeTextExist() throws Exception {
    StockEventDto eventDto = createNoSourceDestinationStockEventDto();
    eventDto.getLineItems().get(0).setDestinationFreeText("destination free text");
    setContext(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) 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