use of org.mifos.domain.builders.OfficeBuilder in project head by mifos.
the class GroupTransferToOfficeServiceTest method givenOfficeIsInactiveGroupTransferToBranchShouldFailValidation.
@Test
public void givenOfficeIsInactiveGroupTransferToBranchShouldFailValidation() {
// setup
GroupBO group = new GroupBuilder().build();
OfficeBO office = new OfficeBuilder().inActive().build();
// exercise test
try {
customerService.transferGroupTo(group, office);
fail("should fail validation");
} catch (CustomerException e) {
assertThat(e.getKey(), is(CustomerConstants.ERRORS_TRANSFER_IN_INACTIVE_OFFICE));
}
}
use of org.mifos.domain.builders.OfficeBuilder in project head by mifos.
the class GroupTransferToOfficeServiceTest method givenOfficeAlreadyHasGroupWithSameNameThenGroupTransferToBranchShouldFailValidation.
@Test
public void givenOfficeAlreadyHasGroupWithSameNameThenGroupTransferToBranchShouldFailValidation() throws Exception {
// setup
GroupBO group = new GroupBuilder().withName("already-exists-group").build();
OfficeBO office = new OfficeBuilder().inActive().build();
// stubbing
doThrow(new CustomerException(CustomerConstants.ERRORS_DUPLICATE_CUSTOMER)).when(customerDao).validateGroupNameIsNotTakenForOffice(anyString(), anyShort());
// exercise test
try {
customerService.transferGroupTo(group, office);
fail("should fail validation");
} catch (CustomerException e) {
assertThat(e.getKey(), is(CustomerConstants.ERRORS_TRANSFER_IN_INACTIVE_OFFICE));
}
}
use of org.mifos.domain.builders.OfficeBuilder in project head by mifos.
the class GroupUpdateTest method updatesLoanOfficerForAllChildrenAndThierAccountsWhenLoanOfficerIsUpdated.
@Test
public void updatesLoanOfficerForAllChildrenAndThierAccountsWhenLoanOfficerIsUpdated() throws Exception {
// setup
UserContext userContext = TestUtils.makeUser();
GroupUpdate groupUpdate = new GroupUpdateBuilder().build();
PersonnelBO newLoanOfficer = new PersonnelBuilder().anyLoanOfficer();
// stubbing
when(customerDao.findGroupBySystemId(groupUpdate.getGlobalCustNum())).thenReturn(mockedGroup);
when(mockedGroup.isNameDifferent(groupUpdate.getDisplayName())).thenReturn(false);
when(personnelDao.findPersonnelById(groupUpdate.getLoanOfficerId())).thenReturn(newLoanOfficer);
when(mockedGroup.isLoanOfficerChanged(newLoanOfficer)).thenReturn(true);
when(mockedGroup.getOffice()).thenReturn(new OfficeBuilder().build());
// exercise test
customerService.updateGroup(userContext, groupUpdate);
// verification
verify(mockedGroup).setLoanOfficer(newLoanOfficer);
verify(mockedGroup).validate();
verify(customerDao).updateLoanOfficersForAllChildrenAndAccounts(anyShort(), anyString(), anyShort());
}
use of org.mifos.domain.builders.OfficeBuilder in project head by mifos.
the class GroupUpdateTest method rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs.
@Test(expected = MifosRuntimeException.class)
public void rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs() throws Exception {
// setup
UserContext userContext = TestUtils.makeUser();
GroupUpdate groupUpdate = new GroupUpdateBuilder().build();
PersonnelBO newLoanOfficer = new PersonnelBuilder().anyLoanOfficer();
// stubbing
when(customerDao.findGroupBySystemId(groupUpdate.getGlobalCustNum())).thenReturn(mockedGroup);
when(mockedGroup.isNameDifferent(groupUpdate.getDisplayName())).thenReturn(false);
when(personnelDao.findPersonnelById(groupUpdate.getLoanOfficerId())).thenReturn(newLoanOfficer);
when(mockedGroup.isLoanOfficerChanged(newLoanOfficer)).thenReturn(false);
when(mockedGroup.getOffice()).thenReturn(new OfficeBuilder().build());
// stub
doThrow(new RuntimeException()).when(customerDao).save(mockedGroup);
// exercise test
customerService.updateGroup(userContext, groupUpdate);
// verification
verify(hibernateTransactionHelper).rollbackTransaction();
verify(hibernateTransactionHelper).closeSession();
}
use of org.mifos.domain.builders.OfficeBuilder in project head by mifos.
the class GroupUpdateTest method rollsbackTransactionClosesSessionAndReThrowsApplicationException.
@Test(expected = CustomerException.class)
public void rollsbackTransactionClosesSessionAndReThrowsApplicationException() throws Exception {
// setup
UserContext userContext = TestUtils.makeUser();
GroupUpdate groupUpdate = new GroupUpdateBuilder().build();
PersonnelBO newLoanOfficer = new PersonnelBuilder().anyLoanOfficer();
// stubbing
when(customerDao.findGroupBySystemId(groupUpdate.getGlobalCustNum())).thenReturn(mockedGroup);
when(mockedGroup.isNameDifferent(groupUpdate.getDisplayName())).thenReturn(false);
when(personnelDao.findPersonnelById(groupUpdate.getLoanOfficerId())).thenReturn(newLoanOfficer);
when(mockedGroup.isLoanOfficerChanged(newLoanOfficer)).thenReturn(false);
when(mockedGroup.getOffice()).thenReturn(new OfficeBuilder().build());
// stub
doThrow(new CustomerException(CustomerConstants.ERRORS_DUPLICATE_CUSTOMER)).when(mockedGroup).validate();
// exercise test
customerService.updateGroup(userContext, groupUpdate);
// verification
verify(hibernateTransactionHelper).rollbackTransaction();
verify(hibernateTransactionHelper).closeSession();
}
Aggregations