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