Search in sources :

Example 6 with StockEventDto

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

the class StockCardServiceIntegrationTest method shouldGetStockCardWithCalculatedSohWhenFindStockCard.

@Test
public void shouldGetStockCardWithCalculatedSohWhenFindStockCard() throws Exception {
    // given
    StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
    stockEventDto.getLineItems().get(0).setSourceId(null);
    stockEventDto.getLineItems().get(0).setDestinationId(null);
    StockEvent savedEvent = save(stockEventDto, randomUUID());
    // when
    UUID cardId = stockCardRepository.findByOriginEvent(savedEvent).getId();
    StockCardDto card = stockCardService.findStockCardById(cardId);
    // then
    assertThat(card.getStockOnHand(), is(stockEventDto.getLineItems().get(0).getQuantity()));
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) BaseIntegrationTest(org.openlmis.stockmanagement.BaseIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with StockEventDto

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

the class StockCardServiceIntegrationTest method shouldGetRefdataAndConvertOrganizationsWhenFindStockCard.

@Test
public void shouldGetRefdataAndConvertOrganizationsWhenFindStockCard() throws Exception {
    // given
    UUID userId = randomUUID();
    StockEventDto stockEventDto = createStockEventDto();
    stockEventDto.getLineItems().get(0).setLotId(randomUUID());
    // 1. mock ref data service
    FacilityDto cardFacility = new FacilityDto();
    FacilityDto sourceFacility = new FacilityDto();
    ProgramDto programDto = new ProgramDto();
    OrderableDto orderableDto = new OrderableDto();
    LotDto lotDto = new LotDto();
    when(facilityReferenceDataService.findOne(stockEventDto.getFacilityId())).thenReturn(cardFacility);
    when(facilityReferenceDataService.findOne(fromString("e6799d64-d10d-4011-b8c2-0e4d4a3f65ce"))).thenReturn(sourceFacility);
    when(programReferenceDataService.findOne(stockEventDto.getProgramId())).thenReturn(programDto);
    when(orderableReferenceDataService.findOne(stockEventDto.getLineItems().get(0).getOrderableId())).thenReturn(orderableDto);
    when(lotReferenceDataService.findOne(stockEventDto.getLineItems().get(0).getLotId())).thenReturn(lotDto);
    // 2. there is an existing stock card with line items
    StockEvent savedEvent = save(stockEventDto, userId);
    // when
    StockCard savedCard = stockCardRepository.findByOriginEvent(savedEvent);
    StockCardDto foundCardDto = stockCardService.findStockCardById(savedCard.getId());
    // then
    assertThat(foundCardDto.getFacility(), is(cardFacility));
    assertThat(foundCardDto.getProgram(), is(programDto));
    assertThat(foundCardDto.getOrderable(), is(orderableDto));
    assertThat(foundCardDto.getLot(), is(lotDto));
    StockCardLineItemDto lineItemDto = foundCardDto.getLineItems().get(0);
    assertThat(lineItemDto.getSource(), is(sourceFacility));
    assertThat(lineItemDto.getDestination().getName(), is("NGO"));
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) StockCardLineItemDto(org.openlmis.stockmanagement.dto.StockCardLineItemDto) ProgramDto(org.openlmis.stockmanagement.dto.referencedata.ProgramDto) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) FacilityDto(org.openlmis.stockmanagement.dto.referencedata.FacilityDto) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) LotDto(org.openlmis.stockmanagement.dto.referencedata.LotDto) BaseIntegrationTest(org.openlmis.stockmanagement.BaseIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with StockEventDto

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

the class StockEventProcessorIntegrationTest method shouldNotSaveEventsIfAnythingGoesWrongInValidationsService.

@Test
public void shouldNotSaveEventsIfAnythingGoesWrongInValidationsService() throws Exception {
    // given
    StockEventDto stockEventDto = createStockEventDto();
    stockEventDto.setUserId(userId);
    setContext(stockEventDto);
    Mockito.doThrow(new RuntimeException("something wrong from validations service")).when(stockEventValidationsService).validate(stockEventDto);
    // when
    try {
        stockEventProcessor.process(stockEventDto);
    } catch (RuntimeException ex) {
        // then
        assertSize(cardSize, eventSize, lineItemSize);
        return;
    }
    Assert.fail();
}
Also used : StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) BaseIntegrationTest(org.openlmis.stockmanagement.BaseIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with StockEventDto

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

the class AdjustmentReasonValidatorIntegrationTest method incorrectReasonTypeShouldNotPassWhenEventHasNoSourceAndDestination.

@Test
public void incorrectReasonTypeShouldNotPassWhenEventHasNoSourceAndDestination() throws Exception {
    // given
    StockCardLineItemReason reason = StockCardLineItemReason.builder().reasonType(ReasonType.BALANCE_ADJUSTMENT).reasonCategory(ReasonCategory.ADJUSTMENT).isFreeTextAllowed(true).name("Balance Adjustment").build();
    StockEventDto stockEventDto = StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto();
    stockEventDto.getLineItems().get(0).setReasonId(reasonRepository.save(reason).getId());
    setContext(stockEventDto);
    expectedEx.expect(ValidationMessageException.class);
    expectedEx.expectMessage(ERROR_EVENT_ADJUSTMENT_REASON_TYPE_INVALID + ": " + reason.getReasonType());
    // when
    adjustmentReasonValidator.validate(stockEventDto);
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) BaseIntegrationTest(org.openlmis.stockmanagement.BaseIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with StockEventDto

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

the class AdjustmentReasonValidatorIntegrationTest method incorrectReasonCategoryShouldNotPassWhenEventHasNoSourceAndDestination.

@Test
public void incorrectReasonCategoryShouldNotPassWhenEventHasNoSourceAndDestination() throws Exception {
    // given
    StockCardLineItemReason reason = StockCardLineItemReason.builder().reasonType(ReasonType.CREDIT).reasonCategory(ReasonCategory.TRANSFER).name("Credit Ad_hoc").isFreeTextAllowed(false).build();
    StockEventDto stockEventDto = StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto();
    stockEventDto.getLineItems().get(0).setReasonId(reasonRepository.save(reason).getId());
    setContext(stockEventDto);
    expectedEx.expect(ValidationMessageException.class);
    expectedEx.expectMessage(ERROR_EVENT_ADJUSTMENT_REASON_CATEGORY_INVALID + ": " + reason.getReasonCategory());
    // when
    adjustmentReasonValidator.validate(stockEventDto);
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) BaseIntegrationTest(org.openlmis.stockmanagement.BaseIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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