in component-test/src/main/java/org/apache/fineract/cn/accounting/AccountApiDocumentation.java [439:564]
public void documentFetchActiveAccounts ( ) 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> holdersListThree = new HashSet <>();
String holderThree = "Holder Three";
holdersListThree.add(holderThree);
Set <String> holdersListFour = new HashSet <>();
String holderFour = "Holder Four";
holdersListFour.add(holderFour);
Set <String> signatoriesOne = new HashSet <>();
String signatureOne = "Signatory One";
signatoriesOne.add(signatureOne);
Set <String> signatoriesTwo = new HashSet <>();
String signatureTwo = "Signatory Two";
signatoriesTwo.add(signatureTwo);
Set <String> signatoriesThree = new HashSet <>();
String signatureThree = "Signatory Three";
signatoriesThree.add(signatureThree);
Set <String> signatoriesFour = new HashSet <>();
String signatureFour = "Signatory Four";
signatoriesFour.add(signatureFour);
final Ledger ledger = LedgerGenerator.createRandomLedger();
ledger.setIdentifier("3100");
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account salesAccountOne = AccountGenerator.createAccount(
"Organic Sales", "3100.10", AccountType.REVENUE);
salesAccountOne.setState(Account.State.OPEN.name());
salesAccountOne.setName("Organic Maize");
salesAccountOne.setHolders(holdersListOne);
salesAccountOne.setSignatureAuthorities(signatoriesOne);
salesAccountOne.setBalance(225.0);
salesAccountOne.setState(Account.State.CLOSED.name());
final Account salesAccountTwo = AccountGenerator.createAccount(
"Inorganic Sales", "3100.20", AccountType.REVENUE);
salesAccountTwo.setState(Account.State.OPEN.name());
salesAccountTwo.setName("Organic Pens");
salesAccountTwo.setHolders(holdersListTwo);
salesAccountTwo.setSignatureAuthorities(signatoriesTwo);
salesAccountTwo.setBalance(895.0);
final Account salesAccountThree = AccountGenerator.createAccount(
"Organic Sales", "3100.30", AccountType.REVENUE);
salesAccountThree.setState(Account.State.OPEN.name());
salesAccountThree.setName("Organic Peas");
salesAccountThree.setHolders(holdersListThree);
salesAccountThree.setSignatureAuthorities(signatoriesThree);
salesAccountThree.setBalance(953.0);
salesAccountOne.setState(Account.State.CLOSED.name());
final Account salesAccountFour = AccountGenerator.createAccount(
"Inorganic Sales", "3100.40", AccountType.REVENUE);
salesAccountFour.setState(Account.State.OPEN.name());
salesAccountFour.setName("Organic Pencils");
salesAccountFour.setHolders(holdersListFour);
salesAccountFour.setSignatureAuthorities(signatoriesFour);
salesAccountFour.setBalance(345.0);
List <Account> accountList = new ArrayList <>();
Stream.of(salesAccountOne, salesAccountTwo, salesAccountThree, salesAccountFour).forEach(account -> {
accountList.add(account);
});
List <Account> listOfActiveAccounts = new ArrayList <>();
Stream.of(salesAccountOne, salesAccountTwo, salesAccountThree, salesAccountFour).
forEach(acc -> {
if (acc.getState() == Account.State.OPEN.name())
listOfActiveAccounts.add(acc);
});
final AccountPage accountPage =
this.testSubject.fetchAccounts(true, ledger.getIdentifier(), null, true,
0, 3, null, null);
accountPage.setAccounts(listOfActiveAccounts);
accountPage.setTotalElements(new Long(listOfActiveAccounts.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-active-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("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")
)));
}