use of org.mifos.domain.builders.GroupBuilder in project head by mifos.
the class GroupValidationTest method givenCenterIsSameAsGroupsParentGroupTransferToCenterShouldFailValidation.
@Test
public void givenCenterIsSameAsGroupsParentGroupTransferToCenterShouldFailValidation() {
// setup
CenterBO center = new CenterBuilder().build();
GroupBO group = new GroupBuilder().withParentCustomer(center).build();
// exercise test
try {
group.validateReceivingCenter(center);
fail("should fail validation");
} catch (CustomerException e) {
assertThat(e.getKey(), is(CustomerConstants.ERRORS_SAME_CENTER_TRANSFER));
}
}
use of org.mifos.domain.builders.GroupBuilder in project head by mifos.
the class GroupValidationTest method givenGroupIsTrainedButTrainedDateIsNotSetThenShouldThrowCustomerException.
@Test
public void givenGroupIsTrainedButTrainedDateIsNotSetThenShouldThrowCustomerException() {
PersonnelBO formedBy = new PersonnelBuilder().build();
group = new GroupBuilder().withName("group-On-center").withParentCustomer(center).formedBy(formedBy).isTrained().trainedOn(null).build();
try {
group.validate();
fail("should throw customer exception as trained date must be provided if in trained state when creating group.");
} catch (CustomerException e) {
assertThat(e.getKey(), is(CustomerConstants.INVALID_TRAINED_OR_TRAINEDDATE));
}
}
use of org.mifos.domain.builders.GroupBuilder 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.domain.builders.GroupBuilder in project head by mifos.
the class CustomerSearchIdGenerationTest method transferClientFromGroupToGroupTest.
@Test
public void transferClientFromGroupToGroupTest() throws Exception {
final short office1_id = 2;
final Integer group1_id = 33;
final Integer group2_id = 22;
final int group2_child_count = 8;
// setup
UserContext userContext = TestUtils.makeUser();
OfficeBO office1 = new OfficeBuilder().withName("office1").branchOffice().withOfficeId(office1_id).build();
PersonnelBO loanOfficer = PersonnelBuilder.anyLoanOfficer();
GroupBO existingGroup = new GroupBuilder().pendingApproval().withLoanOfficer(loanOfficer).with(userContext).buildAsTopOfHierarchy();
existingGroup = spy(existingGroup);
when(existingGroup.getCustomerId()).thenReturn(group1_id);
existingGroup.generateSearchId();
ClientBO existingClient = new ClientBuilder().pendingApproval().withParentCustomer(existingGroup).withVersion(1).buildForUnitTests();
existingGroup.addChild(existingClient);
existingGroup.setCustomerDao(customerDao);
GroupBO existingGroup2 = new GroupBuilder().pendingApproval().withLoanOfficer(loanOfficer).with(userContext).withSearchId(group2_child_count).withOffice(office1).buildAsTopOfHierarchy();
existingGroup2.setCustomerDao(customerDao);
existingGroup2 = spy(existingGroup2);
when(existingGroup2.getCustomerId()).thenReturn(group2_id);
existingGroup2.generateSearchId();
// stubbing
when(customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(office1_id)).thenReturn(3);
when(customerDao.findClientBySystemId("clientid")).thenReturn(existingClient);
when(customerDao.findCustomerById(group2_id)).thenReturn(existingGroup2);
when(holidayDao.findCalendarEventsForThisYearAndNext(anyShort())).thenReturn(calendarEvent);
when(configurationHelper.isLoanScheduleRepaymentIndependentOfCustomerMeetingEnabled()).thenReturn(true);
// exercise test
assertThat(existingGroup.getSearchId(), is("1." + group1_id));
assertThat(existingClient.getSearchId(), is("1." + group1_id + ".1"));
customerService.transferClientTo(userContext, group2_id, "clientid", 1);
// verification
assertThat(existingGroup2.getSearchId(), is("1." + group2_id));
assertThat(existingClient.getSearchId(), is("1." + group2_id + "." + (group2_child_count + 1)));
}
use of org.mifos.domain.builders.GroupBuilder 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);
}
Aggregations