Search in sources :

Example 1 with CenterUpdateBuilder

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();
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) MifosRuntimeException(org.mifos.core.MifosRuntimeException) 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 2 with CenterUpdateBuilder

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();
}
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 3 with CenterUpdateBuilder

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));
    }
}
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 4 with CenterUpdateBuilder

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);
}
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 5 with CenterUpdateBuilder

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);
}
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

Test (org.junit.Test)5 CenterUpdateBuilder (org.mifos.domain.builders.CenterUpdateBuilder)5 CenterUpdate (org.mifos.dto.domain.CenterUpdate)5 UserContext (org.mifos.security.util.UserContext)5 CustomerException (org.mifos.customers.exceptions.CustomerException)2 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)2 OfficeBuilder (org.mifos.domain.builders.OfficeBuilder)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 CenterBO (org.mifos.customers.center.business.CenterBO)1 CenterBuilder (org.mifos.domain.builders.CenterBuilder)1 ApplicationException (org.mifos.framework.exceptions.ApplicationException)1 InOrder (org.mockito.InOrder)1