use of org.mifos.domain.builders.CenterBuilder in project head by mifos.
the class CustomerStatusUpdateTest method throwsCheckedExceptionWhenUserDoesNotHavePermissionToUpdateCustomerStatus.
@Test(expected = CustomerException.class)
public void throwsCheckedExceptionWhenUserDoesNotHavePermissionToUpdateCustomerStatus() throws Exception {
// setup
UserContext userContext = TestUtils.makeUser();
CustomerStatusUpdate customerStatusUpdate = new CustomerStatusUpdateBuilder().build();
CenterBO existingCenter = new CenterBuilder().withVersion(customerStatusUpdate.getVersionNum()).build();
// stubbing
when(customerDao.findCustomerById(customerStatusUpdate.getCustomerId())).thenReturn(existingCenter);
doThrow(new CustomerException(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED)).when(customerDao).checkPermissionForStatusChange(anyShort(), eq(userContext), anyShort(), anyShort(), anyShort());
// exercise test
customerService.updateCustomerStatus(userContext, customerStatusUpdate);
// verification
verify(customerDao).checkPermissionForStatusChange(customerStatusUpdate.getNewStatus().getValue(), userContext, customerStatusUpdate.getCustomerStatusFlag().getValue(), existingCenter.getOffice().getOfficeId(), existingCenter.getPersonnel().getPersonnelId());
}
use of org.mifos.domain.builders.CenterBuilder 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();
}
use of org.mifos.domain.builders.CenterBuilder in project head by mifos.
the class GroupCreationTest method throwsCheckedExceptionWhenGroupNameIsTakenForOfficeAlready.
@Test(expected = CustomerException.class)
public void throwsCheckedExceptionWhenGroupNameIsTakenForOfficeAlready() throws Exception {
// setup
CenterBO parent = new CenterBuilder().withLoanOfficer(anyLoanOfficer()).build();
GroupBO stubbedGroup = new GroupBuilder().withName("already-exists-group").withParentCustomer(parent).formedBy(anyLoanOfficer()).build();
List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>();
// stubbing
doThrow(new CustomerException(CustomerConstants.ERRORS_DUPLICATE_CUSTOMER)).when(customerDao).validateGroupNameIsNotTakenForOffice(anyString(), anyShort());
// exercise test
customerService.createGroup(stubbedGroup, meeting, accountFees);
}
use of org.mifos.domain.builders.CenterBuilder in project head by mifos.
the class GroupCreationTest method createsGroupWithCustomerAccount.
@Test
public void createsGroupWithCustomerAccount() throws Exception {
// setup
OfficeBO withOffice = new OfficeBO(new Short("1"), "testOffice", new Integer("1"), new Short("1"));
CenterBO parent = new CenterBuilder().withLoanOfficer(anyLoanOfficer()).with(withOffice).build();
GroupBO stubbedGroup = new GroupBuilder().withName("group").withParentCustomer(parent).formedBy(anyLoanOfficer()).build();
List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>();
// stub
CalendarEvent upcomingCalendarEvents = new CalendarEventBuilder().build();
when(holidayDao.findCalendarEventsForThisYearAndNext((short) 1)).thenReturn(upcomingCalendarEvents);
when(customerAccountFactory.create(stubbedGroup, accountFees, meeting, upcomingCalendarEvents)).thenReturn(customerAccount);
when(customerAccount.getType()).thenReturn(AccountTypes.CUSTOMER_ACCOUNT);
// exercise test
customerService.createGroup(stubbedGroup, meeting, accountFees);
// verification
assertThat(stubbedGroup.getCustomerAccount(), is(customerAccount));
}
use of org.mifos.domain.builders.CenterBuilder in project head by mifos.
the class GroupCreationTest method rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs.
@Test(expected = MifosRuntimeException.class)
public void rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs() throws Exception {
// setup
CenterBO parent = new CenterBuilder().withLoanOfficer(anyLoanOfficer()).build();
GroupBO stubbedGroup = new GroupBuilder().withName("group").withParentCustomer(parent).formedBy(anyLoanOfficer()).build();
List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>();
// stub
doThrow(new RuntimeException()).when(customerDao).save(stubbedGroup);
// exercise test
customerService.createGroup(stubbedGroup, meeting, accountFees);
// verification
verify(hibernateTransactionHelper).rollbackTransaction();
verify(hibernateTransactionHelper).closeSession();
}
Aggregations