public void documentDistributePayments()

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


  public void documentDistributePayments ( ) throws Exception {

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

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

    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("S1R2C3A4C5C6");
    final PayrollPayment firstPayrollPayment = new PayrollPayment();
    firstPayrollPayment.setCustomerIdentifier(customer.getIdentifier());
    firstPayrollPayment.setEmployer("The Shop");
    firstPayrollPayment.setSalary(BigDecimal.valueOf(1234.56D));

    final PayrollPayment secondPayrollPayment = new PayrollPayment();
    secondPayrollPayment.setCustomerIdentifier(customer.getIdentifier());
    secondPayrollPayment.setEmployer("The Tank");
    secondPayrollPayment.setSalary(BigDecimal.valueOf(14.54D));

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

    Gson gson = new Gson();
    this.mockMvc.perform(post("/distribution")
            .contentType(MediaType.APPLICATION_JSON_VALUE)
            .content(gson.toJson(payrollSheet)))
            .andExpect(status().isAccepted())
            .andDo(document("document-distribute-payments", preprocessRequest(prettyPrint()),
                    requestFields(
                            fieldWithPath("sourceAccountNumber").description("Account from which payments ensue"),
                            fieldWithPath("payrollPayments[].customerIdentifier").description("first customer's identifier"),
                            fieldWithPath("payrollPayments[].employer").description("first customer's employer"),
                            fieldWithPath("payrollPayments[].salary").description("first customer's salary"),
                            fieldWithPath("payrollPayments[1].customerIdentifier").description("second customer's identifier"),
                            fieldWithPath("payrollPayments[1].employer").description("second customer's employer"),
                            fieldWithPath("payrollPayments[1].salary").description("second customer's salary")
                    )));
  }