Search in sources :

Example 1 with ClientMfiInfoUpdate

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);
}
Also used : ClientMfiInfoUpdateBuilder(org.mifos.domain.builders.ClientMfiInfoUpdateBuilder) InOrder(org.mockito.InOrder) UserContext(org.mifos.security.util.UserContext) ClientMfiInfoUpdate(org.mifos.dto.domain.ClientMfiInfoUpdate) Test(org.junit.Test)

Example 2 with ClientMfiInfoUpdate

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();
}
Also used : ClientMfiInfoUpdateBuilder(org.mifos.domain.builders.ClientMfiInfoUpdateBuilder) CustomerException(org.mifos.customers.exceptions.CustomerException) UserContext(org.mifos.security.util.UserContext) ClientMfiInfoUpdate(org.mifos.dto.domain.ClientMfiInfoUpdate) Test(org.junit.Test)

Example 3 with ClientMfiInfoUpdate

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();
}
Also used : ClientMfiInfoUpdateBuilder(org.mifos.domain.builders.ClientMfiInfoUpdateBuilder) MifosRuntimeException(org.mifos.core.MifosRuntimeException) UserContext(org.mifos.security.util.UserContext) ClientMfiInfoUpdate(org.mifos.dto.domain.ClientMfiInfoUpdate) Test(org.junit.Test)

Example 4 with ClientMfiInfoUpdate

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());
}
Also used : ClientMfiInfoUpdateBuilder(org.mifos.domain.builders.ClientMfiInfoUpdateBuilder) CustomerException(org.mifos.customers.exceptions.CustomerException) UserContext(org.mifos.security.util.UserContext) ClientMfiInfoUpdate(org.mifos.dto.domain.ClientMfiInfoUpdate) Test(org.junit.Test)

Example 5 with ClientMfiInfoUpdate

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());
}
Also used : ClientCustActionForm(org.mifos.customers.client.struts.actionforms.ClientCustActionForm) CustomerException(org.mifos.customers.exceptions.CustomerException) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ClientMfiInfoUpdate(org.mifos.dto.domain.ClientMfiInfoUpdate) ClientBO(org.mifos.customers.client.business.ClientBO) DateTime(org.joda.time.DateTime) Date(java.sql.Date) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

ClientMfiInfoUpdate (org.mifos.dto.domain.ClientMfiInfoUpdate)6 Test (org.junit.Test)5 ClientMfiInfoUpdateBuilder (org.mifos.domain.builders.ClientMfiInfoUpdateBuilder)5 UserContext (org.mifos.security.util.UserContext)5 CustomerException (org.mifos.customers.exceptions.CustomerException)3 Date (java.sql.Date)1 DateTime (org.joda.time.DateTime)1 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 ClientBO (org.mifos.customers.client.business.ClientBO)1 ClientCustActionForm (org.mifos.customers.client.struts.actionforms.ClientCustActionForm)1 CloseSession (org.mifos.framework.util.helpers.CloseSession)1 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)1 InOrder (org.mockito.InOrder)1