Search in sources :

Example 31 with Filter

use of com.artezio.arttime.filter.Filter in project ART-TIME by Artezio.

the class FilterServiceTest method testGetActiveProjectsFilter.

@Test
public void testGetActiveProjectsFilter() {
    String loggedUserName = "username";
    Project activeProject = new Project();
    activeProject.setStatus(Project.Status.ACTIVE);
    Project closedProject = new Project();
    closedProject.setStatus(Project.Status.CLOSED);
    List<Project> projects = asList(activeProject, closedProject);
    ProjectRepository.ProjectQuery projectQuery = Mockito.mock(ProjectRepository.ProjectQuery.class, RETURNS_DEEP_STUBS);
    EasyMock.expect(principal.getName()).andReturn(loggedUserName).anyTimes();
    EasyMock.expect(projectRepository.query()).andReturn(projectQuery);
    Mockito.when(projectQuery.managedBy(loggedUserName).status(ACTIVE).list()).thenReturn(projects);
    EasyMock.replay(projectRepository, principal);
    Filter expected = new Filter(MY_ACTIVE_PROJECTS_FILTER_NAME, loggedUserName, true, projects);
    Filter actual = filterService.getActiveProjectsFilter();
    EasyMock.verify(projectRepository, principal);
    Mockito.verify(projectQuery.managedBy(loggedUserName).status(ACTIVE)).list();
    assertEquals(expected, actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Filter(com.artezio.arttime.filter.Filter) Test(org.junit.Test)

Example 32 with Filter

use of com.artezio.arttime.filter.Filter in project ART-TIME by Artezio.

the class FilterServiceTest method testGetTimesheetFilter.

@Test
public void testGetTimesheetFilter() {
    String loggedUserName = "username";
    Period period = new Period(CalendarUtils.currentWeekStartDate(), CalendarUtils.currentWeekEndDate());
    List<Project> activeProjects = asList(new Project());
    List<Project> reportedProjects = asList(new Project());
    List<String> departments = asList("dep1");
    List<HourType> hourTypes = asList(new HourType("hourType1"), new HourType("hourType2"));
    List<Employee> employees = asList(new Employee(loggedUserName));
    Employee loggedEmployee = new Employee(loggedUserName);
    ProjectRepository.ProjectQuery projectQuery = Mockito.mock(ProjectRepository.ProjectQuery.class, RETURNS_DEEP_STUBS);
    EmployeeRepository.EmployeeQuery employeeQuery = Mockito.mock(EmployeeRepository.EmployeeQuery.class, RETURNS_DEEP_STUBS);
    EasyMock.expect(sessionContext.getCallerPrincipal()).andReturn(principal);
    EasyMock.expect(projectRepository.query()).andReturn(projectQuery).anyTimes();
    EasyMock.expect(employeeService.getLoggedEmployee()).andReturn(Optional.of(loggedEmployee));
    EasyMock.expect(hourTypeService.getAll()).andReturn(hourTypes);
    EasyMock.expect(departmentRepository.getDepartments()).andReturn(departments);
    EasyMock.expect(principal.getName()).andReturn(loggedUserName).anyTimes();
    Mockito.when(employeeQuery.userName(loggedUserName).getSingleResult()).thenReturn(loggedEmployee);
    Mockito.when(projectQuery.teamMember(loggedUserName).status(ACTIVE).withoutMasterOrWithMasterStatus(ACTIVE).list()).thenReturn(activeProjects);
    Mockito.when(projectQuery.withHoursFor(loggedUserName).withHoursFrom(period.getStart()).withHoursTill(period.getFinish()).distinct().list()).thenReturn(reportedProjects);
    EasyMock.replay(projectRepository, employeeService, hourTypeService, departmentRepository, principal);
    Filter expected = new Filter();
    expected.setEmployees(singletonList(loggedEmployee));
    expected.setProjects(activeProjects);
    expected.setDepartments(departments);
    expected.setHourTypes(hourTypes);
    expected.setEmployees(employees);
    Filter actual = filterService.getTimesheetFilter();
    EasyMock.verify(projectRepository, employeeService, hourTypeService, departmentRepository, principal);
    assertEquals(expected, actual);
}
Also used : HourType(com.artezio.arttime.datamodel.HourType) Period(com.artezio.arttime.datamodel.Period) Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) Filter(com.artezio.arttime.filter.Filter) Test(org.junit.Test)

Example 33 with Filter

use of com.artezio.arttime.filter.Filter in project ART-TIME by Artezio.

the class IntegrationFacadeTest method testGetHours_includeSubprojects.

@Test
public void testGetHours_includeSubprojects() {
    List<Hours> expecteds = new ArrayList<>();
    Project project = new Project();
    project.setCode("TEST-PROJECT");
    Project subproject = new Project(project);
    subproject.setCode("TEST_SUBPROJECT");
    Date from = new GregorianCalendar(2011, 1, 5).getTime();
    Date to = new GregorianCalendar(2011, 1, 15).getTime();
    Period period = new Period(from, to);
    List<Project> projects = asList(project, subproject);
    Filter filter = new Filter();
    filter.setProjects(projects);
    filter.setApproved(null);
    RangePeriodSelector rangePeriodSelector = new RangePeriodSelector(period);
    filter.setRangePeriodSelector(rangePeriodSelector);
    HoursSearchCriteria criteria = new HoursSearchCriteria(from, to, false, asList("TEST-PROJECT"));
    criteria.setIncludeSubprojects(true);
    Project anotherProject = new Project();
    Project anotherSubproject = new Project();
    anotherProject.setCode("ANOTHER-PROJECT");
    anotherSubproject.setCode("ANOTHER-SUBPROJECT");
    List<Project> allProjects = Arrays.asList(project, subproject, anotherProject, anotherSubproject);
    expect(projectService.getAll()).andReturn(allProjects).anyTimes();
    expect(hoursService.getHours(eq(filter))).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 34 with Filter

use of com.artezio.arttime.filter.Filter 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 35 with Filter

use of com.artezio.arttime.filter.Filter 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)

Aggregations

Filter (com.artezio.arttime.filter.Filter)126 Test (org.junit.Test)110 Project (com.artezio.arttime.datamodel.Project)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)25 Employee (com.artezio.arttime.datamodel.Employee)24 RangePeriodSelector (com.artezio.arttime.web.criteria.RangePeriodSelector)16 Date (java.util.Date)9 BigDecimal (java.math.BigDecimal)8 Hours (com.artezio.arttime.datamodel.Hours)7 Arrays.asList (java.util.Arrays.asList)7 List (java.util.List)7 HourType (com.artezio.arttime.datamodel.HourType)5 Efforts (com.artezio.arttime.services.WorkTimeService.Efforts)5 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)5 ArrayList (java.util.ArrayList)4 Collections.emptyList (java.util.Collections.emptyList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Period (com.artezio.arttime.datamodel.Period)3 EmployeeRepository (com.artezio.arttime.repositories.EmployeeRepository)3