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