Search in sources :

Example 71 with Filter

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

the class FilterBeanTest method testSetSelectedProjects_FilterHasFilledProjectList_EmployeeIsExec.

@Test
public void testSetSelectedProjects_FilterHasFilledProjectList_EmployeeIsExec() throws NoSuchFieldException {
    Project project1 = createProject(1L, null, "project1");
    Project project11 = createProject(2L, project1, "project11");
    Project project12 = createProject(3L, project1, "project12");
    Project project2 = createProject(5L, null, "project2");
    List<Project> selectedProjects = Arrays.asList(project11, project12, project2);
    List<Project> projects = Arrays.asList(project1, project2);
    Filter filter = new Filter();
    setField(filterBean, "currentFilter", filter);
    expect(externalContext.isUserInRole("exec")).andReturn(true);
    expect(projectService.getRootProjects(selectedProjects)).andReturn(projects).anyTimes();
    expect(projectService.getSubprojectsByProjects(projects)).andReturn(projects).anyTimes();
    replay(externalContext, projectService);
    filterBean.setSelectedProjects(selectedProjects);
    verify(externalContext, projectService);
    assertSame(projects, filter.getProjects());
}
Also used : Project(com.artezio.arttime.datamodel.Project) Filter(com.artezio.arttime.filter.Filter) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 72 with Filter

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

the class FilterBeanTest method testSave.

@Test
public void testSave() throws NoSuchFieldException {
    String newFilterName = "newFilterName";
    Filter currentFilter = new Filter("filterName", "user", false);
    Filter newFilter = new Filter(currentFilter);
    newFilter.setName(newFilterName);
    filterBean = createMockBuilder(FilterBean.class).addMockedMethod("setCurrentFilter", Filter.class).createMock();
    setField(filterBean, "newFilterName", newFilterName);
    setField(filterBean, "currentFilter", currentFilter);
    setField(filterBean, "filterService", filterService);
    expect(filterService.save(newFilter)).andReturn(newFilter);
    filterBean.setCurrentFilter(newFilter);
    replay(filterService, filterBean);
    filterBean.save();
    verify(filterService, filterBean);
}
Also used : Filter(com.artezio.arttime.filter.Filter) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 73 with Filter

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

the class FilterBeanTest method testSetSelectedProjects_FilterHasNullProjectList_EmployeeIsExec.

/*
      * The filter has null project list when it is formed on the client side and there are not selected projects
    */
@Test
public void testSetSelectedProjects_FilterHasNullProjectList_EmployeeIsExec() throws NoSuchFieldException {
    List<Project> expected = new ArrayList<>();
    Filter filter = new Filter();
    setField(filterBean, "currentFilter", filter);
    expect(projectService.getSubprojectsByProjects(expected)).andReturn(expected).anyTimes();
    replay(externalContext, projectService);
    filterBean.setSelectedProjects(null);
    verify(externalContext, projectService);
    assertTrue(filter.getProjects().isEmpty());
}
Also used : Project(com.artezio.arttime.datamodel.Project) Filter(com.artezio.arttime.filter.Filter) ArrayList(java.util.ArrayList) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 74 with Filter

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

the class FilterBeanTest method testSetSelectedProjects_FilterHasEmptyProjectList_EmployeeIsExec.

/*
     * The filter has empty project list when it is formed on a server
     */
@Test
public void testSetSelectedProjects_FilterHasEmptyProjectList_EmployeeIsExec() throws NoSuchFieldException {
    List<Project> emptyProjectList = new ArrayList<>();
    Filter filter = new Filter();
    setField(filterBean, "currentFilter", filter);
    expect(projectService.getSubprojectsByProjects(emptyProjectList)).andReturn(emptyProjectList).anyTimes();
    replay(externalContext, projectService);
    filterBean.setSelectedProjects(emptyProjectList);
    verify(externalContext, projectService);
    assertTrue(filter.getProjects().isEmpty());
}
Also used : Project(com.artezio.arttime.datamodel.Project) Filter(com.artezio.arttime.filter.Filter) ArrayList(java.util.ArrayList) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 75 with Filter

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

the class FilterBeanTest method testSetSelectedProjects_FilterHasNullProjectList_EmployeeIsPM.

@Test
public void testSetSelectedProjects_FilterHasNullProjectList_EmployeeIsPM() throws NoSuchFieldException {
    Filter filter = new Filter();
    setField(filterBean, "currentFilter", filter);
    expect(projectService.getSubprojectsByProjects(Collections.emptyList())).andReturn(Collections.emptyList()).anyTimes();
    replay(externalContext, projectService);
    filterBean.setSelectedProjects(null);
    verify(externalContext, projectService);
    assertEquals(Collections.emptyList(), filter.getProjects());
}
Also used : Filter(com.artezio.arttime.filter.Filter) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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