Search in sources :

Example 1 with ClientMfiInfoUpdateBuilder

use of org.mifos.domain.builders.ClientMfiInfoUpdateBuilder 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 ClientMfiInfoUpdateBuilder

use of org.mifos.domain.builders.ClientMfiInfoUpdateBuilder 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 ClientMfiInfoUpdateBuilder

use of org.mifos.domain.builders.ClientMfiInfoUpdateBuilder 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 ClientMfiInfoUpdateBuilder

use of org.mifos.domain.builders.ClientMfiInfoUpdateBuilder 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 ClientMfiInfoUpdateBuilder

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

the class ClientUpdateTest method clientMfiDetailsAreUpdated.

@Test
public void clientMfiDetailsAreUpdated() 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);
    // exercise test
    customerService.updateClientMfiInfo(userContext, clientMfiInfoUpdate);
    // verification
    verify(mockedClient).updateMfiInfo(personnel, clientMfiInfoUpdate);
}
Also used : ClientMfiInfoUpdateBuilder(org.mifos.domain.builders.ClientMfiInfoUpdateBuilder) UserContext(org.mifos.security.util.UserContext) ClientMfiInfoUpdate(org.mifos.dto.domain.ClientMfiInfoUpdate) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 ClientMfiInfoUpdateBuilder (org.mifos.domain.builders.ClientMfiInfoUpdateBuilder)5 ClientMfiInfoUpdate (org.mifos.dto.domain.ClientMfiInfoUpdate)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