Search in sources :

Example 11 with OrderableDto

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

the class ApprovedOrderableValidatorTest method stockEventWithOrderableIdInApprovedListShouldPass.

@Test
public void stockEventWithOrderableIdInApprovedListShouldPass() throws Exception {
    // given:
    String orderableIdString = "d8290082-f9fa-4a37-aefb-a3d76ff805a8";
    UUID orderableId = UUID.fromString(orderableIdString);
    StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
    stockEventDto.getLineItems().get(0).setOrderableId(orderableId);
    OrderableDto orderableDto = new OrderableDto();
    orderableDto.setId(UUID.fromString(orderableIdString));
    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) UUID(java.util.UUID) StockEventProcessContext(org.openlmis.stockmanagement.util.StockEventProcessContext) Test(org.junit.Test)

Example 12 with OrderableDto

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

the class LotValidatorTest method shouldFailIfLotDoesNotMatchOrderable.

@Test
public void shouldFailIfLotDoesNotMatchOrderable() throws Exception {
    // expect
    expectedEx.expectMessage(ERROR_EVENT_LOT_ORDERABLE_NOT_MATCH);
    // given
    UUID lotId = randomUUID();
    stockEventDto.getLineItems().get(0).setLotId(lotId);
    LotDto lotDto = new LotDto();
    lotDto.setId(lotId);
    lotDto.setTradeItemId(UUID.randomUUID());
    OrderableDto product = OrderableDto.builder().id(stockEventDto.getLineItems().get(0).getOrderableId()).identifiers(emptyMap()).build();
    // when
    when(lotReferenceDataService.findOne(lotId)).thenReturn(lotDto);
    when(orderableReferenceDataService.findAll()).thenReturn(singletonList(product));
    lotValidator.validate(stockEventDto);
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) LotDto(org.openlmis.stockmanagement.dto.referencedata.LotDto) Test(org.junit.Test)

Example 13 with OrderableDto

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

the class OrderableReferenceDataServiceTest method shouldReturnOrderablesById.

@Test
public void shouldReturnOrderablesById() {
    OrderableDto product = mockPageResponseEntityAndGetDto();
    UUID orderableId = UUID.randomUUID();
    List<OrderableDto> response = service.findByIds(Collections.singleton(orderableId));
    assertThat(response, hasSize(1));
    assertThat(response, hasItem(product));
    verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(), refEq(new DynamicPageTypeReference<>(OrderableDto.class)));
    URI uri = uriCaptor.getValue();
    assertEquals(serviceUrl + service.getUrl() + "?id=" + orderableId.toString(), uri.toString());
    assertAuthHeader(entityCaptor.getValue());
    assertNull(entityCaptor.getValue().getBody());
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) DynamicPageTypeReference(org.openlmis.stockmanagement.util.DynamicPageTypeReference) UUID(java.util.UUID) URI(java.net.URI) Test(org.junit.Test)

Example 14 with OrderableDto

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

the class ApprovedOrderableValidator method validate.

/**
 * Validate if the orderable in stock event is in the approved list.
 *
 * @param stockEventDto the event to be validated.
 */
public void validate(StockEventDto stockEventDto) {
    LOGGER.debug("Validate approved product reference data service");
    UUID facility = stockEventDto.getFacilityId();
    UUID program = stockEventDto.getProgramId();
    // that is other validator's job
    if (!stockEventDto.hasLineItems() || facility == null || program == null) {
        return;
    }
    List<UUID> nonApprovedIds = findNonApprovedIds(stockEventDto, stockEventDto.getContext().getAllApprovedProducts());
    if (!isEmpty(nonApprovedIds)) {
        List<OrderableDto> orderables = orderableReferenceDataService.findByIds(nonApprovedIds);
        String codes = orderables.stream().map(OrderableDto::getProductCode).collect(Collectors.joining(", "));
        throw new ValidationMessageException(new Message(ERROR_ORDERABLE_NOT_IN_APPROVED_LIST, codes));
    }
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) UUID(java.util.UUID)

Example 15 with OrderableDto

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

the class StockCardSummariesServiceTest method shouldFindStockCards.

@Test
public void shouldFindStockCards() throws Exception {
    OrderableDto orderable = new OrderableDtoDataBuilder().build();
    OrderableDto orderable2 = new OrderableDtoDataBuilder().build();
    OrderableDto orderable3 = new OrderableDtoDataBuilder().build();
    StockCardSummariesV2SearchParams params = new StockCardSummariesV2SearchParamsDataBuilder().withOrderableIds(asList(orderable.getId(), orderable2.getId())).build();
    when(approvedProductReferenceDataService.getApprovedProducts(eq(params.getFacilityId()), eq(params.getProgramId()), eq(params.getOrderableIds()))).thenReturn(new PageImpl<>(asList(orderable, orderable2, orderable3), new PageRequest(0, Integer.MAX_VALUE), 3));
    Map<UUID, OrderableFulfillDto> fulfillMap = new HashMap<>();
    fulfillMap.put(orderable.getId(), new OrderableFulfillDtoDataBuilder().withCanFulfillForMe(asList(orderable2.getId(), orderable3.getId())).build());
    fulfillMap.put(orderable2.getId(), new OrderableFulfillDtoDataBuilder().withCanFulfillForMe(asList(orderable.getId(), orderable3.getId())).build());
    when(orderableFulfillReferenceDataService.findByIds(asList(orderable.getId(), orderable2.getId(), orderable3.getId()))).thenReturn(fulfillMap);
    StockEvent event = new StockEventDataBuilder().withFacility(params.getFacilityId()).withProgram(params.getProgramId()).build();
    StockCard stockCard = new StockCardDataBuilder(event).withOrderable(orderable.getId()).withStockOnHand(12).build();
    StockCard stockCard1 = new StockCardDataBuilder(event).withOrderable(orderable3.getId()).withStockOnHand(26).build();
    List<StockCard> stockCards = asList(stockCard, stockCard1);
    when(cardRepository.findByProgramIdAndFacilityId(params.getProgramId(), params.getFacilityId())).thenReturn(stockCards);
    StockCardSummaries result = stockCardSummariesService.findStockCards(params);
    assertEquals(3, result.getPageOfApprovedProducts().size());
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) HashMap(java.util.HashMap) StockCardDataBuilder(org.openlmis.stockmanagement.testutils.StockCardDataBuilder) OrderableFulfillDtoDataBuilder(org.openlmis.stockmanagement.testutils.OrderableFulfillDtoDataBuilder) OrderableFulfillDto(org.openlmis.stockmanagement.dto.referencedata.OrderableFulfillDto) PageRequest(org.springframework.data.domain.PageRequest) StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) OrderableDtoDataBuilder(org.openlmis.stockmanagement.testutils.OrderableDtoDataBuilder) StockEventDataBuilder(org.openlmis.stockmanagement.testutils.StockEventDataBuilder) StockCardSummariesV2SearchParamsDataBuilder(org.openlmis.stockmanagement.testutils.StockCardSummariesV2SearchParamsDataBuilder) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) 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