public void workflowImportingLoanFromExternalSystem()

in component-test/src/main/java/org/apache/fineract/cn/portfolio/TestAccountingInteractionInLoanWorkflow.java [121:162]


  public void workflowImportingLoanFromExternalSystem() throws InterruptedException {
    final LocalDateTime initialDisbursalDate = LocalDateTime.of(2017,11,8,0,0);
    final LocalDateTime today = LocalDateTime.of(2017,11,22,0,0);

    step1CreateProduct();
    step2CreateCase();
    step3IImportCaseWhenAccountsDontExistYet(initialDisbursalDate);

    final List<PlannedPayment> plannedPayments = individualLending.getPaymentScheduleForCaseStream(
        product.getIdentifier(),
        customerCase.getIdentifier(),
        null)
        .collect(Collectors.toList());

    int week = 3;
    while (expectedCurrentPrincipal.compareTo(BigDecimal.ZERO) > 0) {
      logger.info("Simulating week {}. Expected current principal {}.", week, expectedCurrentPrincipal);
      step6CalculateInterestAndCheckForLatenessForWeek(today, week);
      final BigDecimal interestAccruedBeforePayment = interestAccrued;
      final BigDecimal nextRepaymentAmount = findNextRepaymentAmount(today.plusDays((week+1)*7));
      final BigDecimal totalDue = expectedCurrentPrincipal.add(interestAccrued).add(nonLateFees);
      if (totalDue.compareTo(IMPORTED_NEXT_REPAYMENT_AMOUNT) >= 0)
        Assert.assertEquals(IMPORTED_NEXT_REPAYMENT_AMOUNT, nextRepaymentAmount);
      else
        Assert.assertEquals(totalDue, nextRepaymentAmount);
      final Payment payment = step7PaybackPartialAmount(
          nextRepaymentAmount,
          today.plusDays((week + 1) * 7),
          BigDecimal.ZERO,
          nextRepaymentAmount,
          AccountingFixture.CUSTOMERS_DEPOSIT_ACCOUNT);
      final BigDecimal interestAccrual = payment.getBalanceAdjustments().remove(AccountDesignators.INTEREST_ACCRUAL); //Don't compare these with planned payment.
      final BigDecimal customerLoanInterest = payment.getBalanceAdjustments().remove(AccountDesignators.CUSTOMER_LOAN_INTEREST);
      Assert.assertEquals("week " + week, interestAccrual.negate(), customerLoanInterest);
      Assert.assertEquals("week " + week, interestAccruedBeforePayment, customerLoanInterest);
      //TODO: Assert.assertEquals("week " + week, plannedPayments.get(week+1).getPayment(), payment);
      week++;
    }

    step8Close(DateConverter
        .fromIsoString(plannedPayments.get(plannedPayments.size()-1).getPayment().getDate()));
  }