use of org.mifos.dto.domain.CenterUpdate 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.dto.domain.CenterUpdate 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.dto.domain.CenterUpdate in project head by mifos.
the class CenterCustAction method update.
// NOTE - manage->preview->update
@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
CenterBO centerFromSession = (CenterBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
CenterCustActionForm actionForm = (CenterCustActionForm) form;
AddressDto dto = null;
if (actionForm.getAddress() != null) {
dto = Address.toDto(actionForm.getAddress());
}
CenterUpdate centerUpdate = new CenterUpdate(centerFromSession.getCustomerId(), actionForm.getDisplayName(), centerFromSession.getVersionNo(), actionForm.getLoanOfficerIdValue(), actionForm.getExternalId(), actionForm.getMfiJoiningDate(), dto, actionForm.getCustomFields(), actionForm.getCustomerPositions());
try {
this.centerServiceFacade.updateCenter(centerUpdate);
} catch (BusinessRuleException e) {
throw new ApplicationException(e.getMessageKey(), e);
}
return mapping.findForward(ActionForwards.update_success.toString());
}
use of org.mifos.dto.domain.CenterUpdate 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.dto.domain.CenterUpdate 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