use of org.mifos.domain.builders.MeetingBuilder in project head by mifos.
the class UpdateCustomerMeetingScheduleTest method givenLsimIsEnabledShouldNotRegenerateSchedulesForLoanAccountsButShouldRegenerateSchedulesForCustomerAndSavingsAccounts.
@Test
public void givenLsimIsEnabledShouldNotRegenerateSchedulesForLoanAccountsButShouldRegenerateSchedulesForCustomerAndSavingsAccounts() throws Exception {
// setup
UserContext userContext = TestUtils.makeUser();
DateTime mondayTwoWeeksAgo = new DateTime().withDayOfWeek(DayOfWeek.monday()).minusWeeks(2);
MeetingBO weeklyMeeting = new MeetingBuilder().customerMeeting().weekly().every(1).withStartDate(mondayTwoWeeksAgo).build();
weeklyMeeting.updateDetails(userContext);
CustomerAccountBuilder accountBuilder = new CustomerAccountBuilder();
CenterBO center = new CenterBuilder().active().with(weeklyMeeting).withAccount(accountBuilder).withAccount(this.loanAccount).build();
MeetingBO weeklyWednesdayMeeting = new MeetingBuilder().customerMeeting().weekly().every(1).occuringOnA(WeekDay.WEDNESDAY).build();
weeklyWednesdayMeeting.updateDetails(userContext);
// stubbing
CalendarEvent calendarEvent = new CalendarEventBuilder().build();
when(holidayDao.findCalendarEventsForThisYearAndNext(anyShort())).thenReturn(calendarEvent);
when(configurationHelper.isLoanScheduleRepaymentIndependentOfCustomerMeetingEnabled()).thenReturn(true);
// pre - verification
assertThatAllCustomerSchedulesOccuringAfterCurrentInstallmentPeriodFallOnDayOfWeek(center, WeekDay.MONDAY);
// exercise test
customerService.updateCustomerMeetingSchedule(weeklyWednesdayMeeting, center);
// verification
assertThatAllCustomerSchedulesOccuringBeforeOrOnCurrentInstallmentPeriodRemainUnchanged(center, WeekDay.MONDAY);
assertThatAllCustomerSchedulesOccuringAfterCurrentInstallmentPeriodFallOnDayOfWeek(center, WeekDay.WEDNESDAY);
}
use of org.mifos.domain.builders.MeetingBuilder in project head by mifos.
the class CustomerAccountGenerateNextSetOfMeetingDatesTest method canGenerateNextSetOfMeetingScheduleOnTopOfPreviousMeetingScheduleWithRecurringFees.
@Test
public void canGenerateNextSetOfMeetingScheduleOnTopOfPreviousMeetingScheduleWithRecurringFees() {
// use default setup
MeetingBuilder weeklyMeetingBuilder = new MeetingBuilder().customerMeeting().weekly().every(1);
MeetingBO customerMeeting = weeklyMeetingBuilder.build();
customer = new CenterBuilder().active().with(customerMeeting).build();
AmountFeeBO recurringFee = new FeeBuilder().appliesToAllCustomers().periodic().with(weeklyMeetingBuilder).withFeeAmount("3.0").build();
AccountFeesEntity recurringFeeEntity = new AccountFeesEntity(null, recurringFee, recurringFee.getFeeAmount().getAmountDoubleValue());
recurringFeeEntity = spy(recurringFeeEntity);
when(recurringFeeEntity.getAccountFeeId()).thenReturn(1);
accountFees = new ArrayList<AccountFeesEntity>();
accountFees.add(recurringFeeEntity);
customerAccount = CustomerAccountBO.createNew(customer, accountFees, customerMeeting, calendarEvent);
// setup
AccountFeesEntity sameButDifferentRecurringFeeEntity = new AccountFeesEntity(customerAccount, recurringFee, recurringFee.getFeeAmount().getAmountDoubleValue());
sameButDifferentRecurringFeeEntity = spy(sameButDifferentRecurringFeeEntity);
customerAccount.getAccountFees().clear();
customerAccount.addAccountFees(sameButDifferentRecurringFeeEntity);
when(sameButDifferentRecurringFeeEntity.getAccountFeeId()).thenReturn(1);
List<AccountActionDateEntity> schedules = new ArrayList<AccountActionDateEntity>(customerAccount.getAccountActionDates());
DateTime lastScheduledDate = new DateTime(schedules.get(9).getActionDate());
ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(customer.getCustomerMeetingValue());
// stubbing
List<DateTime> generatedDates = elevenDatesStartingFromAndIncluding(lastScheduledDate, scheduledEvent);
when(scheduledDateGeneration.generateScheduledDates(anyInt(), (DateTime) anyObject(), (ScheduledEvent) anyObject(), anyBoolean())).thenReturn(generatedDates);
// exercise test
customerAccount.generateNextSetOfMeetingDates(scheduledDateGeneration);
assertThat(customerAccount.getAccountActionDates().size(), is(20));
}
use of org.mifos.domain.builders.MeetingBuilder in project head by mifos.
the class CustomerAccountGenerateNextSetOfMeetingDatesTest method canGenerateNextSetOfMeetingDatesWithFreshlyGeneratedSchedule.
@Test
public void canGenerateNextSetOfMeetingDatesWithFreshlyGeneratedSchedule() {
// use default setup
MeetingBO customerMeeting = new MeetingBuilder().customerMeeting().weekly().every(1).build();
customer = new CenterBuilder().active().with(customerMeeting).build();
customerAccount = CustomerAccountBO.createNew(customer, accountFees, customerMeeting, calendarEvent);
// pre verification
assertThat(customerAccount.getAccountActionDates().size(), is(10));
// setup
List<AccountActionDateEntity> schedules = new ArrayList<AccountActionDateEntity>(customerAccount.getAccountActionDates());
DateTime lastScheduledDate = new DateTime(schedules.get(9).getActionDate());
ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(customer.getCustomerMeetingValue());
// stubbing
List<DateTime> generatedDates = elevenDatesStartingFromAndIncluding(lastScheduledDate, scheduledEvent);
when(scheduledDateGeneration.generateScheduledDates(anyInt(), (DateTime) anyObject(), (ScheduledEvent) anyObject(), anyBoolean())).thenReturn(generatedDates);
// exercise test
customerAccount.generateNextSetOfMeetingDates(scheduledDateGeneration);
//verification
assertThat(customerAccount.getAccountActionDates().size(), is(20));
}
use of org.mifos.domain.builders.MeetingBuilder in project head by mifos.
the class CustomerAccountBOIntegrationTest method testTrxnDetailEntityObjectsForMultipleInstallmentsWhenOnlyCustomerAccountChargesAreDue.
@Test
public void testTrxnDetailEntityObjectsForMultipleInstallmentsWhenOnlyCustomerAccountChargesAreDue() throws Exception {
MeetingBO weeklyMeeting = new MeetingBuilder().customerMeeting().weekly().every(1).startingToday().build();
center = new CenterBuilder().with(weeklyMeeting).withName("Center").with(sampleBranchOffice()).withLoanOfficer(testUser()).build();
IntegrationTestObjectMother.createCenter((CenterBO) center, weeklyMeeting);
CustomerAccountBO customerAccount = center.getCustomerAccount();
final Money fiftyAmount = new Money(getCurrency(), "50.0");
final Money seventyAmount = new Money(getCurrency(), "70.0");
final Money oneHundredTwentyAmount = new Money(getCurrency(), "120.0");
final Money twoHundredFortyAmount = new Money(getCurrency(), "240.0");
for (AccountActionDateEntity accountActionDateEntity : customerAccount.getAccountActionDates()) {
CustomerScheduleEntity customerSchedule = (CustomerScheduleEntity) accountActionDateEntity;
if (customerSchedule.getInstallmentId() != 2) {
customerSchedule.setMiscFee(fiftyAmount);
customerSchedule.setMiscPenalty(seventyAmount);
}
}
Date transactionDate = incrementCurrentDate(14);
PaymentData paymentData = PaymentData.createPaymentData(twoHundredFortyAmount, center.getPersonnel(), Short.valueOf("1"), transactionDate);
paymentData.setCustomer(center);
IntegrationTestObjectMother.applyAccountPayment(customerAccount, paymentData);
if (customerAccount.getAccountPayments() != null && customerAccount.getAccountPayments().size() == 1) {
for (AccountPaymentEntity accountPaymentEntity : customerAccount.getAccountPayments()) {
final Money zeroAmount = new Money(accountPaymentEntity.getAmount().getCurrency(), "0.0");
if (accountPaymentEntity.getAccountTrxns() != null && accountPaymentEntity.getAccountTrxns().size() == 3) {
for (AccountTrxnEntity accountTrxnEntity : accountPaymentEntity.getAccountTrxns()) {
CustomerTrxnDetailEntity customerTrxnDetailEntity = (CustomerTrxnDetailEntity) accountTrxnEntity;
if (customerTrxnDetailEntity.getInstallmentId() != 2) {
Assert.assertEquals(oneHundredTwentyAmount, customerTrxnDetailEntity.getAmount());
Assert.assertEquals(oneHundredTwentyAmount, customerTrxnDetailEntity.getTotalAmount());
Assert.assertEquals(fiftyAmount, customerTrxnDetailEntity.getMiscFeeAmount());
Assert.assertEquals(seventyAmount, customerTrxnDetailEntity.getMiscPenaltyAmount());
} else {
Assert.assertEquals(zeroAmount, customerTrxnDetailEntity.getAmount());
Assert.assertEquals(zeroAmount, customerTrxnDetailEntity.getTotalAmount());
Assert.assertEquals(zeroAmount, customerTrxnDetailEntity.getMiscFeeAmount());
Assert.assertEquals(zeroAmount, customerTrxnDetailEntity.getMiscPenaltyAmount());
}
Assert.assertEquals(0, customerTrxnDetailEntity.getFeesTrxnDetails().size());
}
} else {
throw new Exception("Expected three CustomerTrxnDetailEntity, found none or not three");
}
}
} else {
throw new Exception("Expected one AccountPaymentEntity, found none or more than one");
}
}
use of org.mifos.domain.builders.MeetingBuilder in project head by mifos.
the class CenterValidationTest method cannotCreateCenterWithMultipleInstancesOfSamePeriodFee.
@Test
public void cannotCreateCenterWithMultipleInstancesOfSamePeriodFee() {
// setup
DateTime today = new DateTime();
MeetingBuilder aWeeklyMeeting = new MeetingBuilder().customerMeeting().weekly();
CenterBO center = new CenterBuilder().withName("center1").withLoanOfficer(anyLoanOfficer()).with(aWeeklyMeeting).withMfiJoiningDate(today).build();
MeetingBuilder aWeeklyFeeMeeting = new MeetingBuilder().periodicFeeMeeting().weekly();
AmountFeeBO montlyPeriodicFee = new FeeBuilder().appliesToCenterOnly().with(aWeeklyFeeMeeting).build();
AccountFeesEntity accountFee = new AccountFeesEntity(null, montlyPeriodicFee, montlyPeriodicFee.getFeeAmount().getAmountDoubleValue());
List<AccountFeesEntity> centerAccountFees = new ArrayList<AccountFeesEntity>();
centerAccountFees.add(accountFee);
centerAccountFees.add(accountFee);
// exercise test
try {
center.validateMeetingAndFees(centerAccountFees);
fail("cannotCreateCenterWithFeeThatHasDifferentPeriod");
} catch (ApplicationException e) {
assertThat(e.getKey(), is(CustomerConstants.ERRORS_DUPLICATE_PERIODIC_FEE));
}
}
Aggregations