Search in sources :

Example 1 with GroupUpdateBuilder

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

the class GroupUpdateTest method updatesLoanOfficerForAllChildrenAndThierAccountsWhenLoanOfficerIsUpdated.

@Test
public void updatesLoanOfficerForAllChildrenAndThierAccountsWhenLoanOfficerIsUpdated() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    GroupUpdate groupUpdate = new GroupUpdateBuilder().build();
    PersonnelBO newLoanOfficer = new PersonnelBuilder().anyLoanOfficer();
    // stubbing
    when(customerDao.findGroupBySystemId(groupUpdate.getGlobalCustNum())).thenReturn(mockedGroup);
    when(mockedGroup.isNameDifferent(groupUpdate.getDisplayName())).thenReturn(false);
    when(personnelDao.findPersonnelById(groupUpdate.getLoanOfficerId())).thenReturn(newLoanOfficer);
    when(mockedGroup.isLoanOfficerChanged(newLoanOfficer)).thenReturn(true);
    when(mockedGroup.getOffice()).thenReturn(new OfficeBuilder().build());
    // exercise test
    customerService.updateGroup(userContext, groupUpdate);
    // verification
    verify(mockedGroup).setLoanOfficer(newLoanOfficer);
    verify(mockedGroup).validate();
    verify(customerDao).updateLoanOfficersForAllChildrenAndAccounts(anyShort(), anyString(), anyShort());
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) GroupUpdateBuilder(org.mifos.domain.builders.GroupUpdateBuilder) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) GroupUpdate(org.mifos.dto.domain.GroupUpdate) Test(org.junit.Test)

Example 2 with GroupUpdateBuilder

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

the class GroupUpdateTest method rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs.

@Test(expected = MifosRuntimeException.class)
public void rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    GroupUpdate groupUpdate = new GroupUpdateBuilder().build();
    PersonnelBO newLoanOfficer = new PersonnelBuilder().anyLoanOfficer();
    // stubbing
    when(customerDao.findGroupBySystemId(groupUpdate.getGlobalCustNum())).thenReturn(mockedGroup);
    when(mockedGroup.isNameDifferent(groupUpdate.getDisplayName())).thenReturn(false);
    when(personnelDao.findPersonnelById(groupUpdate.getLoanOfficerId())).thenReturn(newLoanOfficer);
    when(mockedGroup.isLoanOfficerChanged(newLoanOfficer)).thenReturn(false);
    when(mockedGroup.getOffice()).thenReturn(new OfficeBuilder().build());
    // stub
    doThrow(new RuntimeException()).when(customerDao).save(mockedGroup);
    // exercise test
    customerService.updateGroup(userContext, groupUpdate);
    // verification
    verify(hibernateTransactionHelper).rollbackTransaction();
    verify(hibernateTransactionHelper).closeSession();
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) GroupUpdateBuilder(org.mifos.domain.builders.GroupUpdateBuilder) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) GroupUpdate(org.mifos.dto.domain.GroupUpdate) Test(org.junit.Test)

Example 3 with GroupUpdateBuilder

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

the class GroupUpdateTest method rollsbackTransactionClosesSessionAndReThrowsApplicationException.

@Test(expected = CustomerException.class)
public void rollsbackTransactionClosesSessionAndReThrowsApplicationException() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    GroupUpdate groupUpdate = new GroupUpdateBuilder().build();
    PersonnelBO newLoanOfficer = new PersonnelBuilder().anyLoanOfficer();
    // stubbing
    when(customerDao.findGroupBySystemId(groupUpdate.getGlobalCustNum())).thenReturn(mockedGroup);
    when(mockedGroup.isNameDifferent(groupUpdate.getDisplayName())).thenReturn(false);
    when(personnelDao.findPersonnelById(groupUpdate.getLoanOfficerId())).thenReturn(newLoanOfficer);
    when(mockedGroup.isLoanOfficerChanged(newLoanOfficer)).thenReturn(false);
    when(mockedGroup.getOffice()).thenReturn(new OfficeBuilder().build());
    // stub
    doThrow(new CustomerException(CustomerConstants.ERRORS_DUPLICATE_CUSTOMER)).when(mockedGroup).validate();
    // exercise test
    customerService.updateGroup(userContext, groupUpdate);
    // verification
    verify(hibernateTransactionHelper).rollbackTransaction();
    verify(hibernateTransactionHelper).closeSession();
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) GroupUpdateBuilder(org.mifos.domain.builders.GroupUpdateBuilder) CustomerException(org.mifos.customers.exceptions.CustomerException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) GroupUpdate(org.mifos.dto.domain.GroupUpdate) Test(org.junit.Test)

Example 4 with GroupUpdateBuilder

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

the class GroupUpdateTest method trainedDetailsAreUpdated.

@Test
public void trainedDetailsAreUpdated() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    GroupUpdate groupUpdate = new GroupUpdateBuilder().build();
    // stubbing
    when(customerDao.findGroupBySystemId(groupUpdate.getGlobalCustNum())).thenReturn(mockedGroup);
    // exercise test
    customerService.updateGroup(userContext, groupUpdate);
    // verification
    verify(mockedGroup).updateTrainedDetails(groupUpdate);
}
Also used : GroupUpdateBuilder(org.mifos.domain.builders.GroupUpdateBuilder) UserContext(org.mifos.security.util.UserContext) GroupUpdate(org.mifos.dto.domain.GroupUpdate) Test(org.junit.Test)

Example 5 with GroupUpdateBuilder

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

the class GroupUpdateTest method userContextIsSetBeforeBeginningAuditLogging.

@Test
public void userContextIsSetBeforeBeginningAuditLogging() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    GroupUpdate groupUpdate = new GroupUpdateBuilder().build();
    // stubbing
    when(customerDao.findGroupBySystemId(groupUpdate.getGlobalCustNum())).thenReturn(mockedGroup);
    // exercise test
    customerService.updateGroup(userContext, groupUpdate);
    // verification
    InOrder inOrder = inOrder(hibernateTransactionHelper, mockedGroup);
    inOrder.verify(mockedGroup).setUserContext(userContext);
    inOrder.verify(hibernateTransactionHelper).beginAuditLoggingFor(mockedGroup);
}
Also used : GroupUpdateBuilder(org.mifos.domain.builders.GroupUpdateBuilder) InOrder(org.mockito.InOrder) UserContext(org.mifos.security.util.UserContext) GroupUpdate(org.mifos.dto.domain.GroupUpdate) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 GroupUpdateBuilder (org.mifos.domain.builders.GroupUpdateBuilder)8 GroupUpdate (org.mifos.dto.domain.GroupUpdate)8 UserContext (org.mifos.security.util.UserContext)8 OfficeBuilder (org.mifos.domain.builders.OfficeBuilder)4 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)3 PersonnelBuilder (org.mifos.domain.builders.PersonnelBuilder)3 CustomerException (org.mifos.customers.exceptions.CustomerException)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 InOrder (org.mockito.InOrder)1