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;
}
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));
}
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"));
}
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();
}
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();
}
Aggregations