Search in sources :

Example 11 with CustomerStatusUpdateBuilder

use of org.mifos.domain.builders.CustomerStatusUpdateBuilder in project head by mifos.

the class CustomerStatusUpdateTest method rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs.

@Test(expected = MifosRuntimeException.class)
public void rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    CustomerStatusUpdate customerStatusUpdate = new CustomerStatusUpdateBuilder().with(CustomerStatus.CENTER_INACTIVE).build();
    CenterBO existingCenter = new CenterBuilder().withVersion(customerStatusUpdate.getVersionNum()).active().build();
    CustomerDto customer1 = new CustomerDto();
    List<CustomerDto> clientsThatAreNotCancelledOrClosed = new ArrayList<CustomerDto>();
    clientsThatAreNotCancelledOrClosed.add(customer1);
    // stubbing
    when(customerDao.findCustomerById(customerStatusUpdate.getCustomerId())).thenReturn(existingCenter);
    doThrow(new RuntimeException()).when(customerDao).save(existingCenter);
    // exercise test
    customerService.updateCustomerStatus(userContext, customerStatusUpdate);
    // verification
    verify(hibernateTransaction).rollbackTransaction();
    verify(hibernateTransaction).closeSession();
}
Also used : CustomerStatusUpdate(org.mifos.application.servicefacade.CustomerStatusUpdate) MifosRuntimeException(org.mifos.core.MifosRuntimeException) UserContext(org.mifos.security.util.UserContext) CustomerDto(org.mifos.dto.domain.CustomerDto) ArrayList(java.util.ArrayList) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) CustomerStatusUpdateBuilder(org.mifos.domain.builders.CustomerStatusUpdateBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 CustomerStatusUpdate (org.mifos.application.servicefacade.CustomerStatusUpdate)11 CustomerStatusUpdateBuilder (org.mifos.domain.builders.CustomerStatusUpdateBuilder)11 UserContext (org.mifos.security.util.UserContext)11 CenterBO (org.mifos.customers.center.business.CenterBO)8 CenterBuilder (org.mifos.domain.builders.CenterBuilder)8 GroupBO (org.mifos.customers.group.business.GroupBO)4 GroupBuilder (org.mifos.domain.builders.GroupBuilder)4 ArrayList (java.util.ArrayList)3 CustomerException (org.mifos.customers.exceptions.CustomerException)3 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)3 CustomerDto (org.mifos.dto.domain.CustomerDto)3 CustomerStatusEntity (org.mifos.customers.business.CustomerStatusEntity)2 ClientBO (org.mifos.customers.client.business.ClientBO)2 OfficeBO (org.mifos.customers.office.business.OfficeBO)2 ClientBuilder (org.mifos.domain.builders.ClientBuilder)2 OfficeBuilder (org.mifos.domain.builders.OfficeBuilder)2 LocalDate (org.joda.time.LocalDate)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1