public void documentFetchDistributionHistory()

in component-test/src/main/java/org/apache/fineract/cn/payroll/PayrollApiDocumentation.java [249:312]


  public void documentFetchDistributionHistory ( ) throws Exception {

    final PayrollConfiguration payrollConf = DomainObjectGenerator.getPayrollConfiguration();
    payrollConf.setMainAccountNumber("XYVZ12345");

    final Customer customer = new Customer();
    customer.setIdentifier("splundna");

    this.prepareDistributionMocks(customer.getIdentifier(), payrollConf);
    super.testSubject.setPayrollConfiguration(customer.getIdentifier(), payrollConf);
    super.eventRecorder.wait(EventConstants.PUT_CONFIGURATION, customer.getIdentifier());

    final PayrollCollectionSheet payrollSheet = new PayrollCollectionSheet();
    payrollSheet.setSourceAccountNumber("S9R7C5A3C1C");
    final PayrollPayment firstPayrollPayment = new PayrollPayment();
    firstPayrollPayment.setCustomerIdentifier(customer.getIdentifier());
    firstPayrollPayment.setEmployer("Awa & Sons");
    firstPayrollPayment.setSalary(BigDecimal.valueOf(234.56D));

    final PayrollPayment secondPayrollPayment = new PayrollPayment();
    secondPayrollPayment.setCustomerIdentifier(customer.getIdentifier());
    secondPayrollPayment.setEmployer("Njeiforbi");
    secondPayrollPayment.setSalary(BigDecimal.valueOf(120.D));

    payrollSheet.setPayrollPayments(Lists.newArrayList(firstPayrollPayment, secondPayrollPayment));

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

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

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

    super.testSubject.distribute(payrollSheet);
    super.eventRecorder.wait(EventConstants.POST_DISTRIBUTION, payrollSheet.getSourceAccountNumber());

    this.mockMvc.perform(get("/distribution")
            .accept(MediaType.ALL_VALUE)
            .contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(status().isOk())
            .andDo(document("document-fetch-distribution-history", preprocessResponse(prettyPrint()),
                    responseFields(
                            fieldWithPath("[].identifier").description("Payroll history identifier"),
                            fieldWithPath("[].sourceAccountNumber").description("Account from which payments ensue"),
                            fieldWithPath("[].createdBy").description("Employee who distributed payroll"),
                            fieldWithPath("[].createdOn").description("Date when payroll was distributed")
                    )
            ));
  }