Search in sources :

Example 16 with OrderableDto

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

the class StockCardSummariesServiceTest method shouldReturnPageOfStockCards.

@Test
public void shouldReturnPageOfStockCards() throws Exception {
    // given
    UUID programId = randomUUID();
    UUID facilityId = randomUUID();
    PageRequest pageRequest = new PageRequest(0, 1);
    UUID orderableId = randomUUID();
    OrderableDto orderable = createOrderableDto(orderableId, "");
    StockCard card = createStockCard(orderableId, randomUUID());
    when(cardRepository.findByProgramIdAndFacilityId(programId, facilityId, pageRequest)).thenReturn(new PageImpl<>(singletonList(card), pageRequest, 10));
    when(orderableReferenceDataService.findAll()).thenReturn(singletonList(orderable));
    when(lotReferenceDataService.getAllLotsOf(any(UUID.class))).thenReturn(emptyList());
    // when
    Page<StockCardDto> stockCards = stockCardSummariesService.findStockCards(programId, facilityId, pageRequest);
    // then
    assertThat(stockCards.getContent().size(), is(1));
    assertThat(stockCards.getTotalElements(), is(10L));
    assertThat(stockCards.getContent().get(0).getExtraData().get("vvmStatus"), is("STAGE_2"));
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) PageRequest(org.springframework.data.domain.PageRequest) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 17 with OrderableDto

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

the class StockEventProcessContextBuilderTest method testBuildContext.

private void testBuildContext(StockEventDto stockEventDto) {
    // given
    UUID lotId = UUID.randomUUID();
    LotDto lot = new LotDto();
    lot.setId(lotId);
    StockEventDtoDataBuilder.createStockEventDto();
    stockEventDto.getLineItems().get(0).setLotId(lotId);
    ProgramDto programDto = new ProgramDto();
    FacilityDto facilityDto = new FacilityDto();
    ArrayList<OrderableDto> approvedProductDtos = new ArrayList<>();
    when(programService.findOne(stockEventDto.getProgramId())).thenReturn(programDto);
    when(facilityService.findOne(stockEventDto.getFacilityId())).thenReturn(facilityDto);
    when(orderableReferenceDataService.findAll()).thenReturn(approvedProductDtos);
    when(lotReferenceDataService.findOne(lotId)).thenReturn(lot);
    // when
    StockEventProcessContext context = contextBuilder.buildContext(stockEventDto);
    // then
    assertThat(context.getCurrentUserId(), is(userDto.getId()));
    assertThat(context.getProgram(), is(programDto));
    assertThat(context.getFacility(), is(facilityDto));
    assertThat(context.getAllApprovedProducts(), is(approvedProductDtos));
    assertThat(context.findLot(lotId), is(lot));
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) ProgramDto(org.openlmis.stockmanagement.dto.referencedata.ProgramDto) ArrayList(java.util.ArrayList) FacilityDto(org.openlmis.stockmanagement.dto.referencedata.FacilityDto) UUID(java.util.UUID) LotDto(org.openlmis.stockmanagement.dto.referencedata.LotDto) StockEventProcessContext(org.openlmis.stockmanagement.util.StockEventProcessContext)

Example 18 with OrderableDto

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

the class VvmValidatorTest method shouldNotRejectIfOrderableEnabledVvmAndLineItemHasVvmStatus.

@Test
public void shouldNotRejectIfOrderableEnabledVvmAndLineItemHasVvmStatus() {
    OrderableDto orderable = generateOrderable();
    orderable.setExtraData(Collections.singletonMap("useVVM", "true"));
    VvmApplicable lineItem = generateVvmApplicable(orderable);
    lineItem.setExtraData(Collections.singletonMap("vvmStatus", "status"));
    validator.validate(Collections.singletonList(lineItem), ERROR_MESSAGE, false);
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) VvmApplicable(org.openlmis.stockmanagement.domain.common.VvmApplicable) Test(org.junit.Test)

Example 19 with OrderableDto

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

the class VvmValidatorTest method shouldRejectIfOrderableNotConfiguredVvmAndLineItemHasVvmStatus.

@Test(expected = ValidationMessageException.class)
public void shouldRejectIfOrderableNotConfiguredVvmAndLineItemHasVvmStatus() {
    OrderableDto orderable = generateOrderable();
    VvmApplicable lineItem = generateVvmApplicable(orderable);
    lineItem.setExtraData(Collections.singletonMap("vvmStatus", "status"));
    validator.validate(Collections.singletonList(lineItem), ERROR_MESSAGE, false);
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) VvmApplicable(org.openlmis.stockmanagement.domain.common.VvmApplicable) Test(org.junit.Test)

Example 20 with OrderableDto

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

the class ApprovedOrderableValidatorTest method stockEventWithOrderableIdNotInApprovedListShouldNotPassValidation.

@Test(expected = ValidationMessageException.class)
public void stockEventWithOrderableIdNotInApprovedListShouldNotPassValidation() throws Exception {
    // given:
    StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
    OrderableDto orderableDto = new OrderableDto();
    orderableDto.setId(UUID.randomUUID());
    StockEventProcessContext context = new StockEventProcessContext();
    context.setAllApprovedProducts(new LazyList<>(() -> singletonList(orderableDto)));
    stockEventDto.setContext(context);
    // when:
    approvedOrderableValidator.validate(stockEventDto);
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) StockEventProcessContext(org.openlmis.stockmanagement.util.StockEventProcessContext) Test(org.junit.Test)

Aggregations

OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)23 UUID (java.util.UUID)16 Test (org.junit.Test)16 UUID.randomUUID (java.util.UUID.randomUUID)8 LotDto (org.openlmis.stockmanagement.dto.referencedata.LotDto)6 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)5 VvmApplicable (org.openlmis.stockmanagement.domain.common.VvmApplicable)5 StockCardDto (org.openlmis.stockmanagement.dto.StockCardDto)5 URI (java.net.URI)4 StockEventProcessContext (org.openlmis.stockmanagement.util.StockEventProcessContext)4 List (java.util.List)3 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)3 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)3 ApprovedProductDto (org.openlmis.stockmanagement.dto.referencedata.ApprovedProductDto)3 FacilityDto (org.openlmis.stockmanagement.dto.referencedata.FacilityDto)3 ProgramDto (org.openlmis.stockmanagement.dto.referencedata.ProgramDto)3 DynamicPageTypeReference (org.openlmis.stockmanagement.util.DynamicPageTypeReference)3 Map (java.util.Map)2 UUID.fromString (java.util.UUID.fromString)2 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)2