use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class ReceiveIssueReasonValidatorTest method eventThatHasDestinationAndA_reasonOfDebitShouldPass.
@Test
public void eventThatHasDestinationAndA_reasonOfDebitShouldPass() throws Exception {
// given
StockEventDto stockEventDto = createStockEventDto();
stockEventDto.getLineItems().get(0).setDestinationId(UUID.randomUUID());
stockEventDto.getLineItems().get(0).setSourceId(null);
// the following is a debit reason
UUID reasonId = UUID.randomUUID();
stockEventDto.getLineItems().get(0).setReasonId(reasonId);
setContext(stockEventDto);
when(reasonRepository.findByIdIn(singleton(reasonId))).thenReturn(singletonList(debitAdhocReason));
debitAdhocReason.setId(reasonId);
// when
receiveIssueReasonValidator.validate(stockEventDto);
// then: no error exception
}
use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class ReceiveIssueReasonValidatorTest method eventThatHasDestinationButNoReasonShouldPass.
@Test
public void eventThatHasDestinationButNoReasonShouldPass() throws Exception {
// given
StockEventDto stockEventDto = createStockEventDto();
stockEventDto.getLineItems().get(0).setDestinationId(UUID.randomUUID());
stockEventDto.getLineItems().get(0).setSourceId(null);
stockEventDto.getLineItems().get(0).setReasonId(null);
setContext(stockEventDto);
// when
receiveIssueReasonValidator.validate(stockEventDto);
// then: no error exception
}
use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class SourceDestinationAssignmentValidatorTest method shouldNotPassWhenEventHasSourceNotInValidList.
@Test
public void shouldNotPassWhenEventHasSourceNotInValidList() throws Exception {
// given
StockEventDto eventDto = createStockEventDto();
createContextWithFacility(eventDto);
eventDto.getLineItems().get(0).setSourceId(UUID.randomUUID());
eventDto.getLineItems().get(0).setDestinationId(null);
when(validSourceAssignmentRepository.findByProgramIdAndFacilityTypeId(any(UUID.class), any(UUID.class))).thenReturn(new ArrayList<>());
expectedEx.expect(ValidationMessageException.class);
expectedEx.expectMessage(containsString(ERROR_SOURCE_NOT_IN_VALID_LIST));
// when
sourceDestinationAssignmentValidator.validate(eventDto);
}
use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class SourceDestinationAssignmentValidatorTest method shouldNotPassWhenEventHasDestinationNotInValidList.
@Test
public void shouldNotPassWhenEventHasDestinationNotInValidList() throws Exception {
// given
StockEventDto eventDto = createStockEventDto();
createContextWithFacility(eventDto);
eventDto.getLineItems().get(0).setDestinationId(UUID.randomUUID());
eventDto.getLineItems().get(0).setSourceId(null);
when(validDestinationAssignmentRepository.findByProgramIdAndFacilityTypeId(any(UUID.class), any(UUID.class))).thenReturn(new ArrayList<>());
expectedEx.expect(ValidationMessageException.class);
expectedEx.expectMessage(containsString(ERROR_DESTINATION_NOT_IN_VALID_LIST));
// when
sourceDestinationAssignmentValidator.validate(eventDto);
}
use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class StockEventVvmValidatorTest method shouldCallVvmValidator.
@Test
public void shouldCallVvmValidator() {
// given
StockEventDto stockEvent = new StockEventDto();
stockEvent.setLineItems(Collections.emptyList());
doNothing().when(vvmValidator).validate(eq(stockEvent.getLineItems()), anyString(), eq(true));
// when
validator.validate(stockEvent);
// then
verify(vvmValidator, atLeastOnce()).validate(eq(stockEvent.getLineItems()), anyString(), eq(true));
}
Aggregations