use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.
the class StockCardServiceIntegrationTest method shouldReassignPhysicalInventoryReasonNames.
@Test
public void shouldReassignPhysicalInventoryReasonNames() throws Exception {
// given
StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
stockEventDto.getLineItems().get(0).setSourceId(null);
stockEventDto.getLineItems().get(0).setDestinationId(null);
stockEventDto.getLineItems().get(0).setReasonId(null);
StockEvent savedEvent = save(stockEventDto, randomUUID());
// when
UUID cardId = stockCardRepository.findByOriginEvent(savedEvent).getId();
StockCardDto card = stockCardService.findStockCardById(cardId);
// then
String reasonName = card.getLineItems().get(0).getLineItem().getReason().getName();
assertThat(reasonName, is("Overstock"));
}
use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.
the class StockCardServiceTest method setUp.
@Before
public void setUp() {
when(user.getId()).thenReturn(userId);
when(authenticationHelper.getCurrentUser()).thenReturn(user);
when(permissionStringsHandler.get()).thenReturn(Collections.singleton(PermissionStringDto.create(STOCK_CARDS_VIEW, facilityId, programId)));
when(permissionService.getPermissionStrings(userId)).thenReturn(permissionStringsHandler);
when(facilityRefDataService.findOne(facilityId)).thenReturn(FacilityDto.builder().id(facilityId).build());
when(programRefDataService.findOne(programId)).thenReturn(ProgramDto.builder().id(programId).build());
StockEvent originalEvent = new StockEventDataBuilder().withFacility(facilityId).withProgram(programId).build();
stockCard = new StockCardDataBuilder(originalEvent).build();
SecurityContextHolder.setContext(securityContext);
when(securityContext.getAuthentication()).thenReturn(authentication);
when(authentication.isClientOnly()).thenReturn(false);
}
use of org.openlmis.stockmanagement.domain.event.StockEvent 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