Search in sources :

Example 96 with Project

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);
}
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 97 with Project

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);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) Hours(com.artezio.arttime.datamodel.Hours) Period(com.artezio.arttime.datamodel.Period) CalendarUtils.createPeriod(com.artezio.arttime.test.utils.CalendarUtils.createPeriod) HoursRepository(com.artezio.arttime.repositories.HoursRepository) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 98 with Project

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);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) Hours(com.artezio.arttime.datamodel.Hours) Period(com.artezio.arttime.datamodel.Period) CalendarUtils.createPeriod(com.artezio.arttime.test.utils.CalendarUtils.createPeriod) HoursRepository(com.artezio.arttime.repositories.HoursRepository) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 99 with Project

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);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) Hours(com.artezio.arttime.datamodel.Hours) Test(org.junit.Test)

Example 100 with Project

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);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) Hours(com.artezio.arttime.datamodel.Hours) Period(com.artezio.arttime.datamodel.Period) CalendarUtils.createPeriod(com.artezio.arttime.test.utils.CalendarUtils.createPeriod) HoursRepository(com.artezio.arttime.repositories.HoursRepository) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Aggregations

Project (com.artezio.arttime.datamodel.Project)310 Test (org.junit.Test)278 Employee (com.artezio.arttime.datamodel.Employee)195 HourType (com.artezio.arttime.datamodel.HourType)119 Hours (com.artezio.arttime.datamodel.Hours)108 Date (java.util.Date)61 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)56 Period (com.artezio.arttime.datamodel.Period)43 BigDecimal (java.math.BigDecimal)39 Filter (com.artezio.arttime.filter.Filter)33 TeamFilter (com.artezio.arttime.datamodel.TeamFilter)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)25 CalendarUtils.createPeriod (com.artezio.arttime.test.utils.CalendarUtils.createPeriod)21 ArrayList (java.util.ArrayList)18 Arrays.asList (java.util.Arrays.asList)18 ProjectRepository (com.artezio.arttime.repositories.ProjectRepository)17 List (java.util.List)17 HoursRepository (com.artezio.arttime.repositories.HoursRepository)13 HashMap (java.util.HashMap)13 Map (java.util.Map)11