private void step3IImportCaseWhenAccountsDontExistYet()

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


  private void step3IImportCaseWhenAccountsDontExistYet(final LocalDateTime forDateTime) throws InterruptedException {
    logger.info("step3IImportCaseWhenAccountsDontExistYet");

    final BigDecimal currentPrincipal = BigDecimal.valueOf(2_000_00, MINOR_CURRENCY_UNIT_DIGITS);

    final AccountAssignment customerLoanPrincipalAccountAssignment = new AccountAssignment();
    customerLoanPrincipalAccountAssignment.setDesignator(AccountDesignators.CUSTOMER_LOAN_PRINCIPAL);
    customerLoanPrincipalAccountAssignment.setAlternativeAccountNumber("external-system-sourced-customer-loan-principal-account-identifier");
    customerLoanPrincipalAccountAssignment.setLedgerIdentifier(AccountDesignators.CUSTOMER_LOAN_GROUP);
    final AccountAssignment customerLoanInterestAccountAssignment = new AccountAssignment();
    customerLoanInterestAccountAssignment.setDesignator(AccountDesignators.CUSTOMER_LOAN_INTEREST);
    customerLoanInterestAccountAssignment.setAlternativeAccountNumber("external-system-sourced-customer-loan-interest-account-identifier");
    customerLoanInterestAccountAssignment.setLedgerIdentifier(AccountDesignators.CUSTOMER_LOAN_GROUP);
    final AccountAssignment customerLoanFeeAccountAssignment = new AccountAssignment();
    customerLoanFeeAccountAssignment.setDesignator(AccountDesignators.CUSTOMER_LOAN_FEES);
    customerLoanFeeAccountAssignment.setAlternativeAccountNumber("external-system-sourced-customer-loan-fees-account-identifier");
    customerLoanFeeAccountAssignment.setLedgerIdentifier(AccountDesignators.CUSTOMER_LOAN_GROUP);
    final ArrayList<AccountAssignment> importAccountAssignments = new ArrayList<>();
    importAccountAssignments.add(customerLoanPrincipalAccountAssignment);
    importAccountAssignments.add(customerLoanInterestAccountAssignment);
    importAccountAssignments.add(customerLoanFeeAccountAssignment);

    final ImportParameters importParameters = new ImportParameters();
    importParameters.setCaseAccountAssignments(importAccountAssignments);
    importParameters.setPaymentSize(IMPORTED_NEXT_REPAYMENT_AMOUNT);
    importParameters.setCreatedOn(DateConverter.toIsoString(forDateTime));
    importParameters.setCurrentBalances(Collections.singletonMap(AccountDesignators.CUSTOMER_LOAN_PRINCIPAL, currentPrincipal));
    importParameters.setStartOfTerm(DateConverter.toIsoString(forDateTime));
    portfolioManager.executeImportCommand(product.getIdentifier(), customerCase.getIdentifier(), importParameters);

    Assert.assertTrue(eventRecorder.wait(IndividualLoanEventConstants.IMPORT_INDIVIDUALLOAN_CASE, new IndividualLoanCommandEvent(product.getIdentifier(), customerCase.getIdentifier(), DateConverter.toIsoString(forDateTime))));

    final String customerLoanLedgerIdentifier = AccountingFixture.verifyLedgerCreation(
        ledgerManager,
        AccountingFixture.CUSTOMER_LOAN_LEDGER_IDENTIFIER,
        AccountType.ASSET);

    customerLoanPrincipalIdentifier =
        AccountingFixture.verifyAccountCreationMatchingDesignator(
            ledgerManager, customerLoanLedgerIdentifier,
            AccountDesignators.CUSTOMER_LOAN_PRINCIPAL,
            customerLoanPrincipalAccountAssignment.getAlternativeAccountNumber(),
            AccountType.ASSET,
            currentPrincipal);
    customerLoanInterestIdentifier =
        AccountingFixture.verifyAccountCreationMatchingDesignator(
            ledgerManager,
            customerLoanLedgerIdentifier,
            AccountDesignators.CUSTOMER_LOAN_INTEREST,
            customerLoanInterestAccountAssignment.getAlternativeAccountNumber(),
            AccountType.ASSET,
            BigDecimal.ZERO);
    customerLoanFeeIdentifier =
        AccountingFixture.verifyAccountCreationMatchingDesignator(
            ledgerManager,
            customerLoanLedgerIdentifier,
            AccountDesignators.CUSTOMER_LOAN_FEES,
            customerLoanFeeAccountAssignment.getAlternativeAccountNumber(),
            AccountType.ASSET,
            BigDecimal.ZERO);

    final CaseStatus changedCaseStatus = portfolioManager.getCaseStatus(product.getIdentifier(), customerCase.getIdentifier());
    Assert.assertEquals(Case.State.ACTIVE.name(), changedCaseStatus.getCurrentState());
    Assert.assertEquals(DateConverter.toIsoString(forDateTime), changedCaseStatus.getStartOfTerm());
    Assert.assertEquals("2018-02-08T00:00:00Z", changedCaseStatus.getEndOfTerm());
    checkNextActionsCorrect(product.getIdentifier(), customerCase.getIdentifier(),
        Action.APPLY_INTEREST, Action.MARK_LATE, Action.ACCEPT_PAYMENT, Action.DISBURSE, Action.MARK_IN_ARREARS, Action.WRITE_OFF, Action.CLOSE);

    expectedCurrentPrincipal = currentPrincipal;
    updateBalanceMock();

    final Case changedCase = portfolioManager.getCase(product.getIdentifier(), customerCase.getIdentifier());
    final Map<String, String> designatorsAssignedForCase = changedCase.getAccountAssignments().stream()
        .collect(Collectors.toMap(AccountAssignment::getDesignator, AccountAssignment::getAccountIdentifier));
    Assert.assertEquals(
        customerLoanPrincipalIdentifier,
        designatorsAssignedForCase.get(AccountDesignators.CUSTOMER_LOAN_PRINCIPAL));
    Assert.assertEquals(
        customerLoanInterestIdentifier,
        designatorsAssignedForCase.get(AccountDesignators.CUSTOMER_LOAN_INTEREST));
    Assert.assertEquals(
        customerLoanFeeIdentifier,
        designatorsAssignedForCase.get(AccountDesignators.CUSTOMER_LOAN_FEES));
  }