Search in sources :

Example 21 with OfficeBuilder

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

the class HolidayDaoHibernateIntegrationTest method shouldfindCurrentAndFutureOfficeHolidaysEarliestFirst.

@Test
public void shouldfindCurrentAndFutureOfficeHolidaysEarliestFirst() throws Exception {
    DateTime yesterday = new DateTime().minusDays(1);
    Set<HolidayBO> holidays;
    OfficeBO headOffice = IntegrationTestObjectMother.findOfficeById(Short.valueOf("1"));
    holidays = new HashSet<HolidayBO>();
    holidays.add((HolidayBO) new HolidayBuilder().withName("Fourth").from(yesterday.plusWeeks(4)).to(yesterday.plusWeeks(5)).build());
    holidays.add((HolidayBO) new HolidayBuilder().withName("Second").from(yesterday.plusDays(1)).to(yesterday.plusWeeks(7)).build());
    headOffice.setHolidays(holidays);
    IntegrationTestObjectMother.createOffice(headOffice);
    // builder not setting searchId correctly due to not going thru office.save (which uses HierarchyManager)
    String headOfficeSearchId = headOffice.getSearchId();
    OfficeBO areaOffice = new OfficeBuilder().withName("Area Office").withSearchId(headOfficeSearchId + "25.").withParentOffice(headOffice).withGlobalOfficeNum("area56").build();
    holidays = new HashSet<HolidayBO>();
    holidays.add((HolidayBO) new HolidayBuilder().withName("Fifth").from(yesterday.plusWeeks(8)).to(yesterday.plusWeeks(9)).build());
    areaOffice.setHolidays(holidays);
    IntegrationTestObjectMother.createOffice(areaOffice);
    OfficeBO myOffice = new OfficeBuilder().withName("My Office").withSearchId(headOfficeSearchId + "25.1.").withParentOffice(areaOffice).withGlobalOfficeNum("my001").build();
    holidays = new HashSet<HolidayBO>();
    holidays.add((HolidayBO) new HolidayBuilder().withName("Third").from(yesterday.plusWeeks(3)).to(yesterday.plusWeeks(4)).build());
    holidays.add((HolidayBO) new HolidayBuilder().withName("First").from(yesterday).to(yesterday.plusWeeks(2)).build());
    myOffice.setHolidays(holidays);
    IntegrationTestObjectMother.createOffice(myOffice);
    OfficeBO anotherOffice = new OfficeBuilder().withName("Another Unconnected Office").withSearchId(headOfficeSearchId + "26.").withParentOffice(headOffice).withGlobalOfficeNum("n/a001").build();
    holidays = new HashSet<HolidayBO>();
    holidays.add((HolidayBO) new HolidayBuilder().withName("N/A").from(yesterday.minusWeeks(3)).to(yesterday.plusWeeks(4)).build());
    anotherOffice.setHolidays(holidays);
    IntegrationTestObjectMother.createOffice(anotherOffice);
    List<Holiday> myHolidays = holidayDao.findCurrentAndFutureOfficeHolidaysEarliestFirst(myOffice.getOfficeId());
    assertThat(myHolidays.size(), is(5));
    assertThat(myHolidays.get(0).getName(), is("First"));
    assertThat(myHolidays.get(1).getName(), is("Second"));
    assertThat(myHolidays.get(2).getName(), is("Third"));
    assertThat(myHolidays.get(3).getName(), is("Fourth"));
    assertThat(myHolidays.get(4).getName(), is("Fifth"));
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) OfficeBO(org.mifos.customers.office.business.OfficeBO) Holiday(org.mifos.application.holiday.business.Holiday) HolidayBO(org.mifos.application.holiday.business.HolidayBO) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 22 with OfficeBuilder

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

the class GroupUpdateTest method validatesNameOfGroupIsNotTakenWhenNameIsUpdatedToDifferentValue.

@Test
public void validatesNameOfGroupIsNotTakenWhenNameIsUpdatedToDifferentValue() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    GroupUpdate groupUpdate = new GroupUpdateBuilder().build();
    // stubbing
    when(customerDao.findGroupBySystemId(groupUpdate.getGlobalCustNum())).thenReturn(mockedGroup);
    when(mockedGroup.isNameDifferent(groupUpdate.getDisplayName())).thenReturn(true);
    when(mockedGroup.getOffice()).thenReturn(new OfficeBuilder().build());
    // exercise test
    customerService.updateGroup(userContext, groupUpdate);
    // verification
    verify(mockedGroup).setDisplayName(groupUpdate.getDisplayName());
    verify(customerDao).validateGroupNameIsNotTakenForOffice(anyString(), anyShort());
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) GroupUpdateBuilder(org.mifos.domain.builders.GroupUpdateBuilder) UserContext(org.mifos.security.util.UserContext) GroupUpdate(org.mifos.dto.domain.GroupUpdate) Test(org.junit.Test)

Example 23 with OfficeBuilder

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

the class GroupValidationTest method givenGroupWithNullMeetingShouldThrowBusinessRuleException.

@Test(expected = BusinessRuleException.class)
public void givenGroupWithNullMeetingShouldThrowBusinessRuleException() {
    OfficeBO office = new OfficeBuilder().build();
    PersonnelBO loanOfficer = new PersonnelBuilder().asLoanOfficer().build();
    group = new GroupBuilder().withName("group-On-branch").withOffice(office).withLoanOfficer(loanOfficer).withMeeting(null).buildAsTopOfHierarchy();
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) GroupBuilder(org.mifos.domain.builders.GroupBuilder) Test(org.junit.Test)

Example 24 with OfficeBuilder

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

the class GroupValidationTest method givenGroupWithNullParentShouldThrowIllegalArgumentException.

@Test(expected = IllegalArgumentException.class)
public void givenGroupWithNullParentShouldThrowIllegalArgumentException() {
    OfficeBO office = new OfficeBuilder().build();
    PersonnelBO loanOfficer = new PersonnelBuilder().asLoanOfficer().build();
    MeetingBO meeting = new MeetingBuilder().customerMeeting().build();
    group = new GroupBuilder().withName("group-On-center").withOffice(office).withLoanOfficer(loanOfficer).withMeeting(meeting).withParentCustomer(null).build();
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) MeetingBO(org.mifos.application.meeting.business.MeetingBO) GroupBuilder(org.mifos.domain.builders.GroupBuilder) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) Test(org.junit.Test)

Example 25 with OfficeBuilder

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

the class GroupValidationTest method loanOfficerMustBeAssigned.

@Test
public void loanOfficerMustBeAssigned() {
    OfficeBO office = new OfficeBuilder().build();
    group = new GroupBuilder().withName("group-On-branch").withOffice(office).withLoanOfficer(null).buildAsTopOfHierarchy();
    try {
        group.validate();
        fail("should throw customer exception as loan officer must exist when creating group under a branch.");
    } catch (CustomerException e) {
        assertThat(e.getKey(), is(CustomerConstants.ERRORS_SELECT_LOAN_OFFICER));
    }
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) CustomerException(org.mifos.customers.exceptions.CustomerException) OfficeBO(org.mifos.customers.office.business.OfficeBO) GroupBuilder(org.mifos.domain.builders.GroupBuilder) Test(org.junit.Test)

Aggregations

OfficeBuilder (org.mifos.domain.builders.OfficeBuilder)33 OfficeBO (org.mifos.customers.office.business.OfficeBO)23 Test (org.junit.Test)22 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)12 UserContext (org.mifos.security.util.UserContext)11 GroupBO (org.mifos.customers.group.business.GroupBO)9 GroupBuilder (org.mifos.domain.builders.GroupBuilder)9 CustomerException (org.mifos.customers.exceptions.CustomerException)7 PersonnelBuilder (org.mifos.domain.builders.PersonnelBuilder)7 CenterBuilder (org.mifos.domain.builders.CenterBuilder)6 MeetingBO (org.mifos.application.meeting.business.MeetingBO)5 CenterBO (org.mifos.customers.center.business.CenterBO)5 ClientBO (org.mifos.customers.client.business.ClientBO)4 ClientBuilder (org.mifos.domain.builders.ClientBuilder)4 GroupUpdateBuilder (org.mifos.domain.builders.GroupUpdateBuilder)4 GroupUpdate (org.mifos.dto.domain.GroupUpdate)4 DateTime (org.joda.time.DateTime)3 MeetingBuilder (org.mifos.domain.builders.MeetingBuilder)3 DateMidnight (org.joda.time.DateMidnight)2 Before (org.junit.Before)2