in component-test/src/main/java/org/apache/fineract/cn/accounting/LedgerApiDocumentation.java [361:439]
public void documentFetchAccountsForLedger ( ) throws Exception {
Set <String> holdersListOne = new HashSet <>();
String holderOne = "Holder One";
holdersListOne.add(holderOne);
Set <String> signatoriesOne = new HashSet <>();
String signatureOne = "Signatory One";
signatoriesOne.add(signatureOne);
final Ledger liabilityLedger = LedgerGenerator.createRandomLedger();
liabilityLedger.setType(AccountType.LIABILITY.name());
liabilityLedger.setIdentifier("6100");
this.testSubject.createLedger(liabilityLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier());
final List <Account> createdLiabilityAccounts = Stream.generate(( ) -> AccountGenerator.createRandomAccount(liabilityLedger.getIdentifier())).limit(1)
.peek(account -> {
account.setType(AccountType.LIABILITY.name());
account.setIdentifier("6100.10");
account.setName("First Account Of " + liabilityLedger.getIdentifier());
account.setHolders(holdersListOne);
account.setSignatureAuthorities(signatoriesOne);
account.setBalance(1234.0);
account.setLedger(liabilityLedger.getIdentifier());
this.testSubject.createAccount(account);
})
.collect(Collectors.toList());
createdLiabilityAccounts.stream().forEach(
account -> {
try {
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account.getIdentifier());
} catch (InterruptedException e) {
e.printStackTrace();
}
});
final AccountPage accountPage =
this.testSubject.fetchAccounts(true, liabilityLedger.getIdentifier(), null, true,
0, createdLiabilityAccounts.size(), null, null);
accountPage.setAccounts(createdLiabilityAccounts);
accountPage.setTotalElements(new Long(createdLiabilityAccounts.size()));
accountPage.setTotalPages(1);
Gson gson = new Gson();
this.mockMvc.perform(get("/ledgers/" + liabilityLedger.getIdentifier() + "/accounts")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE)
.content(gson.toJson(accountPage)))
.andExpect(status().isOk())
.andDo(document("document-fetch-accounts-for-ledger", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("accounts").type("List<Account>").description("List of Accounts"),
fieldWithPath("accounts[].type").description("AccountType").description("Type of first Account " +
" + \n" +
" + \n" +
" *enum* _AccountType_ { + \n" +
" ASSET, + \n" +
" LIABILITY, + \n" +
" EQUITY, + \n" +
" REVENUE, + \n" +
" EXPENSE + \n" +
"}"),
fieldWithPath("accounts[].identifier").type("String").description("first account identifier"),
fieldWithPath("accounts[].name").type("String").description("first account name"),
fieldWithPath("accounts[].holders").type("Set<String>").description("Set of account holders"),
fieldWithPath("accounts[].signatureAuthorities").type("Set<String>").description("Set of signatories to account"),
fieldWithPath("accounts[].balance").type("Double").description("first account's balance"),
fieldWithPath("accounts[].ledger").type("String").description("Associated ledger"),
fieldWithPath("totalPages").type("Integer").description("Total pages"),
fieldWithPath("totalElements").type("Integer").description("Total accounts in page")
),
responseFields(
fieldWithPath("accounts").type("List<Account>").description("List of Accounts"),
fieldWithPath("totalPages").type("Integer").description("Total number of pages"),
fieldWithPath("totalElements").type("String").description("Total number of elements")
)));
}