in component-test/src/main/java/org/apache/fineract/cn/accounting/AccountApiDocumentation.java [245:343]
public void documentFetchAccounts ( ) throws Exception {
Set <String> holdersListOne = new HashSet <>();
String holderOne = "Holder One";
holdersListOne.add(holderOne);
Set <String> holdersListTwo = new HashSet <>();
String holderTwo = "Holder Two";
holdersListTwo.add(holderTwo);
Set <String> signatoriesOne = new HashSet <>();
String signatureOne = "Signatory One";
signatoriesOne.add(signatureOne);
Set <String> signatoriesTwo = new HashSet <>();
String signatureTwo = "Signatory Two";
signatoriesTwo.add(signatureTwo);
final Account salesAccountOne = AccountGenerator.createAccount(
"Organic Sales", "1111", AccountType.EXPENSE);
salesAccountOne.setName("Organic Maize");
salesAccountOne.setHolders(holdersListOne);
salesAccountOne.setSignatureAuthorities(signatoriesOne);
salesAccountOne.setBalance(225.0);
final Account salesAccountTwo = AccountGenerator.createAccount(
"Inorganic Sales", "1112", AccountType.EXPENSE);
salesAccountTwo.setName("Organic Beans");
salesAccountTwo.setHolders(holdersListTwo);
salesAccountTwo.setSignatureAuthorities(signatoriesTwo);
salesAccountTwo.setBalance(895.0);
List <Account> accountList = new ArrayList <>();
Stream.of(salesAccountOne, salesAccountTwo).forEach(account -> {
accountList.add(account);
});
final Ledger ledger = LedgerGenerator.createRandomLedger();
ledger.setIdentifier("11021");
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final AccountPage accountPage =
this.testSubject.fetchAccounts(true, null, null, true,
0, 3, null, null);
accountPage.setAccounts(accountList);
accountPage.setTotalElements(new Long(accountList.size()));
accountPage.setTotalPages(1);
Gson gson = new Gson();
this.mockMvc.perform(get("/accounts")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE)
.content(gson.toJson(accountPage)))
.andExpect(status().isOk())
.andDo(document("document-fetch-accounts", 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("accounts[1].type").description("AccountType").description("Type of second Account " +
" + \n" +
" + \n" +
" *enum* _AccountType_ { + \n" +
" ASSET, + \n" +
" LIABILITY, + \n" +
" EQUITY, + \n" +
" REVENUE, + \n" +
" EXPENSE + \n" +
"}"),
fieldWithPath("accounts[1].identifier").type("String").description("second account identifier"),
fieldWithPath("accounts[1].name").type("String").description("second account's name"),
fieldWithPath("accounts[1].holders").type("Set<String>").description("Set of account holders"),
fieldWithPath("accounts[1].signatureAuthorities").type("Set<String>").description("Set of signatories to account"),
fieldWithPath("accounts[1].balance").type("Double").description("second account balance"),
fieldWithPath("accounts[1].ledger").type("String").description("Associated ledger"),
fieldWithPath("totalPages").type("Integer").description("Total number of pages"),
fieldWithPath("totalElements").type("String").description("Total number of elements")
),
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")
)));
}