in component-test/src/main/java/org/apache/fineract/cn/customer/CustomerApiDocumentation.java [317:550]
public void documentFetchCustomers ( ) throws Exception {
final Customer customerOne = CustomerGenerator.createRandomCustomer();
final Customer customerTwo = CustomerGenerator.createRandomCustomer();
DateOfBirth dateOfBirthOne = new DateOfBirth();
dateOfBirthOne.setYear(Integer.valueOf(1997));
dateOfBirthOne.setMonth(Integer.valueOf(6));
dateOfBirthOne.setDay(Integer.valueOf(5));
Address addressOne = new Address();
addressOne.setStreet("Che St");
addressOne.setCity("Bali");
addressOne.setRegion("WC");
addressOne.setPostalCode("8050");
addressOne.setCountryCode("CM");
addressOne.setCountry("Cameroon");
ContactDetail contactDetailOne = new ContactDetail();
contactDetailOne.setType(ContactDetail.Type.MOBILE.name());
contactDetailOne.setGroup(ContactDetail.Group.PRIVATE.name());
contactDetailOne.setValue("675673477");
contactDetailOne.setPreferenceLevel(Integer.valueOf(1));
contactDetailOne.setValidated(Boolean.FALSE);
List <ContactDetail> contactDetailsOne = new ArrayList <>();
contactDetailsOne.add(contactDetailOne);
customerOne.setIdentifier("meni");
customerOne.setType(Customer.Type.PERSON.name());
customerOne.setGivenName("Meni");
customerOne.setMiddleName("Richmond");
customerOne.setSurname("Akom");
customerOne.setDateOfBirth(dateOfBirthOne);
customerOne.setMember(Boolean.TRUE);
customerOne.setAssignedOffice("Buea ViB");
customerOne.setAssignedEmployee("Itoh Mih");
customerOne.setAddress(addressOne);
customerOne.setContactDetails(contactDetailsOne);
customerOne.setCurrentState(Customer.State.PENDING.name());
customerOne.setAccountBeneficiary("Spouse");
customerOne.setReferenceCustomer("friend");
customerOne.setApplicationDate(LocalDate.ofYearDay(2018, 49).toString());
DateOfBirth dateOfBirthTwo = new DateOfBirth();
dateOfBirthTwo.setYear(Integer.valueOf(2000));
dateOfBirthTwo.setMonth(Integer.valueOf(6));
dateOfBirthTwo.setDay(Integer.valueOf(6));
Address addressTwo = new Address();
addressTwo.setStreet("Mile 16");
addressTwo.setCity("Buea");
addressTwo.setRegion("SWR");
addressTwo.setPostalCode("8050");
addressTwo.setCountryCode("CM");
addressTwo.setCountry("Cameroon");
ContactDetail contactDetailTwo = new ContactDetail();
contactDetailTwo.setType(ContactDetail.Type.MOBILE.name());
contactDetailTwo.setGroup(ContactDetail.Group.PRIVATE.name());
contactDetailTwo.setValue("677784712");
contactDetailTwo.setPreferenceLevel(Integer.valueOf(1));
contactDetailTwo.setValidated(Boolean.FALSE);
ContactDetail contactDetailThree = new ContactDetail();
contactDetailThree.setType(ContactDetail.Type.PHONE.name());
contactDetailThree.setGroup(ContactDetail.Group.BUSINESS.name());
contactDetailThree.setValue("237463690");
contactDetailThree.setPreferenceLevel(Integer.valueOf(2));
contactDetailThree.setValidated(Boolean.FALSE);
List <ContactDetail> contactDetailsTwo = new ArrayList <>();
contactDetailsTwo.add(contactDetailTwo);
contactDetailsTwo.add(contactDetailThree);
customerTwo.setIdentifier("bencho");
customerTwo.setType(Customer.Type.PERSON.name());
customerTwo.setGivenName("Bencho");
customerTwo.setMiddleName("Etah");
customerTwo.setSurname("Obi");
customerTwo.setDateOfBirth(dateOfBirthTwo);
customerTwo.setMember(Boolean.TRUE);
customerTwo.setAssignedOffice("Kah ViB");
customerTwo.setAssignedEmployee("Ebot Tabi");
customerTwo.setAddress(addressTwo);
customerTwo.setContactDetails(contactDetailsTwo);
customerTwo.setCurrentState(Customer.State.PENDING.name());
customerTwo.setAccountBeneficiary("Spouse");
customerTwo.setReferenceCustomer("mate");
customerTwo.setApplicationDate(LocalDate.ofYearDay(2017, 100).toString());
customerTwo.setLastModifiedBy("Nalowa");
customerTwo.setLastModifiedOn(LocalDate.ofYearDay(2018, 40).toString());
Stream.of(customerOne, customerTwo)
.forEach(customer -> {
this.customerManager.createCustomer(customer);
try {
this.eventRecorder.wait(CustomerEventConstants.POST_CUSTOMER, customer.getIdentifier());
} catch (final InterruptedException ex) {
Assert.fail(ex.getMessage());
}
});
final CustomerPage customerPage = this.customerManager.fetchCustomers(null, null, 0, 20, null, null);
Assert.assertTrue(customerPage.getTotalElements() >= 2);
this.mockMvc.perform(get("/customers")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE))
.andExpect(status().isOk())
.andDo(document("document-fetch-customers", preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
responseFields(
fieldWithPath("customers").type("List<Customer>").description("The List of Customers +\n"),
fieldWithPath("totalPages").type("Integer").description("Number of pages"),
fieldWithPath("totalElements").type("Long").description("Number of customers in page"),
fieldWithPath("customers[].identifier").type("String").description("First customer's identifier"),
fieldWithPath("customers[].type").type("Type").description("The type of first customer +\n" +
" +\n" +
"*enum* _Type_ { +\n" +
" PERSON, +\n" +
" BUSINESS +\n" +
" } +"),
fieldWithPath("customers[].givenName").description("first customer's given name"),
fieldWithPath("customers[].middleName").description("first customer's middle name"),
fieldWithPath("customers[].surname").description("first customer's surName"),
fieldWithPath("customers[].dateOfBirth").type("DateOfBirth").description("first customer's date of birth +\n" +
" +\n" +
" _DateOfBirth_ { +\n" +
" *Integer* year, +\n" +
" *Integer* month, +\n" +
" *Integer* day, +\n" +
"} +"),
fieldWithPath("customers[].member").description("Is customer a member of the MFI ?"),
fieldWithPath("customers[].assignedOffice").description("first customer's assigned office"),
fieldWithPath("customers[].assignedEmployee").description("first customer's assigned employee"),
fieldWithPath("customers[].address").type("Address").description("first customer's physical address +\n" +
" +\n" +
"_Address_ { +\n" +
"*String* street, +\n" +
"*String* city, +\n" +
"*String* region, +\n" +
"*String* postalCode, +\n" +
"*String* countryCode, +\n" +
"*String* country } +"),
fieldWithPath("customers[].contactDetails").type("List<ContactDetail>").description("first customer's contact details +\n" +
" +\n" +
"_ContactDetail_ { +\n" +
" *enum* _Type_ { +\n" +
" EMAIL, +\n" +
" PHONE, +\n" +
" MOBILE +\n" +
" } type, +\n" +
" *enum* _Group_ { +\n" +
" BUSINESS, +\n" +
" PRIVATE +\n" +
" } group, +\n" +
" *String* value +\n" +
" } +"),
fieldWithPath("customers[].currentState").type("State").description("first customer's current state +\n" +
" +\n" +
"*enum* _State_ { +\n" +
" PENDING, +\n" +
" ACTIVE, +\n" +
" LOCKED, +\n" +
" CLOSED +\n" +
" } +"),
fieldWithPath("customers[].accountBeneficiary").description("first customer's beneficiary"),
fieldWithPath("customers[].referenceCustomer").description("first customer's reference"),
fieldWithPath("customers[].applicationDate").description("The date first customer applied for account"),
fieldWithPath("customers[].customValues").type("List<Value>").description("first customer's custom values"),
fieldWithPath("customers[].createdBy").description("employee who created first customer's account"),
fieldWithPath("customers[].createdOn").description("Date and time when first customer's account was created"),
fieldWithPath("customers[].lastModifiedBy").type("String").description("Employee who last modified first customer's account"),
fieldWithPath("customers[].lastModifiedOn").type("String").description("Date and time first customer's account was last modified"),
fieldWithPath("customers[1].identifier").description("Second customer's identifier"),
fieldWithPath("customers[1].type").type("Type").description("The type of the second customer +\n" +
" +\n" +
"*enum* _Type_ { +\n" +
" PERSON, +\n" +
" BUSINESS +\n" +
" } +"),
fieldWithPath("customers[1].givenName").description("The second customer's given name"),
fieldWithPath("customers[1].middleName").description("The second customer's middle name"),
fieldWithPath("customers[1].surname").description("The second customer's surName"),
fieldWithPath("customers[1].dateOfBirth").type("DateOfBirth").description("The second customer's date of birth +\n" +
" +\n" +
" _DateOfBirth_ { +\n" +
" *Integer* year, +\n" +
" *Integer* month, +\n" +
" *Integer* day, +\n" +
"} +"),
fieldWithPath("customers[1].member").description("Is second customer a member of the MFI ?"),
fieldWithPath("customers[1].assignedOffice").description("The second customer's assigned office"),
fieldWithPath("customers[1].assignedEmployee").description("The second customer's assigned employee"),
fieldWithPath("customers[1].address").type("Address").description("second customer's physical address +\n" +
" +\n" +
"_Address_ { +\n" +
"*String* street, +\n" +
"*String* city, +\n" +
"*String* region, +\n" +
"*String* postalCode, +\n" +
"*String* countryCode, +\n" +
"*String* country } +"),
fieldWithPath("customers[1].contactDetails").type("List<ContactDetail>").description("second customer's contact details +\n" +
" +\n" +
"_ContactDetail_ { +\n" +
" *enum* _Type_ { +\n" +
" EMAIL, +\n" +
" PHONE, +\n" +
" MOBILE +\n" +
" } type, +\n" +
" *enum* _Group_ { +\n" +
" BUSINESS, +\n" +
" PRIVATE +\n" +
" } group, +\n" +
" *String* value +\n" +
" } +"),
fieldWithPath("customers[1].currentState").type("State").description("The second customer's current state +\n" +
" +\n" +
"*enum* _State_ { +\n" +
" PENDING, +\n" +
" ACTIVE, +\n" +
" LOCKED, +\n" +
" CLOSED +\n" +
" } +"),
fieldWithPath("customers[1].accountBeneficiary").description("The second customer's beneficiary"),
fieldWithPath("customers[1].referenceCustomer").description("The second customer's reference"),
fieldWithPath("customers[1].applicationDate").description("The date second customer applied for account"),
fieldWithPath("customers[1].customValues").type("List<Value>").description("Second customer's custom values"),
fieldWithPath("customers[1].createdBy").description("User who created second customer's account"),
fieldWithPath("customers[1].createdOn").description("Date and time when second customer's account was created"),
fieldWithPath("customers[1].lastModifiedBy").type("String").description("Employee who last modified second customer's account"),
fieldWithPath("customers[1].lastModifiedOn").type("String").description("Date and time second customer's account was last modified"))));
}