Search in sources :

Example 56 with StockEventDto

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

the class QuantityValidatorTest method shouldNotRejectWhenStockOnHandDoesNotMatchQuantityAndNoAdjustmentsProvided.

@Test
public void shouldNotRejectWhenStockOnHandDoesNotMatchQuantityAndNoAdjustmentsProvided() {
    // given
    LocalDate firstDate = dateFromYear(2015);
    StockCardLineItem lineItem = createCreditLineItem(firstDate.plusDays(1), 15);
    StockCard card = new StockCard();
    card.setLineItems(newArrayList(lineItem));
    StockEventDto event = createPhysicalInventoryEventDto(firstDate.plusDays(2), 5, null);
    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)

Example 57 with StockEventDto

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

the class QuantityValidatorTest method shouldNotRejectWhenEventLineItemHasNoReason.

@Test
public void shouldNotRejectWhenEventLineItemHasNoReason() throws Exception {
    // given
    StockEventDto event = createStockEventDto();
    setContext(event);
    StockEventLineItemDto invalidItem = event.getLineItems().get(0);
    invalidItem.setDestinationId(randomUUID());
    invalidItem.setReasonId(null);
    // 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 58 with StockEventDto

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

the class ReasonExistenceValidatorTest method shouldThrowErrorIfEventReasonIdNotFoundInDb.

@Test
public void shouldThrowErrorIfEventReasonIdNotFoundInDb() throws Exception {
    // expect
    expectedEx.expect(ValidationMessageException.class);
    expectedEx.expectMessage(ERROR_EVENT_REASON_NOT_EXIST);
    // given
    StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
    UUID reasonId = UUID.randomUUID();
    stockEventDto.getLineItems().get(0).setReasonId(reasonId);
    setContext(stockEventDto);
    when(reasonRepository.findOne(reasonId)).thenReturn(null);
    // when
    reasonExistenceValidator.validate(stockEventDto);
}
Also used : StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) UUID(java.util.UUID) Test(org.junit.Test)

Example 59 with StockEventDto

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

the class ReceiveIssueReasonValidatorTest method eventThatHasSourceAndA_reasonOfCreditShouldPass.

@Test
public void eventThatHasSourceAndA_reasonOfCreditShouldPass() throws Exception {
    // given
    StockEventDto stockEventDto = createStockEventDto();
    stockEventDto.getLineItems().get(0).setSourceId(UUID.randomUUID());
    stockEventDto.getLineItems().get(0).setDestinationId(null);
    UUID reasonId = UUID.randomUUID();
    stockEventDto.getLineItems().get(0).setReasonId(reasonId);
    setContext(stockEventDto);
    when(reasonRepository.findByIdIn(singleton(reasonId))).thenReturn(singletonList(creditAdhocReason));
    creditAdhocReason.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 60 with StockEventDto

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

the class ReceiveIssueReasonValidatorTest method eventThatHasDestinationAndA_reasonOfCreditShouldNotPass.

@Test
public void eventThatHasDestinationAndA_reasonOfCreditShouldNotPass() throws Exception {
    StockEventDto stockEventDto = createStockEventDto();
    stockEventDto.getLineItems().get(0).setDestinationId(UUID.randomUUID());
    stockEventDto.getLineItems().get(0).setSourceId(null);
    stockEventDto.getLineItems().get(0).setReasonId(UUID.randomUUID());
    testErrorCase(ERROR_EVENT_ISSUE_REASON_TYPE_INVALID, stockEventDto, creditAdhocReason);
}
Also used : 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