public void shouldDistributePayments()

in component-test/src/main/java/org/apache/fineract/cn/payroll/TestPayrollDistribution.java [58:101]


  public void shouldDistributePayments() throws Exception {
    final String customerIdentifier = RandomStringUtils.randomAlphanumeric(32);
    final PayrollConfiguration payrollConfiguration = DomainObjectGenerator.getPayrollConfiguration();
    this.prepareMocks(customerIdentifier, payrollConfiguration);

    super.testSubject.setPayrollConfiguration(customerIdentifier, payrollConfiguration);
    Assert.assertTrue(super.eventRecorder.wait(EventConstants.PUT_CONFIGURATION, customerIdentifier));

    final PayrollCollectionSheet payrollCollectionSheet = new PayrollCollectionSheet();
    payrollCollectionSheet.setSourceAccountNumber(RandomStringUtils.randomAlphanumeric(34));
    final PayrollPayment payrollPayment = new PayrollPayment();
    payrollPayment.setCustomerIdentifier(customerIdentifier);
    payrollPayment.setEmployer("ACME, Inc.");
    payrollPayment.setSalary(BigDecimal.valueOf(1234.56D));
    payrollCollectionSheet.setPayrollPayments(Lists.newArrayList(payrollPayment));

    final Account sourceAccount = new Account();
    sourceAccount.setState(Account.State.OPEN.name());
    Mockito
        .doAnswer(invocation -> Optional.of(sourceAccount))
        .when(this.accountingAdaptorSpy).findAccount(Matchers.eq(payrollCollectionSheet.getSourceAccountNumber()));

    Mockito
        .doAnswer(invocation -> Optional.empty())
        .when(this.accountingAdaptorSpy).postPayrollPayment(
        Matchers.any(PayrollCollectionEntity.class),
        Matchers.refEq(payrollPayment),
        Matchers.any(PayrollConfiguration.class)
    );

    super.testSubject.distribute(payrollCollectionSheet);
    Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_DISTRIBUTION, payrollCollectionSheet.getSourceAccountNumber()));

    final List<PayrollCollectionHistory> payrollCollectionHistories = super.testSubject.fetchDistributionHistory();
    Assert.assertEquals(1, payrollCollectionHistories.size());

    final PayrollCollectionHistory payrollCollectionHistory = payrollCollectionHistories.get(0);
    final PayrollPaymentPage payrollPaymentPage =
        super.testSubject.fetchPayments(payrollCollectionHistory.getIdentifier(), 0, 10, null, null);
    Assert.assertEquals(Long.valueOf(1L), payrollPaymentPage.getTotalElements());

    final PayrollPayment fetchedPayrollPayment = payrollPaymentPage.getPayrollPayments().get(0);
    Assert.assertTrue(fetchedPayrollPayment.getProcessed());
  }