use of org.mifos.customers.client.business.ClientBO in project head by mifos.
the class GroupValidationTest method givenAnActiveSavingsAccountExistsOnClientOfGroupGroupTransferToCenterShouldFailValidation.
@Test
public void givenAnActiveSavingsAccountExistsOnClientOfGroupGroupTransferToCenterShouldFailValidation() {
// setup
CenterBO center = new CenterBuilder().build();
GroupBO group = new GroupBuilder().withParentCustomer(center).build();
ClientBO client = new ClientBuilder().withParentCustomer(group).active().buildForUnitTests();
group.addChild(client);
SavingsBO savings = new SavingsAccountBuilder().active().withCustomer(group).build();
client.addAccount(savings);
// exercise test
try {
group.validateNoActiveAccountsExist();
fail("should fail validation");
} catch (CustomerException e) {
assertThat(e.getKey(), is(CustomerConstants.ERRORS_CHILDREN_HAS_ACTIVE_ACCOUNT));
}
}
use of org.mifos.customers.client.business.ClientBO in project head by mifos.
the class GroupValidationTest method givenAnActiveLoanAccountExistsOnClientOfGroupGroupTransferToCenterShouldFailValidation.
@Test
public void givenAnActiveLoanAccountExistsOnClientOfGroupGroupTransferToCenterShouldFailValidation() {
// setup
CenterBO center = new CenterBuilder().build();
GroupBO group = new GroupBuilder().withParentCustomer(center).build();
ClientBO client = new ClientBuilder().withParentCustomer(group).active().buildForUnitTests();
group.addChild(client);
LoanBO loan = new LoanAccountBuilder().activeInGoodStanding().build();
client.addAccount(loan);
// exercise test
try {
group.validateNoActiveAccountsExist();
fail("should fail validation");
} catch (CustomerException e) {
assertThat(e.getKey(), is(CustomerConstants.ERRORS_CHILDREN_HAS_ACTIVE_ACCOUNT));
}
}
use of org.mifos.customers.client.business.ClientBO in project head by mifos.
the class CustomerSearchIdGenerationTest method removeGroupMembershipTest.
@Test
public void removeGroupMembershipTest() throws Exception {
// setup
short localeId = 1;
CustomerStatusUpdate customerStatusUpdate = new CustomerStatusUpdateBuilder().with(CustomerStatus.GROUP_CANCELLED).build();
PersonnelBO loanOfficer = PersonnelBuilder.anyLoanOfficer();
CenterBO existingCenter = new CenterBuilder().withLoanOfficer(loanOfficer).active().withNumberOfExistingCustomersInOffice(1).build();
GroupBO existingGroup = new GroupBuilder().pendingApproval().withParentCustomer(existingCenter).withVersion(customerStatusUpdate.getVersionNum()).build();
ClientBO existingClient = new ClientBuilder().withParentCustomer(existingGroup).pendingApproval().buildForUnitTests();
existingGroup.addChild(existingClient);
UserContext userContext = TestUtils.makeUser();
existingGroup.setUserContext(userContext);
existingClient.setUserContext(userContext);
existingClient.setCustomerDao(customerDao);
// stubbing
when(configurationPersistence.isGlimEnabled()).thenReturn(false);
when(customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(anyShort())).thenReturn(3);
existingClient = spy(existingClient);
int customer_id = 22;
when(existingClient.getCustomerId()).thenReturn(customer_id);
// exercise test
assertThat(existingClient.getSearchId(), is("1.1.1.1"));
customerService.removeGroupMembership(existingClient, loanOfficer, accountNotesEntity, localeId);
// verification
assertThat(existingClient.getSearchId(), is("1." + customer_id));
}
use of org.mifos.customers.client.business.ClientBO in project head by mifos.
the class CustomerSearchIdGenerationTest method transferClientFromGroupToGroupTest.
@Test
public void transferClientFromGroupToGroupTest() throws Exception {
final short office1_id = 2;
final Integer group1_id = 33;
final Integer group2_id = 22;
final int group2_child_count = 8;
// setup
UserContext userContext = TestUtils.makeUser();
OfficeBO office1 = new OfficeBuilder().withName("office1").branchOffice().withOfficeId(office1_id).build();
PersonnelBO loanOfficer = PersonnelBuilder.anyLoanOfficer();
GroupBO existingGroup = new GroupBuilder().pendingApproval().withLoanOfficer(loanOfficer).with(userContext).buildAsTopOfHierarchy();
existingGroup = spy(existingGroup);
when(existingGroup.getCustomerId()).thenReturn(group1_id);
existingGroup.generateSearchId();
ClientBO existingClient = new ClientBuilder().pendingApproval().withParentCustomer(existingGroup).withVersion(1).buildForUnitTests();
existingGroup.addChild(existingClient);
existingGroup.setCustomerDao(customerDao);
GroupBO existingGroup2 = new GroupBuilder().pendingApproval().withLoanOfficer(loanOfficer).with(userContext).withSearchId(group2_child_count).withOffice(office1).buildAsTopOfHierarchy();
existingGroup2.setCustomerDao(customerDao);
existingGroup2 = spy(existingGroup2);
when(existingGroup2.getCustomerId()).thenReturn(group2_id);
existingGroup2.generateSearchId();
// stubbing
when(customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(office1_id)).thenReturn(3);
when(customerDao.findClientBySystemId("clientid")).thenReturn(existingClient);
when(customerDao.findCustomerById(group2_id)).thenReturn(existingGroup2);
when(holidayDao.findCalendarEventsForThisYearAndNext(anyShort())).thenReturn(calendarEvent);
when(configurationHelper.isLoanScheduleRepaymentIndependentOfCustomerMeetingEnabled()).thenReturn(true);
// exercise test
assertThat(existingGroup.getSearchId(), is("1." + group1_id));
assertThat(existingClient.getSearchId(), is("1." + group1_id + ".1"));
customerService.transferClientTo(userContext, group2_id, "clientid", 1);
// verification
assertThat(existingGroup2.getSearchId(), is("1." + group2_id));
assertThat(existingClient.getSearchId(), is("1." + group2_id + "." + (group2_child_count + 1)));
}
use of org.mifos.customers.client.business.ClientBO in project head by mifos.
the class GroupStatusChangeIntegrationTest method givenGroupIsPendingAndContainsClientsInPartialStateThenWhenTransitioningToCancelledStateAllClientsAreTransitionedToPartial.
@Test
public void givenGroupIsPendingAndContainsClientsInPartialStateThenWhenTransitioningToCancelledStateAllClientsAreTransitionedToPartial() throws Exception {
// setup
CenterBO existingCenter = new CenterBuilder().with(existingMeeting).withName("Center-IntegrationTest").with(existingOffice).withLoanOfficer(existingLoanOfficer).withUserContext().build();
IntegrationTestObjectMother.createCenter(existingCenter, existingMeeting);
GroupBO existingPendingGroup = new GroupBuilder().withName("newGroup").withStatus(CustomerStatus.GROUP_PENDING).withParentCustomer(existingCenter).formedBy(existingUser).build();
IntegrationTestObjectMother.createGroup(existingPendingGroup, existingMeeting);
ClientBO existingPartialClient = new ClientBuilder().withName("partialClient").withStatus(CustomerStatus.CLIENT_PARTIAL).withParentCustomer(existingPendingGroup).buildForIntegrationTests();
IntegrationTestObjectMother.createClient(existingPartialClient, existingMeeting);
ClientBO existingPendingClient = new ClientBuilder().withName("pendingClient").withStatus(CustomerStatus.CLIENT_PENDING).withParentCustomer(existingPendingGroup).buildForIntegrationTests();
IntegrationTestObjectMother.createClient(existingPendingClient, existingMeeting);
existingPendingGroup = this.customerDao.findGroupBySystemId(existingPendingGroup.getGlobalCustNum());
existingPendingGroup.setUserContext(TestUtils.makeUser());
StaticHibernateUtil.startTransaction();
existingPartialClient = this.customerDao.findClientBySystemId(existingPartialClient.getGlobalCustNum());
existingPendingClient = this.customerDao.findClientBySystemId(existingPendingClient.getGlobalCustNum());
CustomerStatusFlag customerStatusFlag = CustomerStatusFlag.GROUP_CANCEL_BLACKLISTED;
CustomerNoteEntity customerNote = new CustomerNoteEntity("Made Inactive", new java.util.Date(), existingPendingGroup.getPersonnel(), existingPendingGroup);
// exercise test
customerService.updateGroupStatus(existingPendingGroup, existingPendingGroup.getStatus(), CustomerStatus.GROUP_CANCELLED, customerStatusFlag, customerNote);
// verification
assertThat(existingPendingGroup.getStatus(), is(CustomerStatus.GROUP_CANCELLED));
assertThat(existingPendingClient.getStatus(), is(CustomerStatus.CLIENT_PENDING));
assertThat(existingPartialClient.getStatus(), is(CustomerStatus.CLIENT_PARTIAL));
}
Aggregations