Search in sources :

Example 51 with StockEventDto

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

the class StockEventValidationsServiceTest method shouldValidateWithAllImplementationsOfValidators.

@Test
public void shouldValidateWithAllImplementationsOfValidators() throws Exception {
    // given
    StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
    // when:
    stockEventValidationsService.validate(stockEventDto);
    // then:
    verify(validator1, times(1)).validate(stockEventDto);
    verify(validator2, times(1)).validate(stockEventDto);
}
Also used : StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 52 with StockEventDto

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

the class StockEventValidationsServiceTest method shouldNotRunNextValidatorIfPreviousValidatorFailed.

@Test
public void shouldNotRunNextValidatorIfPreviousValidatorFailed() throws Exception {
    // given
    StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
    doThrow(new ValidationMessageException(new Message("some error"))).when(validator1).validate(stockEventDto);
    // when:
    try {
        stockEventValidationsService.validate(stockEventDto);
    } catch (ValidationMessageException ex) {
        // then:
        verify(validator1, times(1)).validate(stockEventDto);
        verify(validator2, never()).validate(stockEventDto);
    }
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 53 with StockEventDto

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

the class QuantityValidatorTest method shouldNotRejectWhenEventReasonIdIsNotFound.

@Test
public void shouldNotRejectWhenEventReasonIdIsNotFound() throws Exception {
    // given
    StockEventDto event = createStockEventDto();
    StockEventLineItemDto invalidItem = event.getLineItems().get(0);
    invalidItem.setDestinationId(null);
    setContext(event);
    // when
    quantityValidator.validate(event);
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) Test(org.junit.Test)

Example 54 with StockEventDto

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

the class QuantityValidatorTest method shouldRejectWhenQuantityMakesStockOnHandBelowZero.

@Test
public void shouldRejectWhenQuantityMakesStockOnHandBelowZero() {
    // expect
    expectedException.expect(ValidationMessageException.class);
    expectedException.expectMessage(ERROR_EVENT_DEBIT_QUANTITY_EXCEED_SOH);
    // given
    LocalDate firstDate = dateFromYear(2015);
    StockCard card = new StockCard();
    card.setLineItems(newArrayList(createCreditLineItem(firstDate.plusDays(1), 5), createDebitLineItem(firstDate.plusDays(3), 1), createCreditLineItem(firstDate.plusDays(4), 2)));
    StockEventDto event = createDebitEventDto(firstDate.plusDays(2), 5);
    mockCardFound(event, card);
    // when
    quantityValidator.validate(event);
}
Also used : StockCard(org.openlmis.stockmanagement.domain.card.StockCard) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 55 with StockEventDto

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

the class QuantityValidatorTest method shouldNotRejectWhenStockOnHandWithAdjustmentsMatchesQuantity.

@Test
public void shouldNotRejectWhenStockOnHandWithAdjustmentsMatchesQuantity() throws Exception {
    // given
    LocalDate firstDate = dateFromYear(2015);
    StockCardLineItem lineItem = createCreditLineItem(firstDate.plusDays(1), 10);
    StockCard card = new StockCard();
    card.setLineItems(newArrayList(lineItem));
    StockEventDto event = spy(createPhysicalInventoryEventDto(firstDate.plusDays(2), 5, singletonList(createDebitAdjustment(5))));
    mockCardFound(event, card);
    // when
    quantityValidator.validate(event);
}
Also used : StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) LocalDate(java.time.LocalDate) 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