Search in sources :

Example 1 with ClientPersonalInfoUpdateBuilder

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

the class ClientUpdateTest method clientPersonalDetailsAreUpdated.

@Test
public void clientPersonalDetailsAreUpdated() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    ClientPersonalInfoUpdate clientPersonalInfoUpdate = new ClientPersonalInfoUpdateBuilder().build();
    // stubbing
    when(customerDao.findCustomerById(clientPersonalInfoUpdate.getCustomerId())).thenReturn(mockedClient);
    // exercise test
    customerService.updateClientPersonalInfo(userContext, clientPersonalInfoUpdate);
    // verification
    verify(mockedClient).updatePersonalInfo(clientPersonalInfoUpdate);
}
Also used : ClientPersonalInfoUpdate(org.mifos.dto.domain.ClientPersonalInfoUpdate) UserContext(org.mifos.security.util.UserContext) ClientPersonalInfoUpdateBuilder(org.mifos.domain.builders.ClientPersonalInfoUpdateBuilder) Test(org.junit.Test)

Example 2 with ClientPersonalInfoUpdateBuilder

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

the class ClientUpdateTest method rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs2.

@Test(expected = MifosRuntimeException.class)
public void rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs2() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    ClientPersonalInfoUpdate clientPersonalInfoUpdate = new ClientPersonalInfoUpdateBuilder().build();
    // stubbing
    when(customerDao.findCustomerById(clientPersonalInfoUpdate.getCustomerId())).thenReturn(mockedClient);
    doThrow(new RuntimeException()).when(customerDao).save(mockedClient);
    // exercise test
    customerService.updateClientPersonalInfo(userContext, clientPersonalInfoUpdate);
    // verification
    verify(hibernateTransactionHelper).rollbackTransaction();
    verify(hibernateTransactionHelper).closeSession();
}
Also used : ClientPersonalInfoUpdate(org.mifos.dto.domain.ClientPersonalInfoUpdate) MifosRuntimeException(org.mifos.core.MifosRuntimeException) UserContext(org.mifos.security.util.UserContext) ClientPersonalInfoUpdateBuilder(org.mifos.domain.builders.ClientPersonalInfoUpdateBuilder) Test(org.junit.Test)

Example 3 with ClientPersonalInfoUpdateBuilder

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

the class ClientUpdateTest method throwsCheckedExceptionWhenVersionOfClientForUpdateIsDifferentToPersistedClient.

@Test(expected = CustomerException.class)
public void throwsCheckedExceptionWhenVersionOfClientForUpdateIsDifferentToPersistedClient() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    ClientPersonalInfoUpdate clientPersonalInfoUpdate = new ClientPersonalInfoUpdateBuilder().build();
    // stubbing
    when(customerDao.findCustomerById(clientPersonalInfoUpdate.getCustomerId())).thenReturn(mockedClient);
    doThrow(new CustomerException(Constants.ERROR_VERSION_MISMATCH)).when(mockedClient).validateVersion(clientPersonalInfoUpdate.getOriginalClientVersionNumber());
    // exercise test
    customerService.updateClientPersonalInfo(userContext, clientPersonalInfoUpdate);
    // verify
    verify(mockedClient).validateVersion(clientPersonalInfoUpdate.getOriginalClientVersionNumber());
}
Also used : ClientPersonalInfoUpdate(org.mifos.dto.domain.ClientPersonalInfoUpdate) CustomerException(org.mifos.customers.exceptions.CustomerException) UserContext(org.mifos.security.util.UserContext) ClientPersonalInfoUpdateBuilder(org.mifos.domain.builders.ClientPersonalInfoUpdateBuilder) Test(org.junit.Test)

Example 4 with ClientPersonalInfoUpdateBuilder

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

the class ClientUpdateTest method userContextAndUpdateDetailsAreSetBeforeBeginningAuditLoggingForPersonalInfo.

@Test
public void userContextAndUpdateDetailsAreSetBeforeBeginningAuditLoggingForPersonalInfo() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    ClientPersonalInfoUpdate clientPersonalInfoUpdate = new ClientPersonalInfoUpdateBuilder().build();
    // stubbing
    when(customerDao.findCustomerById(clientPersonalInfoUpdate.getCustomerId())).thenReturn(mockedClient);
    // exercise test
    customerService.updateClientPersonalInfo(userContext, clientPersonalInfoUpdate);
    // verification
    InOrder inOrder = inOrder(hibernateTransactionHelper, mockedClient);
    inOrder.verify(mockedClient).updateDetails(userContext);
    inOrder.verify(hibernateTransactionHelper).beginAuditLoggingFor(mockedClient);
}
Also used : ClientPersonalInfoUpdate(org.mifos.dto.domain.ClientPersonalInfoUpdate) InOrder(org.mockito.InOrder) UserContext(org.mifos.security.util.UserContext) ClientPersonalInfoUpdateBuilder(org.mifos.domain.builders.ClientPersonalInfoUpdateBuilder) Test(org.junit.Test)

Example 5 with ClientPersonalInfoUpdateBuilder

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

the class ClientUpdateTest method rollsbackTransactionClosesSessionAndReThrowsApplicationException2.

@Test(expected = CustomerException.class)
public void rollsbackTransactionClosesSessionAndReThrowsApplicationException2() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    ClientPersonalInfoUpdate clientPersonalInfoUpdate = new ClientPersonalInfoUpdateBuilder().build();
    // stubbing
    when(customerDao.findCustomerById(clientPersonalInfoUpdate.getCustomerId())).thenReturn(mockedClient);
    doThrow(new CustomerException(ClientConstants.INVALID_DOB_EXCEPTION)).when(mockedClient).updatePersonalInfo(clientPersonalInfoUpdate);
    // exercise test
    customerService.updateClientPersonalInfo(userContext, clientPersonalInfoUpdate);
    // verification
    verify(hibernateTransactionHelper).rollbackTransaction();
    verify(hibernateTransactionHelper).closeSession();
}
Also used : ClientPersonalInfoUpdate(org.mifos.dto.domain.ClientPersonalInfoUpdate) CustomerException(org.mifos.customers.exceptions.CustomerException) UserContext(org.mifos.security.util.UserContext) ClientPersonalInfoUpdateBuilder(org.mifos.domain.builders.ClientPersonalInfoUpdateBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 ClientPersonalInfoUpdateBuilder (org.mifos.domain.builders.ClientPersonalInfoUpdateBuilder)5 ClientPersonalInfoUpdate (org.mifos.dto.domain.ClientPersonalInfoUpdate)5 UserContext (org.mifos.security.util.UserContext)5 CustomerException (org.mifos.customers.exceptions.CustomerException)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 InOrder (org.mockito.InOrder)1