Search in sources :

Example 76 with CenterBuilder

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

the class CustomerAccountGenerateNextSetOfMeetingDatesTest method canGenerateTenSchedulesMatchingMeetingRecurrenceWhenNoPreviousSchedulesExisted.

@Test
public void canGenerateTenSchedulesMatchingMeetingRecurrenceWhenNoPreviousSchedulesExisted() throws Exception {
    // use default setup
    customer = new CenterBuilder().inActive().build();
    customerAccount = CustomerAccountBO.createNew(customer, accountFees, customer.getCustomerMeetingValue(), calendarEvent);
    DateTime lastScheduledDate = new DateTime().toDateMidnight().toDateTime();
    ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(customer.getCustomerMeetingValue());
    // pre verification
    assertThat(customerAccount.getAccountActionDates().isEmpty(), is(true));
    // 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().isEmpty(), is(false));
    assertThat(customerAccount.getAccountActionDates().size(), is(10));
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) CenterBuilder(org.mifos.domain.builders.CenterBuilder) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 77 with CenterBuilder

use of org.mifos.domain.builders.CenterBuilder 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));
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ArrayList(java.util.ArrayList) CenterBuilder(org.mifos.domain.builders.CenterBuilder) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) DateTime(org.joda.time.DateTime) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) FeeBuilder(org.mifos.domain.builders.FeeBuilder) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Test(org.junit.Test)

Example 78 with CenterBuilder

use of org.mifos.domain.builders.CenterBuilder 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));
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) ScheduledEvent(org.mifos.schedule.ScheduledEvent) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ArrayList(java.util.ArrayList) CenterBuilder(org.mifos.domain.builders.CenterBuilder) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 79 with CenterBuilder

use of org.mifos.domain.builders.CenterBuilder 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));
}
Also used : CustomerStatusUpdate(org.mifos.application.servicefacade.CustomerStatusUpdate) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) GroupBuilder(org.mifos.domain.builders.GroupBuilder) ClientBO(org.mifos.customers.client.business.ClientBO) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) GroupBO(org.mifos.customers.group.business.GroupBO) CustomerStatusUpdateBuilder(org.mifos.domain.builders.CustomerStatusUpdateBuilder) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 80 with CenterBuilder

use of org.mifos.domain.builders.CenterBuilder 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");
    }
}
Also used : PaymentData(org.mifos.accounts.util.helpers.PaymentData) MeetingBO(org.mifos.application.meeting.business.MeetingBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) CenterBuilder(org.mifos.domain.builders.CenterBuilder) Date(java.sql.Date) SystemException(org.mifos.framework.exceptions.SystemException) AccountException(org.mifos.accounts.exceptions.AccountException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) Test(org.junit.Test)

Aggregations

CenterBuilder (org.mifos.domain.builders.CenterBuilder)123 Test (org.junit.Test)98 CenterBO (org.mifos.customers.center.business.CenterBO)82 MeetingBuilder (org.mifos.domain.builders.MeetingBuilder)73 MeetingBO (org.mifos.application.meeting.business.MeetingBO)54 GroupBuilder (org.mifos.domain.builders.GroupBuilder)53 DateTime (org.joda.time.DateTime)52 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)46 ArrayList (java.util.ArrayList)42 GroupBO (org.mifos.customers.group.business.GroupBO)36 ClientBuilder (org.mifos.domain.builders.ClientBuilder)30 OfficeBO (org.mifos.customers.office.business.OfficeBO)21 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)19 CustomerException (org.mifos.customers.exceptions.CustomerException)18 FeeBuilder (org.mifos.domain.builders.FeeBuilder)18 CalendarEventBuilder (org.mifos.domain.builders.CalendarEventBuilder)17 LocalDate (org.joda.time.LocalDate)14 Before (org.junit.Before)14 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)13 ClientBO (org.mifos.customers.client.business.ClientBO)13