Search in sources :

Example 31 with GroupBuilder

use of org.mifos.domain.builders.GroupBuilder in project head by mifos.

the class GroupValidationTest method givenAnActiveSavingsAccountExistsGroupTransferToCenterShouldFailValidation.

@Test
public void givenAnActiveSavingsAccountExistsGroupTransferToCenterShouldFailValidation() {
    // setup
    CenterBO center = new CenterBuilder().build();
    GroupBO group = new GroupBuilder().withParentCustomer(center).build();
    SavingsBO savings = new SavingsAccountBuilder().active().withCustomer(group).build();
    group.addAccount(savings);
    // exercise test
    try {
        group.validateNoActiveAccountsExist();
        fail("should fail validation");
    } catch (CustomerException e) {
        assertThat(e.getKey(), is(CustomerConstants.ERRORS_HAS_ACTIVE_ACCOUNT));
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) GroupBuilder(org.mifos.domain.builders.GroupBuilder) 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) Test(org.junit.Test)

Example 32 with GroupBuilder

use of org.mifos.domain.builders.GroupBuilder in project head by mifos.

the class GroupValidationTest method formedByPersonnelMustBeAssigned.

@Test
public void formedByPersonnelMustBeAssigned() {
    group = new GroupBuilder().withName("group-On-center").withParentCustomer(center).formedBy(null).build();
    try {
        group.validate();
        fail("should throw customer exception as personnel that fomed group must exist when creating group.");
    } catch (CustomerException e) {
        assertThat(e.getKey(), is(CustomerConstants.INVALID_FORMED_BY));
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) GroupBuilder(org.mifos.domain.builders.GroupBuilder) Test(org.junit.Test)

Example 33 with GroupBuilder

use of org.mifos.domain.builders.GroupBuilder in project head by mifos.

the class CustomerStatusUpdateTest method setsActivationDateAndUpdatesCustomerHierarchyWhenTransitioningToActiveForFirstTime.

@Test
public void setsActivationDateAndUpdatesCustomerHierarchyWhenTransitioningToActiveForFirstTime() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    CustomerStatusUpdate customerStatusUpdate = new CustomerStatusUpdateBuilder().with(CustomerStatus.GROUP_ACTIVE).build();
    PersonnelBO loanOfficer = PersonnelBuilder.anyLoanOfficer();
    CenterBO existingCenter = new CenterBuilder().withLoanOfficer(loanOfficer).active().build();
    GroupBO existingGroup = new GroupBuilder().pendingApproval().withParentCustomer(existingCenter).withVersion(customerStatusUpdate.getVersionNum()).build();
    // stubbing
    when(customerDao.findCustomerById(customerStatusUpdate.getCustomerId())).thenReturn(existingGroup);
    // exercise test
    customerService.updateCustomerStatus(userContext, customerStatusUpdate);
    // verification
    assertThat(new LocalDate(existingGroup.getCustomerActivationDate()), is(new LocalDate()));
    assertThat((CenterBO) existingGroup.getActiveCustomerHierarchy().getParentCustomer(), is(existingCenter));
    assertThat((GroupBO) existingGroup.getActiveCustomerHierarchy().getCustomer(), is(existingGroup));
}
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) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) GroupBO(org.mifos.customers.group.business.GroupBO) LocalDate(org.joda.time.LocalDate) CustomerStatusUpdateBuilder(org.mifos.domain.builders.CustomerStatusUpdateBuilder) Test(org.junit.Test)

Example 34 with GroupBuilder

use of org.mifos.domain.builders.GroupBuilder in project head by mifos.

the class CustomerStatusUpdateTest method throwsCheckedExceptionWhenValidationFailsForTransitioningToActive.

@Test(expected = CustomerException.class)
public void throwsCheckedExceptionWhenValidationFailsForTransitioningToActive() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    CustomerStatusUpdate customerStatusUpdate = new CustomerStatusUpdateBuilder().with(CustomerStatus.GROUP_ACTIVE).build();
    CenterBO existingCenter = new CenterBuilder().build();
    GroupBO existingGroup = new GroupBuilder().active().withParentCustomer(existingCenter).withVersion(customerStatusUpdate.getVersionNum()).build();
    existingGroup.setLoanOfficer(null);
    // stubbing
    when(customerDao.findCustomerById(customerStatusUpdate.getCustomerId())).thenReturn(existingGroup);
    // exercise test
    customerService.updateCustomerStatus(userContext, customerStatusUpdate);
}
Also used : CustomerStatusUpdate(org.mifos.application.servicefacade.CustomerStatusUpdate) UserContext(org.mifos.security.util.UserContext) GroupBuilder(org.mifos.domain.builders.GroupBuilder) 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) Test(org.junit.Test)

Example 35 with GroupBuilder

use of org.mifos.domain.builders.GroupBuilder in project head by mifos.

the class CustomerStatusUpdateTest method updatesPendingChildrenToPartialWhenTransitioningGroupFromPendingToCancelled.

@Test
public void updatesPendingChildrenToPartialWhenTransitioningGroupFromPendingToCancelled() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    CustomerStatusUpdate customerStatusUpdate = new CustomerStatusUpdateBuilder().with(CustomerStatus.GROUP_CANCELLED).build();
    PersonnelBO loanOfficer = PersonnelBuilder.anyLoanOfficer();
    CenterBO existingCenter = new CenterBuilder().withLoanOfficer(loanOfficer).active().build();
    GroupBO existingGroup = new GroupBuilder().pendingApproval().withParentCustomer(existingCenter).withVersion(customerStatusUpdate.getVersionNum()).build();
    ClientBO existingClient = new ClientBuilder().withParentCustomer(existingGroup).pendingApproval().buildForUnitTests();
    existingGroup.addChild(existingClient);
    // stubbing
    when(customerDao.findCustomerById(customerStatusUpdate.getCustomerId())).thenReturn(existingGroup);
    // exercise test
    customerService.updateCustomerStatus(userContext, customerStatusUpdate);
    // verification
    assertThat(existingGroup.getStatus(), is(CustomerStatus.GROUP_CANCELLED));
    assertThat(existingClient.getUserContext(), is(userContext));
    assertThat(existingClient.getStatus(), is(CustomerStatus.CLIENT_PARTIAL));
}
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)

Aggregations

GroupBuilder (org.mifos.domain.builders.GroupBuilder)67 CenterBuilder (org.mifos.domain.builders.CenterBuilder)53 Test (org.junit.Test)49 GroupBO (org.mifos.customers.group.business.GroupBO)42 CenterBO (org.mifos.customers.center.business.CenterBO)35 ClientBuilder (org.mifos.domain.builders.ClientBuilder)31 MeetingBuilder (org.mifos.domain.builders.MeetingBuilder)24 CustomerException (org.mifos.customers.exceptions.CustomerException)21 MeetingBO (org.mifos.application.meeting.business.MeetingBO)16 ClientBO (org.mifos.customers.client.business.ClientBO)14 OfficeBO (org.mifos.customers.office.business.OfficeBO)14 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)13 ArrayList (java.util.ArrayList)12 LocalDate (org.joda.time.LocalDate)11 DateTime (org.joda.time.DateTime)10 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)10 OfficeBuilder (org.mifos.domain.builders.OfficeBuilder)9 Before (org.junit.Before)8 CustomerNoteEntity (org.mifos.customers.business.CustomerNoteEntity)8 CustomerStatusFlag (org.mifos.customers.util.helpers.CustomerStatusFlag)8