use of org.mifos.dto.domain.ClientMfiInfoUpdate in project head by mifos.
the class ClientUpdateTest method userContextAndUpdateDetailsAreSetBeforeBeginningAuditLogging.
@Test
public void userContextAndUpdateDetailsAreSetBeforeBeginningAuditLogging() throws Exception {
// setup
UserContext userContext = TestUtils.makeUser();
ClientMfiInfoUpdate clientMfiInfoUpdate = new ClientMfiInfoUpdateBuilder().build();
// stubbing
when(customerDao.findCustomerById(clientMfiInfoUpdate.getClientId())).thenReturn(mockedClient);
// exercise test
customerService.updateClientMfiInfo(userContext, clientMfiInfoUpdate);
// verification
InOrder inOrder = inOrder(hibernateTransactionHelper, mockedClient);
inOrder.verify(mockedClient).updateDetails(userContext);
inOrder.verify(hibernateTransactionHelper).beginAuditLoggingFor(mockedClient);
}
use of org.mifos.dto.domain.ClientMfiInfoUpdate in project head by mifos.
the class ClientUpdateTest method rollsbackTransactionClosesSessionAndReThrowsApplicationException.
@Test(expected = CustomerException.class)
public void rollsbackTransactionClosesSessionAndReThrowsApplicationException() throws Exception {
// setup
UserContext userContext = TestUtils.makeUser();
ClientMfiInfoUpdate clientMfiInfoUpdate = new ClientMfiInfoUpdateBuilder().build();
// stubbing
when(customerDao.findCustomerById(clientMfiInfoUpdate.getClientId())).thenReturn(mockedClient);
when(personnelDao.findPersonnelById(clientMfiInfoUpdate.getPersonnelId())).thenReturn(personnel);
doThrow(new CustomerException(CustomerConstants.ERRORS_DUPLICATE_CUSTOMER)).when(mockedClient).updateMfiInfo(personnel, clientMfiInfoUpdate);
// exercise test
customerService.updateClientMfiInfo(userContext, clientMfiInfoUpdate);
// verification
verify(hibernateTransactionHelper).rollbackTransaction();
verify(hibernateTransactionHelper).closeSession();
}
use of org.mifos.dto.domain.ClientMfiInfoUpdate in project head by mifos.
the class ClientUpdateTest method rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs.
@Test(expected = MifosRuntimeException.class)
public void rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs() throws Exception {
// setup
UserContext userContext = TestUtils.makeUser();
ClientMfiInfoUpdate clientMfiInfoUpdate = new ClientMfiInfoUpdateBuilder().build();
// stubbing
when(customerDao.findCustomerById(clientMfiInfoUpdate.getClientId())).thenReturn(mockedClient);
when(personnelDao.findPersonnelById(clientMfiInfoUpdate.getPersonnelId())).thenReturn(personnel);
doThrow(new RuntimeException()).when(customerDao).save(mockedClient);
// exercise test
customerService.updateClientMfiInfo(userContext, clientMfiInfoUpdate);
// verification
verify(hibernateTransactionHelper).rollbackTransaction();
verify(hibernateTransactionHelper).closeSession();
}
use of org.mifos.dto.domain.ClientMfiInfoUpdate in project head by mifos.
the class ClientUpdateTest method throwsCheckedExceptionWhenVersionOfClientForUpdateIsDifferentToPersistedClientVersion.
@Test(expected = CustomerException.class)
public void throwsCheckedExceptionWhenVersionOfClientForUpdateIsDifferentToPersistedClientVersion() throws Exception {
// setup
UserContext userContext = TestUtils.makeUser();
ClientMfiInfoUpdate clientMfiInfoUpdate = new ClientMfiInfoUpdateBuilder().build();
// stubbing
when(customerDao.findCustomerById(clientMfiInfoUpdate.getClientId())).thenReturn(mockedClient);
doThrow(new CustomerException(Constants.ERROR_VERSION_MISMATCH)).when(mockedClient).validateVersion(clientMfiInfoUpdate.getOrginalClientVersionNumber());
// exercise test
customerService.updateClientMfiInfo(userContext, clientMfiInfoUpdate);
// verify
verify(mockedClient).validateVersion(clientMfiInfoUpdate.getOrginalClientVersionNumber());
}
use of org.mifos.dto.domain.ClientMfiInfoUpdate in project head by mifos.
the class PictureFormFile method updateMfiInfo.
@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward updateMfiInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
ClientCustActionForm actionForm = (ClientCustActionForm) form;
ClientBO clientInSession = getClientFromSession(request);
Integer clientId = clientInSession.getCustomerId();
Integer oldVersionNumber = clientInSession.getVersionNo();
boolean trained = false;
if (trainedValue(actionForm) != null && trainedValue(actionForm).equals(YesNoFlag.YES.getValue())) {
trained = true;
}
DateTime trainedDate = null;
try {
java.sql.Date inputDate = trainedDate(actionForm);
if (inputDate != null) {
trainedDate = new DateTime(trainedDate(actionForm));
}
} catch (InvalidDateException e) {
throw new CustomerException(ClientConstants.TRAINED_DATE_MANDATORY);
}
Short personnelId = Short.valueOf("-1");
if (groupFlagValue(actionForm).equals(YesNoFlag.NO.getValue())) {
if (actionForm.getLoanOfficerIdValue() != null) {
personnelId = actionForm.getLoanOfficerIdValue();
}
} else if (groupFlagValue(actionForm).equals(YesNoFlag.YES.getValue())) {
// TODO for an urgent fix this reads client to get personnelId.
// Client is read again in updateClientMfiInfo. Refactor to only read in
// updateClientMfiInfo.
ClientBO client = (ClientBO) this.customerDao.findCustomerById(clientId);
personnelId = client.getPersonnel().getPersonnelId();
}
ClientMfiInfoUpdate clientMfiInfoUpdate = new ClientMfiInfoUpdate(clientId, oldVersionNumber, personnelId, externalId(actionForm), trained, trainedDate);
this.clientServiceFacade.updateClientMfiInfo(clientMfiInfoUpdate);
return mapping.findForward(ActionForwards.updateMfiInfo_success.toString());
}
Aggregations