public void shouldUpdatePayrollDistribution()

in component-test/src/main/java/org/apache/fineract/cn/payroll/TestPayrollConfiguration.java [61:97]


  public void shouldUpdatePayrollDistribution() 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 PayrollAllocation newPayrollAllocation = new PayrollAllocation();
    payrollConfiguration.setPayrollAllocations(Lists.newArrayList(newPayrollAllocation));
    newPayrollAllocation.setAccountNumber(RandomStringUtils.randomAlphanumeric(34));
    newPayrollAllocation.setAmount(BigDecimal.valueOf(15.00D));
    newPayrollAllocation.setProportional(Boolean.FALSE);

    Mockito
        .doAnswer(invocation -> Optional.of(new Account()))
        .when(this.accountingAdaptorSpy).findAccount(Matchers.eq(newPayrollAllocation.getAccountNumber()));

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

    Thread.sleep(500L);

    final PayrollConfiguration fetchedPayrollConfiguration =
        super.testSubject.findPayrollConfiguration(customerIdentifier);

    Assert.assertNotNull(fetchedPayrollConfiguration.getLastModifiedBy());
    Assert.assertNotNull(fetchedPayrollConfiguration.getLastModifiedOn());
    Assert.assertEquals(1, fetchedPayrollConfiguration.getPayrollAllocations().size());

    final Optional<PayrollAllocation> optionalPayrollAllocation =
        fetchedPayrollConfiguration.getPayrollAllocations().stream().findFirst();

    Assert.assertTrue(optionalPayrollAllocation.isPresent());

    this.comparePayrollAllocations(newPayrollAllocation, optionalPayrollAllocation.get());
  }