VIARequisitionPresenter extends BaseRequisitionPresenter { public void populateAdditionalDrugsViewModels(List<RnrFormItem> addedDrugInVIAs, Date periodBegin) { List<RnrFormItem> additionalProducts = generateRnrItemsForAdditionalProducts(addedDrugInVIAs, periodBegin); requisitionFormItemViewModels.addAll(transformDataItemsToViewModels(additionalProducts)); } VIARequisitionPresenter(); @Override void loadData(long formId, Date periodEndDate); void loadEmergencyData(final List<StockCard> stockCards, final Date periodEndDate); @Override void attachView(BaseView baseView); void populateAdditionalDrugsViewModels(List<RnrFormItem> addedDrugInVIAs, Date periodBegin); void deleteRnRItemFromViewModel(final RnrFormItem rnrFormItem); @Override void updateUIAfterSubmit(); @Override void updateFormUI(); @Override void submitRequisition(); boolean processRequisition(String consultationNumbers); Observable<RnRForm> getSaveFormObservable(final String consultationNumbers); String getConsultationNumbers(); void setConsultationNumbers(String consultationNumbers); void createStockCardsOrUnarchiveAndAddToFormForAdditionalRnrItems(); Observable<Void> removeRnrItem(final RnrFormItem rnrFormItem);  }
@Test public void shouldPopulateAdditionalRnrFormItemsViewModels() throws Exception { presenter.requisitionFormItemViewModels = new ArrayList<>(); Product product1 = new ProductBuilder().setCode("P1").setIsActive(true).setIsArchived(true).build(); Product product2 = new ProductBuilder().setCode("P2").setIsActive(true).setIsArchived(false).build(); RnrFormItem rnrFormItem1 = new RnrFormItemBuilder(). setProduct(product1). setRequestAmount(100L). setCalculatedOrderQuantity(10L). build(); RnrFormItem rnrFormItem2 = new RnrFormItemBuilder(). setProduct(product2). setRequestAmount(200L). build(); when(mockProductRepository.getByCode("P1")).thenReturn(new ProductBuilder().setCode("P1").setIsActive(true).setIsArchived(false).build()); when(mockProductRepository.getByCode("P2")).thenReturn(new ProductBuilder().setCode("P2").setIsActive(true).setIsArchived(true).build()); StockCard stockCard = new StockCard(); stockCard.setId(1L); when(mockStockRepository.queryStockCardByProductId(anyLong())).thenReturn(stockCard); presenter.populateAdditionalDrugsViewModels(newArrayList(rnrFormItem1, rnrFormItem2), new Date()); assertThat(presenter.requisitionFormItemViewModels.size(), is(2)); assertThat(presenter.requisitionFormItemViewModels.get(0).getFmn(), is("P1")); assertThat(presenter.requisitionFormItemViewModels.get(1).getFmn(), is("P2")); assertThat(presenter.requisitionFormItemViewModels.get(0).getRequestAmount(), is("100")); assertThat(presenter.requisitionFormItemViewModels.get(1).getRequestAmount(), is("200")); assertThat(presenter.requisitionFormItemViewModels.get(0).getApprovedAmount(), is("100")); assertThat(presenter.requisitionFormItemViewModels.get(1).getApprovedAmount(), is("200")); }
@Test public void shouldAssignValuesToSelectedArchivedProducts() throws Exception { Date periodBegin = DateUtil.parseString("2016-01-21", DateUtil.DB_DATE_FORMAT); Date periodEnd = DateUtil.parseString("2016-02-20", DateUtil.DB_DATE_FORMAT); Product product1 = new ProductBuilder().setCode("P1").setIsActive(true).setIsArchived(true).build(); Product product2 = new ProductBuilder().setCode("P2").setIsActive(true).setIsArchived(false).build(); RnrFormItem rnrFormItem1 = new RnrFormItemBuilder().setProduct(product1).setRequestAmount(100L).build(); RnrFormItem rnrFormItem2 = new RnrFormItemBuilder().setProduct(product2).setRequestAmount(200L).build(); when(mockProductRepository.getByCode("P1")).thenReturn(product1); when(mockProductRepository.getByCode("P2")).thenReturn(product2); StockCard stockCard = new StockCardBuilder().setStockOnHand(0L).setProduct(product1).build(); StockMovementItem stockMovementItem1 = new StockMovementItemBuilder().withStockOnHand(50).withQuantity(10).withMovementType(MovementReasonManager.MovementType.ISSUE).withDocumentNo("123").build(); StockMovementItem stockMovementItem2 = new StockMovementItemBuilder().build(); StockMovementItem stockMovementItem3 = new StockMovementItemBuilder().build(); when(mockStockRepository.queryStockCardByProductId(product1.getId())).thenReturn(stockCard); when(mockStockMovementRepository.queryStockItemsByCreatedDate(stockCard.getId(), periodBegin, periodEnd)).thenReturn(newArrayList(stockMovementItem1, stockMovementItem2, stockMovementItem3)); presenter.requisitionFormItemViewModels = new ArrayList<>(); presenter.periodEndDate = periodEnd; presenter.populateAdditionalDrugsViewModels(newArrayList(rnrFormItem1, rnrFormItem2), periodBegin); assertThat(presenter.requisitionFormItemViewModels.get(0).getInitAmount(), is("60")); }