Search in sources :

Example 86 with Filter

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

the class FilterServiceTest method testSave_EquivalentExists.

@Test
public void testSave_EquivalentExists() throws NoSuchFieldException {
    setField(filterService, "filterRepository", filterRepository);
    Filter filter = new Filter("filter", "user", false);
    FilterRepository.FilterQuery filterQuery = Mockito.mock(FilterRepository.FilterQuery.class, RETURNS_DEEP_STUBS);
    EasyMock.expect(filterRepository.query()).andReturn(filterQuery);
    Mockito.when(filterQuery.name(filter.getName()).fetchProjects().fetchDepartments().fetchEmployees().fetchHourTypes().getSingleResultOrNull()).thenReturn(filter);
    EasyMock.expect(filterRepository.update(filter)).andReturn(filter);
    EasyMock.replay(filterRepository);
    Filter actual = filterService.save(filter);
    EasyMock.verify(filterRepository);
    Mockito.verify(filterQuery.name(filter.getName()).fetchProjects().fetchDepartments().fetchEmployees().fetchHourTypes()).getSingleResultOrNull();
    assertEquals(filter, actual);
}
Also used : Filter(com.artezio.arttime.filter.Filter) Test(org.junit.Test)

Example 87 with Filter

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

the class FilterServiceTest method testSave_EquivalentNotExists.

@Test
public void testSave_EquivalentNotExists() throws NoSuchFieldException {
    setField(filterService, "filterRepository", filterRepository);
    Filter filter = new Filter("filter", "user", false);
    FilterRepository.FilterQuery filterQuery = Mockito.mock(FilterRepository.FilterQuery.class, RETURNS_DEEP_STUBS);
    EasyMock.expect(filterRepository.query()).andReturn(filterQuery);
    Mockito.when(filterQuery.name(filter.getName()).fetchProjects().fetchDepartments().fetchEmployees().fetchHourTypes().getSingleResultOrNull()).thenReturn(null);
    EasyMock.expect(filterRepository.create(filter)).andReturn(filter);
    EasyMock.replay(filterRepository);
    Filter actual = filterService.save(filter);
    EasyMock.verify(filterRepository);
    Mockito.verify(filterQuery.name(filter.getName()).fetchProjects().fetchDepartments().fetchEmployees().fetchHourTypes()).getSingleResultOrNull();
    assertEquals(filter, actual);
}
Also used : Filter(com.artezio.arttime.filter.Filter) Test(org.junit.Test)

Example 88 with Filter

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

the class FilterServiceTest method testSave_ifPredefined.

@Test
public void testSave_ifPredefined() throws NoSuchFieldException {
    setField(filterService, "filterRepository", filterRepository);
    Filter filter = new Filter("filter", "user", true);
    setField(filter, "id", 1L);
    Filter expected = new Filter("filter", "user", true);
    setField(expected, "id", 2L);
    FilterRepository.FilterQuery filterQuery = Mockito.mock(FilterRepository.FilterQuery.class, RETURNS_DEEP_STUBS);
    EasyMock.expect(filterRepository.query()).andReturn(filterQuery);
    Mockito.when(filterQuery.name(filter.getName()).fetchProjects().fetchDepartments().fetchEmployees().fetchHourTypes().getSingleResultOrNull()).thenReturn(filter);
    EasyMock.expect(filterRepository.create(expected)).andReturn(expected);
    EasyMock.replay(filterRepository);
    Filter actual = filterService.save(expected);
    EasyMock.verify(filterRepository);
    Mockito.verify(filterQuery.name(filter.getName()).fetchProjects().fetchDepartments().fetchEmployees().fetchHourTypes()).getSingleResultOrNull();
    assertEquals(expected, actual);
    assertNotEquals(filter, actual);
}
Also used : Filter(com.artezio.arttime.filter.Filter) Test(org.junit.Test)

Example 89 with Filter

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

the class IntegrationFacadeTest method testGetHours_includeSubprojects_ExpectDistinct.

@Test
public void testGetHours_includeSubprojects_ExpectDistinct() {
    List<Hours> expecteds = 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);
    expecteds.add(h1);
    expecteds.add(h2);
    expecteds.add(h3);
    RangePeriodSelector rangePeriodSelector = new RangePeriodSelector(period);
    filter.setRangePeriodSelector(rangePeriodSelector);
    HoursSearchCriteria criteria = new HoursSearchCriteria(from, to, false, asList("TEST-PROJECT", "TEST_SUBPROJECT"));
    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(expecteds);
    EasyMock.replay(projectService, hoursService);
    List<Hours> actuals = facade.getHours(criteria);
    EasyMock.verify(projectService, hoursService);
    assertSame(expecteds, actuals);
}
Also used : RangePeriodSelector(com.artezio.arttime.web.criteria.RangePeriodSelector) Filter(com.artezio.arttime.filter.Filter) Test(org.junit.Test)

Example 90 with Filter

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

the class EffortsBeanTest method testInitByGetRequest_ifEmployeesIsEmpty.

@Test
public void testInitByGetRequest_ifEmployeesIsEmpty() throws Exception {
    Filter filter = new Filter();
    List<Employee> employees = Collections.emptyList();
    FilterBean filterBean = createMock(FilterBean.class);
    Period period = new Period(sdf.parse("1-01-2015"), sdf.parse("15-01-2015"));
    setField(effortsBean, "filterBean", filterBean);
    setField(effortsBean, "period", period);
    setField(effortsBean, "employees", employees);
    expect(filterBean.getCurrentFilter()).andReturn(filter);
    replay(filterBean);
    effortsBean.initByGetRequest();
    verify(filterBean);
    assertEquals(period, filter.getPeriod());
    assertEquals(employees, filter.getEmployees());
}
Also used : Filter(com.artezio.arttime.filter.Filter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) 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