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);
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations