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