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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations