Search in sources :

Example 21 with StockEventDto

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
}
Also used : StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) UUID(java.util.UUID) Test(org.junit.Test)

Example 22 with StockEventDto

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
}
Also used : StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) Test(org.junit.Test)

Example 23 with StockEventDto

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);
}
Also used : StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) UUID(java.util.UUID) Test(org.junit.Test)

Example 24 with StockEventDto

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);
}
Also used : StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) UUID(java.util.UUID) Test(org.junit.Test)

Example 25 with StockEventDto

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