Search in sources :

Example 6 with RangePeriodSelector

use of com.artezio.arttime.web.criteria.RangePeriodSelector in project ART-TIME by Artezio.

the class IntegrationFacadeTest method testGetHours_emptyProjectsList_expectAllProjects.

@Test
public void testGetHours_emptyProjectsList_expectAllProjects() {
    List<Hours> expectedHours = new ArrayList<>();
    HourType type = new HourType("Type");
    Project project = new Project();
    project.setCode("TEST-PROJECT");
    Project subproject = new Project(project);
    subproject.setCode("TEST_SUBPROJECT");
    Project subproject2 = new Project(project);
    subproject2.setCode("TEST_SUBPROJECT_2");
    Employee employee = new Employee("employee");
    Date from = new GregorianCalendar(2011, 1, 5).getTime();
    Date to = new GregorianCalendar(2011, 1, 15).getTime();
    Period period = new Period(from, to);
    List<Project> allProjects = asList(project, subproject, subproject2);
    Filter filter = new Filter();
    filter.setProjects(allProjects);
    filter.setApproved(null);
    Hours h1 = new Hours(project, from, employee, type);
    Hours h2 = new Hours(subproject, from, employee, type);
    Hours h3 = new Hours(subproject2, from, employee, type);
    expectedHours.add(h1);
    expectedHours.add(h2);
    expectedHours.add(h3);
    RangePeriodSelector rangePeriodSelector = new RangePeriodSelector(period);
    filter.setRangePeriodSelector(rangePeriodSelector);
    HoursSearchCriteria criteria = new HoursSearchCriteria(from, to, false, Collections.emptyList());
    criteria.setIncludeSubprojects(true);
    Project anotherProject = new Project();
    Project anotherSubproject = new Project();
    anotherProject.setCode("ANOTHER-PROJECT");
    anotherSubproject.setCode("ANOTHER-SUBPROJECT");
    List<Project> allStoredProjects = Arrays.asList(project, subproject, subproject2, anotherProject, anotherSubproject);
    expect(projectService.getAll()).andReturn(allStoredProjects).anyTimes();
    EasyMock.expect(hoursService.getHours(filter)).andReturn(expectedHours);
    EasyMock.replay(projectService, hoursService);
    List<Hours> actualHours = facade.getHours(criteria);
    EasyMock.verify(projectService, hoursService);
    assertSame(expectedHours, actualHours);
}
Also used : RangePeriodSelector(com.artezio.arttime.web.criteria.RangePeriodSelector) Filter(com.artezio.arttime.filter.Filter) Test(org.junit.Test)

Example 7 with RangePeriodSelector

use of com.artezio.arttime.web.criteria.RangePeriodSelector in project ART-TIME by Artezio.

the class IntegrationFacadeTest method testGetHours_approvedOnly.

@Test
public void testGetHours_approvedOnly() {
    List<Hours> expecteds = new ArrayList<>();
    Project project = new Project();
    project.setCode("TEST-PROJECT");
    Date from = new GregorianCalendar(2011, 1, 5).getTime();
    Date to = new GregorianCalendar(2011, 1, 15).getTime();
    Period period = new Period(from, to);
    Filter expectedFilter = new Filter();
    expectedFilter.setProjects(asList(project));
    expectedFilter.setApproved(Boolean.TRUE);
    RangePeriodSelector rangePeriodSelector = new RangePeriodSelector(period);
    expectedFilter.setRangePeriodSelector(rangePeriodSelector);
    HoursSearchCriteria criteria = new HoursSearchCriteria(from, to, true, asList("TEST-PROJECT"));
    Project anotherProject = new Project();
    Project anotherSubproject = new Project();
    anotherProject.setCode("ANOTHER-PROJECT");
    anotherSubproject.setCode("ANOTHER-SUBPROJECT");
    List<Project> allProjects = Arrays.asList(project, anotherProject, anotherSubproject);
    expect(projectService.getAll()).andReturn(allProjects).anyTimes();
    expect(hoursService.getHours(eq(expectedFilter))).andReturn(expecteds);
    replay(projectService, hoursRepository, hoursService);
    List<Hours> actuals = facade.getHours(criteria);
    verify(projectService, hoursRepository);
    assertSame(expecteds, actuals);
}
Also used : Filter(com.artezio.arttime.filter.Filter) RangePeriodSelector(com.artezio.arttime.web.criteria.RangePeriodSelector) Test(org.junit.Test)

Example 8 with RangePeriodSelector

use of com.artezio.arttime.web.criteria.RangePeriodSelector in project ART-TIME by Artezio.

the class IntegrationFacadeTest method testGetHours.

@Test
public void testGetHours() {
    List<Hours> expecteds = new ArrayList<>();
    Project project = new Project();
    project.setCode("TEST-PROJECT");
    Date from = new GregorianCalendar(2011, 1, 5).getTime();
    Date to = new GregorianCalendar(2011, 1, 15).getTime();
    Period period = new Period(from, to);
    Filter expectedFilter = new Filter();
    expectedFilter.setProjects(asList(project));
    expectedFilter.setApproved(null);
    RangePeriodSelector rangePeriodSelector = new RangePeriodSelector(period);
    expectedFilter.setRangePeriodSelector(rangePeriodSelector);
    HoursSearchCriteria hoursSearchCriteria = new HoursSearchCriteria(from, to, true, asList("TEST-PROJECT"));
    Project anotherProject = new Project();
    anotherProject.setCode("OtherProject");
    List<Project> allProjects = Arrays.asList(project, anotherProject);
    expect(projectService.getAll()).andReturn(allProjects).anyTimes();
    EasyMock.expect(hoursService.getHours(expectedFilter)).andReturn(expecteds);
    EasyMock.replay(projectService, hoursService);
    List<Hours> actuals = facade.getHours(hoursSearchCriteria);
    verify(projectService, hoursService);
    assertSame(expecteds, actuals);
}
Also used : Filter(com.artezio.arttime.filter.Filter) RangePeriodSelector(com.artezio.arttime.web.criteria.RangePeriodSelector) Test(org.junit.Test)

Example 9 with RangePeriodSelector

use of com.artezio.arttime.web.criteria.RangePeriodSelector in project ART-TIME by Artezio.

the class HoursRepositoryTest method testGetHours_FilterHasProjectsAndHasNoHourTypes.

@Test
public void testGetHours_FilterHasProjectsAndHasNoHourTypes() {
    HourType hourType = new HourType("1");
    List<HourType> hourTypes = Collections.singletonList(hourType);
    Project project = new Project();
    project.setAccountableHours(hourTypes);
    Hours hour = new Hours(project, new Date(), null, hourType);
    entityManager.persist(hourType);
    entityManager.persist(project);
    entityManager.persist(hour);
    RangePeriodSelector rangePeriodSelector = new RangePeriodSelector(createPeriod(-1, 1));
    Filter filter = new Filter();
    filter.setRangePeriodSelector(rangePeriodSelector);
    filter.setHourTypes(Collections.emptyList());
    filter.setProjects(Collections.singletonList(project));
    List<Hours> actual = hoursRepository.getHours(filter);
    List<Hours> expected = Collections.singletonList(hour);
    assertEquals(expected, actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) HourType(com.artezio.arttime.datamodel.HourType) Hours(com.artezio.arttime.datamodel.Hours) Filter(com.artezio.arttime.filter.Filter) RangePeriodSelector(com.artezio.arttime.web.criteria.RangePeriodSelector) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 10 with RangePeriodSelector

use of com.artezio.arttime.web.criteria.RangePeriodSelector in project ART-TIME by Artezio.

the class HoursRepositoryTest method testGetHours_FilterHasNoProjectsAndHourTypes.

@Test
public void testGetHours_FilterHasNoProjectsAndHourTypes() {
    Project project = new Project();
    Hours hour = new Hours();
    hour.setProject(project);
    hour.setDate(new Date());
    entityManager.persist(project);
    entityManager.persist(hour);
    RangePeriodSelector rangePeriodSelector = new RangePeriodSelector(createPeriod(-1, 1));
    Filter filter = new Filter();
    filter.setRangePeriodSelector(rangePeriodSelector);
    filter.setHourTypes(Collections.emptyList());
    filter.setProjects(Collections.emptyList());
    List<Hours> actual = hoursRepository.getHours(filter);
    List<Hours> expected = Collections.singletonList(hour);
    assertEquals(expected, actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Hours(com.artezio.arttime.datamodel.Hours) Filter(com.artezio.arttime.filter.Filter) RangePeriodSelector(com.artezio.arttime.web.criteria.RangePeriodSelector) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Aggregations

RangePeriodSelector (com.artezio.arttime.web.criteria.RangePeriodSelector)19 Filter (com.artezio.arttime.filter.Filter)16 Test (org.junit.Test)14 Hours (com.artezio.arttime.datamodel.Hours)5 Project (com.artezio.arttime.datamodel.Project)5 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)5 Date (java.util.Date)5 HourType (com.artezio.arttime.datamodel.HourType)4 Employee (com.artezio.arttime.datamodel.Employee)2 Period (com.artezio.arttime.datamodel.Period)2 Date (java.sql.Date)2 HoursRepository (com.artezio.arttime.repositories.HoursRepository)1 Before (org.junit.Before)1