in component-test/src/main/java/org/apache/fineract/cn/accounting/AccountApiDocumentation.java [346:436]
public void documentFetchAccountsForTerm ( ) 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 Ledger ledger = LedgerGenerator.createRandomLedger();
ledger.setIdentifier("2100");
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account salesAccountOne = AccountGenerator.createAccount(
"Organic Sales", "2100.1", AccountType.REVENUE);
salesAccountOne.setName("Organic Maize");
salesAccountOne.setHolders(holdersListOne);
salesAccountOne.setSignatureAuthorities(signatoriesOne);
salesAccountOne.setBalance(225.0);
final Account salesAccountTwo = AccountGenerator.createAccount(
"Inorganic Sales", "100", AccountType.REVENUE);
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);
});
List <Account> accountListForTerm = new ArrayList <>();
Stream.of(salesAccountOne, salesAccountTwo).
forEach(acc -> {
if (acc.getIdentifier().contains(ledger.getIdentifier()))
accountListForTerm.add(acc);
});
Assert.assertTrue(accountListForTerm.size() == 1);
final AccountPage accountPage =
this.testSubject.fetchAccounts(true, ledger.getIdentifier(), null, true,
0, 3, null, null);
accountPage.setAccounts(accountListForTerm);
accountPage.setTotalElements(new Long(accountListForTerm.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-for-term", 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")
)));
}