Search in sources :

Example 6 with OfficeBuilder

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

the class IntegrationTestObjectMotherBuilderDsl method anExistingBranchOffice.

public static OfficeBO anExistingBranchOffice(OfficeBuilder aBranchOffice) {
    OfficeBO headOffice = new OfficeBuilder().withGlobalOfficeNum("xxxx-001").withName("builder-head-office").withShortName("hf1").withSearchId("1.1.").headOffice().build();
    IntegrationTestObjectMother.createOffice(headOffice);
    OfficeBO areaOffice = new OfficeBuilder().withParentOffice(headOffice).withGlobalOfficeNum("xxxx-002").withName("builder-area-office").withShortName("af1").withSearchId("1.1.1.").areaOffice().build();
    IntegrationTestObjectMother.createOffice(areaOffice);
    OfficeBO branchOffice = aBranchOffice.withParentOffice(areaOffice).branchOffice().build();
    IntegrationTestObjectMother.createOffice(branchOffice);
    return branchOffice;
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) OfficeBO(org.mifos.customers.office.business.OfficeBO)

Example 7 with OfficeBuilder

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

the class CustomerSearchIdGenerationTest method transferClientFromOfficeToOfficeTest.

@Test
public void transferClientFromOfficeToOfficeTest() throws Exception {
    final short office1_id = 2;
    // setup
    OfficeBO office1 = new OfficeBuilder().withName("office1").branchOffice().withOfficeId(office1_id).build();
    PersonnelBO loanOfficer = PersonnelBuilder.anyLoanOfficer();
    ClientBO existingClient = new ClientBuilder().pendingApproval().withNoParent().withLoanOfficer(loanOfficer).buildForUnitTests();
    existingClient.setCustomerDao(customerDao);
    existingClient = spy(existingClient);
    int customer_id = 22;
    when(existingClient.getCustomerId()).thenReturn(customer_id);
    existingClient.generateSearchId();
    UserContext userContext = TestUtils.makeUser();
    existingClient.setUserContext(userContext);
    // stubbing
    when(customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(office1_id)).thenReturn(3);
    // exercise test
    assertThat(existingClient.getSearchId(), is("1." + customer_id));
    customerService.transferClientTo(existingClient, office1);
    // verification
    assertThat(existingClient.getSearchId(), is("1." + customer_id));
}
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) ClientBO(org.mifos.customers.client.business.ClientBO) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 8 with OfficeBuilder

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

the class CustomerSearchIdGenerationTest method transferGroupFromOfficeToOfficeTest.

@Test
public void transferGroupFromOfficeToOfficeTest() throws Exception {
    final short office1_id = 2;
    // setup
    OfficeBO office1 = new OfficeBuilder().withName("office1").branchOffice().withOfficeId(office1_id).build();
    PersonnelBO loanOfficer = PersonnelBuilder.anyLoanOfficer();
    GroupBO existingGroup = new GroupBuilder().pendingApproval().withLoanOfficer(loanOfficer).buildAsTopOfHierarchy();
    existingGroup = spy(existingGroup);
    int customer_id = 22;
    when(existingGroup.getCustomerId()).thenReturn(customer_id);
    existingGroup.generateSearchId();
    ClientBO existingClient = new ClientBuilder().pendingApproval().withParentCustomer(existingGroup).buildForUnitTests();
    existingGroup.addChild(existingClient);
    existingGroup.setCustomerDao(customerDao);
    UserContext userContext = TestUtils.makeUser();
    existingGroup.setUserContext(userContext);
    // stubbing
    when(customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(office1_id)).thenReturn(3);
    // exercise test
    assertThat(existingGroup.getSearchId(), is("1." + customer_id));
    assertThat(existingClient.getSearchId(), is("1." + customer_id + ".1"));
    customerService.transferGroupTo(existingGroup, office1);
    // verification
    assertThat(existingGroup.getSearchId(), is("1." + customer_id));
    assertThat(existingClient.getSearchId(), is("1." + customer_id + ".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 9 with OfficeBuilder

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

the class CenterUpdateTest method rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs.

@Test(expected = MifosRuntimeException.class)
public void rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs() throws Exception {
    // setup
    PersonnelBO existingLoanOfficer = PersonnelBuilder.anyLoanOfficer();
    UserContext userContext = TestUtils.makeUser();
    CenterUpdate centerUpdate = new CenterUpdateBuilder().build();
    // stubbing
    when(customerDao.findCustomerById(centerUpdate.getCustomerId())).thenReturn(mockedCenter);
    when(personnelDao.findPersonnelById(centerUpdate.getLoanOfficerId())).thenReturn(existingLoanOfficer);
    when(mockedCenter.isLoanOfficerChanged(existingLoanOfficer)).thenReturn(false);
    when(mockedCenter.getOffice()).thenReturn(new OfficeBuilder().build());
    // stub
    doThrow(new RuntimeException()).when(customerDao).save(mockedCenter);
    // exercise test
    customerService.updateCenter(userContext, centerUpdate);
    // verification
    verify(hibernateTransaction).rollbackTransaction();
    verify(hibernateTransaction).closeSession();
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) MifosRuntimeException(org.mifos.core.MifosRuntimeException) CenterUpdateBuilder(org.mifos.domain.builders.CenterUpdateBuilder) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CenterUpdate(org.mifos.dto.domain.CenterUpdate) UserContext(org.mifos.security.util.UserContext) Test(org.junit.Test)

Example 10 with OfficeBuilder

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

the class CenterUpdateTest method rollsbackTransactionClosesSessionAndReThrowsApplicationException.

@Test(expected = CustomerException.class)
public void rollsbackTransactionClosesSessionAndReThrowsApplicationException() throws Exception {
    // setup
    PersonnelBO existingLoanOfficer = PersonnelBuilder.anyLoanOfficer();
    UserContext userContext = TestUtils.makeUser();
    CenterUpdate centerUpdate = new CenterUpdateBuilder().build();
    // stubbing
    when(customerDao.findCustomerById(centerUpdate.getCustomerId())).thenReturn(mockedCenter);
    when(personnelDao.findPersonnelById(centerUpdate.getLoanOfficerId())).thenReturn(existingLoanOfficer);
    when(mockedCenter.isLoanOfficerChanged(existingLoanOfficer)).thenReturn(false);
    when(mockedCenter.getOffice()).thenReturn(new OfficeBuilder().build());
    // stub
    doThrow(new CustomerException(CustomerConstants.ERRORS_DUPLICATE_CUSTOMER)).when(mockedCenter).validate();
    // exercise test
    customerService.updateCenter(userContext, centerUpdate);
    // verification
    verify(hibernateTransaction).rollbackTransaction();
    verify(hibernateTransaction).closeSession();
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) CustomerException(org.mifos.customers.exceptions.CustomerException) CenterUpdateBuilder(org.mifos.domain.builders.CenterUpdateBuilder) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CenterUpdate(org.mifos.dto.domain.CenterUpdate) UserContext(org.mifos.security.util.UserContext) Test(org.junit.Test)

Aggregations

OfficeBuilder (org.mifos.domain.builders.OfficeBuilder)33 OfficeBO (org.mifos.customers.office.business.OfficeBO)23 Test (org.junit.Test)22 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)12 UserContext (org.mifos.security.util.UserContext)11 GroupBO (org.mifos.customers.group.business.GroupBO)9 GroupBuilder (org.mifos.domain.builders.GroupBuilder)9 CustomerException (org.mifos.customers.exceptions.CustomerException)7 PersonnelBuilder (org.mifos.domain.builders.PersonnelBuilder)7 CenterBuilder (org.mifos.domain.builders.CenterBuilder)6 MeetingBO (org.mifos.application.meeting.business.MeetingBO)5 CenterBO (org.mifos.customers.center.business.CenterBO)5 ClientBO (org.mifos.customers.client.business.ClientBO)4 ClientBuilder (org.mifos.domain.builders.ClientBuilder)4 GroupUpdateBuilder (org.mifos.domain.builders.GroupUpdateBuilder)4 GroupUpdate (org.mifos.dto.domain.GroupUpdate)4 DateTime (org.joda.time.DateTime)3 MeetingBuilder (org.mifos.domain.builders.MeetingBuilder)3 DateMidnight (org.joda.time.DateMidnight)2 Before (org.junit.Before)2