Search in sources :

Example 81 with ClientBO

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));
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) GroupBuilder(org.mifos.domain.builders.GroupBuilder) ClientBO(org.mifos.customers.client.business.ClientBO) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) GroupBO(org.mifos.customers.group.business.GroupBO) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 82 with ClientBO

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));
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) LoanAccountBuilder(org.mifos.domain.builders.LoanAccountBuilder) GroupBuilder(org.mifos.domain.builders.GroupBuilder) ClientBO(org.mifos.customers.client.business.ClientBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) GroupBO(org.mifos.customers.group.business.GroupBO) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 83 with ClientBO

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));
}
Also used : CustomerStatusUpdate(org.mifos.application.servicefacade.CustomerStatusUpdate) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) GroupBuilder(org.mifos.domain.builders.GroupBuilder) ClientBO(org.mifos.customers.client.business.ClientBO) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) GroupBO(org.mifos.customers.group.business.GroupBO) CustomerStatusUpdateBuilder(org.mifos.domain.builders.CustomerStatusUpdateBuilder) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 84 with ClientBO

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)));
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) GroupBuilder(org.mifos.domain.builders.GroupBuilder) ClientBO(org.mifos.customers.client.business.ClientBO) GroupBO(org.mifos.customers.group.business.GroupBO) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 85 with ClientBO

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));
}
Also used : CustomerNoteEntity(org.mifos.customers.business.CustomerNoteEntity) CustomerStatusFlag(org.mifos.customers.util.helpers.CustomerStatusFlag) GroupBuilder(org.mifos.domain.builders.GroupBuilder) ClientBO(org.mifos.customers.client.business.ClientBO) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) GroupBO(org.mifos.customers.group.business.GroupBO) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Aggregations

ClientBO (org.mifos.customers.client.business.ClientBO)93 ArrayList (java.util.ArrayList)27 Test (org.junit.Test)27 CustomerException (org.mifos.customers.exceptions.CustomerException)25 CustomerBO (org.mifos.customers.business.CustomerBO)23 GroupBO (org.mifos.customers.group.business.GroupBO)22 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)22 UserContext (org.mifos.security.util.UserContext)21 MifosRuntimeException (org.mifos.core.MifosRuntimeException)19 CenterBO (org.mifos.customers.center.business.CenterBO)19 BusinessRuleException (org.mifos.service.BusinessRuleException)17 ClientBuilder (org.mifos.domain.builders.ClientBuilder)16 PersistenceException (org.mifos.framework.exceptions.PersistenceException)16 OfficeBO (org.mifos.customers.office.business.OfficeBO)14 GroupBuilder (org.mifos.domain.builders.GroupBuilder)14 ClientNameDetailDto (org.mifos.dto.screen.ClientNameDetailDto)14 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)14 Date (java.util.Date)13 DateTime (org.joda.time.DateTime)13 AccountException (org.mifos.accounts.exceptions.AccountException)13