public void documentFetchAccountEntries()

in component-test/src/main/java/org/apache/fineract/cn/accounting/AccountApiDocumentation.java [942:1018]


  public void documentFetchAccountEntries ( ) throws Exception {

    final Ledger ledger = LedgerGenerator.createRandomLedger();
    ledger.setIdentifier("1500");
    this.testSubject.createLedger(ledger);
    this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());

    final Account accountToDebit = AccountGenerator.createRandomAccount(ledger.getIdentifier());
    accountToDebit.setIdentifier("1501");
    this.testSubject.createAccount(accountToDebit);
    this.eventRecorder.wait(EventConstants.POST_ACCOUNT, accountToDebit.getIdentifier());

    final Account accountToCredit = AccountGenerator.createRandomAccount(ledger.getIdentifier());
    accountToCredit.setIdentifier("1601");
    this.testSubject.createAccount(accountToCredit);
    this.eventRecorder.wait(EventConstants.POST_ACCOUNT, accountToCredit.getIdentifier());

    final int journalEntryCount = 3;
    final List <JournalEntry> journalEntries = Stream.generate(( ) -> JournalEntryGenerator.createRandomJournalEntry(accountToDebit, "5.0", accountToCredit, "5.0"))
            .limit(journalEntryCount)
            .collect(Collectors.toList());

    journalEntries.stream()
            .forEach(entry -> {
              entry.setMessage("Message " + journalEntries.indexOf(entry));
            });

    journalEntries.stream()
            .map(jEntry -> {
              this.testSubject.createJournalEntry(jEntry);
              return jEntry.getTransactionIdentifier();
            })
            .forEach(transactionId -> {
              try {
                this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, transactionId);
                this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, transactionId);
              } catch (final InterruptedException e) {
                throw new RuntimeException(e);
              }
            });

    Thread.sleep(20L); // Short pause to make sure it really is last.

    final LocalDate today = LocalDate.now(Clock.systemUTC());
    final String todayDateRange = new DateRange(today, today).toString();

    final AccountEntryPage accountEntriesPage =
            this.testSubject.fetchAccountEntries(accountToCredit.getIdentifier(), todayDateRange, "Entries Fetched", 0,
                    1, "ASC", Sort.Direction.ASC.name());

    Gson gson = new Gson();
    this.mockMvc.perform(get("/accounts/" + accountToCredit.getIdentifier() + "/entries")
            .contentType(MediaType.APPLICATION_JSON_VALUE)
            /*.content(gson.toJson(accountEntriesPage))*/
            .accept(MediaType.ALL_VALUE))
            .andExpect(status().isOk())
            .andDo(document("document-fetch-account-entries", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
                    responseFields(
                            fieldWithPath("accountEntries").type("List<AccountEntry>").description("List of account entries"),
                            fieldWithPath("accountEntries[].type").description("Type of entry DEBIT or CREDIT "),
                            fieldWithPath("accountEntries[].transactionDate").description("Date of transaction"),
                            fieldWithPath("accountEntries[].message").description("Transaction message"),
                            fieldWithPath("accountEntries[].amount").description("Transaction amount"),
                            fieldWithPath("accountEntries[].balance").description("Transaction balance"),
                            fieldWithPath("accountEntries[1].type").description("Type of entry DEBIT or CREDIT "),
                            fieldWithPath("accountEntries[1].transactionDate").description("Date of transaction"),
                            fieldWithPath("accountEntries[1].message").description("Transaction message"),
                            fieldWithPath("accountEntries[1].amount").description("Transaction amount"),
                            fieldWithPath("accountEntries[1].balance").description("Transaction balance"),
                            fieldWithPath("accountEntries[2].type").description("Type of entry DEBIT or CREDIT "),
                            fieldWithPath("accountEntries[2].transactionDate").description("Date of transaction"),
                            fieldWithPath("accountEntries[2].message").description("Transaction message"),
                            fieldWithPath("accountEntries[2].amount").description("Transaction amount"),
                            fieldWithPath("accountEntries[2].balance").description("Transaction balance"),
                            fieldWithPath("totalPages").type("List<AccountEntry>").description("Reopen comment"),
                            fieldWithPath("totalElements").type("List<AccountEntry>").description("Reopen comment"))));
  }