use of org.mifos.domain.builders.CenterUpdateBuilder 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.CenterUpdateBuilder 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();
}
use of org.mifos.domain.builders.CenterUpdateBuilder in project head by mifos.
the class CenterUpdateTest method cannotUpdateCenterWithDifferentVersion.
@Test
public void cannotUpdateCenterWithDifferentVersion() {
// setup
int differentVersionNum = -1;
CenterBO existingCenter = new CenterBuilder().withLoanOfficer(PersonnelBuilder.anyLoanOfficer()).withVersion(differentVersionNum).build();
UserContext userContext = TestUtils.makeUser();
CenterUpdate centerUpdate = new CenterUpdateBuilder().build();
// stub
when(customerDao.findCustomerById(centerUpdate.getCustomerId())).thenReturn(existingCenter);
// exercise test
try {
customerService.updateCenter(userContext, centerUpdate);
fail("cannotUpdateCenterWithDifferentVersion");
} catch (ApplicationException e) {
assertThat(e.getKey(), is(Constants.ERROR_VERSION_MISMATCH));
}
}
use of org.mifos.domain.builders.CenterUpdateBuilder in project head by mifos.
the class CenterUpdateTest method userContextIsSetBeforeBeginningAuditLogging.
@Test
public void userContextIsSetBeforeBeginningAuditLogging() throws Exception {
// setup
UserContext userContext = TestUtils.makeUser();
CenterUpdate centerUpdate = new CenterUpdateBuilder().build();
// stub
when(customerDao.findCustomerById(centerUpdate.getCustomerId())).thenReturn(mockedCenter);
// exercise test
customerService.updateCenter(userContext, centerUpdate);
// verification
InOrder inOrder = inOrder(hibernateTransaction, mockedCenter);
inOrder.verify(mockedCenter).setUserContext(userContext);
inOrder.verify(hibernateTransaction).beginAuditLoggingFor(mockedCenter);
}
use of org.mifos.domain.builders.CenterUpdateBuilder in project head by mifos.
the class CenterUpdateTest method throwsCheckedExceptionWhenVersionOfCenterForUpdateIsDifferentToPersistedCenterVersion.
@Test(expected = CustomerException.class)
public void throwsCheckedExceptionWhenVersionOfCenterForUpdateIsDifferentToPersistedCenterVersion() throws Exception {
// setup
UserContext userContext = TestUtils.makeUser();
CenterUpdate centerUpdate = new CenterUpdateBuilder().build();
// stubbing
when(customerDao.findCustomerById(centerUpdate.getCustomerId())).thenReturn(mockedCenter);
doThrow(new CustomerException(Constants.ERROR_VERSION_MISMATCH)).when(mockedCenter).validateVersion(centerUpdate.getVersionNum());
// exercise test
customerService.updateCenter(userContext, centerUpdate);
}
Aggregations