Search in sources :

Example 51 with GroupBuilder

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

the class GroupValidationTest method givenCenterIsSameAsGroupsParentGroupTransferToCenterShouldFailValidation.

@Test
public void givenCenterIsSameAsGroupsParentGroupTransferToCenterShouldFailValidation() {
    // setup
    CenterBO center = new CenterBuilder().build();
    GroupBO group = new GroupBuilder().withParentCustomer(center).build();
    // exercise test
    try {
        group.validateReceivingCenter(center);
        fail("should fail validation");
    } catch (CustomerException e) {
        assertThat(e.getKey(), is(CustomerConstants.ERRORS_SAME_CENTER_TRANSFER));
    }
}
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) Test(org.junit.Test)

Example 52 with GroupBuilder

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

the class GroupValidationTest method givenGroupIsTrainedButTrainedDateIsNotSetThenShouldThrowCustomerException.

@Test
public void givenGroupIsTrainedButTrainedDateIsNotSetThenShouldThrowCustomerException() {
    PersonnelBO formedBy = new PersonnelBuilder().build();
    group = new GroupBuilder().withName("group-On-center").withParentCustomer(center).formedBy(formedBy).isTrained().trainedOn(null).build();
    try {
        group.validate();
        fail("should throw customer exception as trained date must be provided if in trained state when creating group.");
    } catch (CustomerException e) {
        assertThat(e.getKey(), is(CustomerConstants.INVALID_TRAINED_OR_TRAINEDDATE));
    }
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) CustomerException(org.mifos.customers.exceptions.CustomerException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) GroupBuilder(org.mifos.domain.builders.GroupBuilder) Test(org.junit.Test)

Example 53 with GroupBuilder

use of org.mifos.domain.builders.GroupBuilder 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 54 with GroupBuilder

use of org.mifos.domain.builders.GroupBuilder 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 55 with GroupBuilder

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

the class GroupCreationTest method throwsCheckedExceptionWhenGroupNameIsTakenForOfficeAlready.

@Test(expected = CustomerException.class)
public void throwsCheckedExceptionWhenGroupNameIsTakenForOfficeAlready() throws Exception {
    // setup
    CenterBO parent = new CenterBuilder().withLoanOfficer(anyLoanOfficer()).build();
    GroupBO stubbedGroup = new GroupBuilder().withName("already-exists-group").withParentCustomer(parent).formedBy(anyLoanOfficer()).build();
    List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>();
    // stubbing
    doThrow(new CustomerException(CustomerConstants.ERRORS_DUPLICATE_CUSTOMER)).when(customerDao).validateGroupNameIsNotTakenForOffice(anyString(), anyShort());
    // exercise test
    customerService.createGroup(stubbedGroup, meeting, accountFees);
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) GroupBuilder(org.mifos.domain.builders.GroupBuilder) ArrayList(java.util.ArrayList) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) GroupBO(org.mifos.customers.group.business.GroupBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) 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