use of org.mifos.customers.center.business.CenterBO in project head by mifos.
the class CustomerSearchIdGenerationTest method removeGroupMembershipTest.
@Test
public void removeGroupMembershipTest() throws Exception {
// setup
short localeId = 1;
CustomerStatusUpdate customerStatusUpdate = new CustomerStatusUpdateBuilder().with(CustomerStatus.GROUP_CANCELLED).build();
PersonnelBO loanOfficer = PersonnelBuilder.anyLoanOfficer();
CenterBO existingCenter = new CenterBuilder().withLoanOfficer(loanOfficer).active().withNumberOfExistingCustomersInOffice(1).build();
GroupBO existingGroup = new GroupBuilder().pendingApproval().withParentCustomer(existingCenter).withVersion(customerStatusUpdate.getVersionNum()).build();
ClientBO existingClient = new ClientBuilder().withParentCustomer(existingGroup).pendingApproval().buildForUnitTests();
existingGroup.addChild(existingClient);
UserContext userContext = TestUtils.makeUser();
existingGroup.setUserContext(userContext);
existingClient.setUserContext(userContext);
existingClient.setCustomerDao(customerDao);
// stubbing
when(configurationPersistence.isGlimEnabled()).thenReturn(false);
when(customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(anyShort())).thenReturn(3);
existingClient = spy(existingClient);
int customer_id = 22;
when(existingClient.getCustomerId()).thenReturn(customer_id);
// exercise test
assertThat(existingClient.getSearchId(), is("1.1.1.1"));
customerService.removeGroupMembership(existingClient, loanOfficer, accountNotesEntity, localeId);
// verification
assertThat(existingClient.getSearchId(), is("1." + customer_id));
}
use of org.mifos.customers.center.business.CenterBO 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.customers.center.business.CenterBO 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.customers.center.business.CenterBO 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.customers.center.business.CenterBO 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));
}
Aggregations