public void documentFetchPayments()

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


  public void documentFetchPayments ( ) throws Exception {

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

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

    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("O3C87O643E45C4");
    final PayrollPayment firstPayrollPayment = new PayrollPayment();
    firstPayrollPayment.setCustomerIdentifier(customer.getIdentifier());
    firstPayrollPayment.setEmployer("Nkwane");
    firstPayrollPayment.setSalary(BigDecimal.valueOf(945));

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

    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)
    );

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

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

    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());

    this.mockMvc.perform(get("/distribution/" + payrollCollectionHistories.get(0).getIdentifier() + "/payments")
            .accept(MediaType.ALL_VALUE)
            .contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(status().isOk())
            .andDo(document("document-fetch-payments", preprocessResponse(prettyPrint()),
                    responseFields(
                            fieldWithPath("payrollPayments[0].customerIdentifier").description("second customer's identifier"),
                            fieldWithPath("payrollPayments[0].employer").description("second customer's employer"),
                            fieldWithPath("payrollPayments[0].salary").description("second customer's salary"),
                            fieldWithPath("payrollPayments[0].processed").description("second customer's employer"),
                            fieldWithPath("payrollPayments[0].message").description("second customer's salary"),
                            fieldWithPath("totalPages").type("Integer").description("Pages of payroll payments"),
                            fieldWithPath("totalElements").type("Integer").description("Number of payroll payments")
                    )
            ));
  }