use of com.artezio.arttime.datamodel.Project 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);
}
use of com.artezio.arttime.datamodel.Project in project ART-TIME by Artezio.
the class HoursServiceTest method testReportHours_HoursNotExistWhenSaving.
@Test
public void testReportHours_HoursNotExistWhenSaving() throws Exception {
Employee employee = new Employee();
Project project = new Project();
HourType hourType = new HourType();
Date date = new Date();
Hours hours = createHours(1L, project, date, employee, hourType, true);
List<Hours> persistedHours = emptyList();
HoursRepository.HoursQuery query = Mockito.mock(HoursRepository.HoursQuery.class, Mockito.RETURNS_DEEP_STUBS);
EasyMock.expect(hoursRepository.query()).andReturn(query).anyTimes();
Mockito.when(query.projects(singleton(project)).period(new Period(date, date)).employees(singleton(employee)).uncached().list()).thenReturn(persistedHours);
hoursRepository.lock(employee);
EasyMock.expectLastCall();
EasyMock.expect(hoursRepository.create(hours)).andReturn(hours);
EasyMock.replay(sessionContext, hoursRepository);
hoursService.reportHours(asList(hours));
EasyMock.verify(sessionContext, hoursRepository);
}
use of com.artezio.arttime.datamodel.Project in project ART-TIME by Artezio.
the class HoursServiceTest method testManageHours_HoursWithoutAnyValues.
@Test
public void testManageHours_HoursWithoutAnyValues() throws Exception {
Employee employee = new Employee();
Project project = new Project();
HourType hourType = new HourType();
Date date = new Date();
Hours hours = createHours(1L, project, date, employee, hourType, false);
Hours persistedHours = createHours(2L, project, date, employee, hourType, true);
List<Hours> hoursList = asList(hours);
List<Hours> persistedHoursList = asList(persistedHours);
HoursRepository.HoursQuery query = Mockito.mock(HoursRepository.HoursQuery.class, Mockito.RETURNS_DEEP_STUBS);
EasyMock.expect(hoursRepository.query()).andReturn(query).anyTimes();
Mockito.when(query.projects(singleton(project)).period(new Period(date, date)).employees(singleton(employee)).uncached().list()).thenReturn(persistedHoursList);
hoursRepository.lock(employee);
hoursRepository.remove(hours);
EasyMock.replay(hoursRepository);
hoursService.manageHours(hoursList);
EasyMock.verifyUnexpectedCalls(hoursRepository);
}
use of com.artezio.arttime.datamodel.Project in project ART-TIME by Artezio.
the class HoursServiceTest method testExistApprovedHours_DifferentDates.
@Test
public void testExistApprovedHours_DifferentDates() throws NoSuchFieldException {
Employee employee = new Employee("employee");
Project project = new Project();
setField(project, "id", 1L);
HourType hourType = new HourType("regular");
Hours persisted = new Hours(project, getOffsetDate(0), employee, hourType);
persisted.setApproved(true);
Hours newHour1 = new Hours(project, getOffsetDate(-1), employee, hourType);
Hours newHour2 = new Hours(project, getOffsetDate(1), employee, hourType);
hoursService = new HoursService();
boolean actual = hoursService.existApprovedHours(asList(newHour1, newHour2), asList(persisted));
assertFalse(actual);
}
use of com.artezio.arttime.datamodel.Project in project ART-TIME by Artezio.
the class HoursServiceTest method testManageHours_HoursNotExistWhenSaving.
@Test
public void testManageHours_HoursNotExistWhenSaving() throws Exception {
Employee employee = new Employee();
Project project = new Project();
HourType hourType = new HourType();
Date date = new Date();
Hours hours = createHours(1L, project, date, employee, hourType, true);
List<Hours> persistedHours = emptyList();
HoursRepository.HoursQuery query = Mockito.mock(HoursRepository.HoursQuery.class, Mockito.RETURNS_DEEP_STUBS);
EasyMock.expect(hoursRepository.query()).andReturn(query).anyTimes();
Mockito.when(query.projects(singleton(project)).period(new Period(date, date)).employees(singleton(employee)).uncached().list()).thenReturn(persistedHours);
hoursRepository.lock(employee);
EasyMock.expectLastCall();
EasyMock.expect(hoursRepository.create(hours)).andReturn(hours);
EasyMock.replay(hoursRepository);
hoursService.manageHours(asList(hours));
EasyMock.verify(hoursRepository);
}
Aggregations