Search in sources :

Example 6 with CenterUpdate

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();
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) CustomerException(org.mifos.customers.exceptions.CustomerException) CenterUpdateBuilder(org.mifos.domain.builders.CenterUpdateBuilder) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CenterUpdate(org.mifos.dto.domain.CenterUpdate) UserContext(org.mifos.security.util.UserContext) Test(org.junit.Test)

Example 7 with CenterUpdate

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));
    }
}
Also used : ApplicationException(org.mifos.framework.exceptions.ApplicationException) CenterUpdateBuilder(org.mifos.domain.builders.CenterUpdateBuilder) CenterUpdate(org.mifos.dto.domain.CenterUpdate) UserContext(org.mifos.security.util.UserContext) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) Test(org.junit.Test)

Example 8 with CenterUpdate

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());
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) CenterCustActionForm(org.mifos.customers.center.struts.actionforms.CenterCustActionForm) CenterUpdate(org.mifos.dto.domain.CenterUpdate) CenterBO(org.mifos.customers.center.business.CenterBO) AddressDto(org.mifos.dto.domain.AddressDto) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 9 with CenterUpdate

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

Example 10 with CenterUpdate

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

Aggregations

CenterUpdate (org.mifos.dto.domain.CenterUpdate)12 Test (org.junit.Test)10 UserContext (org.mifos.security.util.UserContext)10 AddressDto (org.mifos.dto.domain.AddressDto)7 SimpleDateFormat (java.text.SimpleDateFormat)6 ArrayList (java.util.ArrayList)6 CustomFieldDto (org.mifos.dto.domain.CustomFieldDto)6 CustomerPositionDto (org.mifos.dto.domain.CustomerPositionDto)6 CenterUpdateBuilder (org.mifos.domain.builders.CenterUpdateBuilder)5 LocalDate (org.joda.time.LocalDate)2 CenterBO (org.mifos.customers.center.business.CenterBO)2 CustomerException (org.mifos.customers.exceptions.CustomerException)2 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)2 OfficeBuilder (org.mifos.domain.builders.OfficeBuilder)2 ApplicationException (org.mifos.framework.exceptions.ApplicationException)2 Date (java.util.Date)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 CustomerNoteEntity (org.mifos.customers.business.CustomerNoteEntity)1 CenterCustActionForm (org.mifos.customers.center.struts.actionforms.CenterCustActionForm)1 CustomerStatusFlag (org.mifos.customers.util.helpers.CustomerStatusFlag)1