Search in sources :

Example 51 with HourType

use of com.artezio.arttime.datamodel.HourType in project ART-TIME by Artezio.

the class HoursRepositoryTest method testGetManagersForApproveByEmployee_byEmployee.

@Test
public void testGetManagersForApproveByEmployee_byEmployee() {
    Date start = new Date();
    Date finish = getOffsetDate(3);
    Period period = new Period(start, finish);
    Employee manager1 = new Employee("manager1");
    Employee manager2 = new Employee("manager2");
    Project project1 = new Project();
    project1.setManagers(Arrays.asList(manager1));
    Project project2 = new Project();
    project2.setManagers(Arrays.asList(manager2));
    Employee employee1 = new Employee("employee1");
    Employee employee2 = new Employee("employee2");
    HourType actualType = new HourType("actual type");
    actualType.setActualTime(true);
    Hours hours1 = createHours(project1, employee1, getOffsetDate(2), actualType, new BigDecimal(8));
    Hours hours2 = createHours(project2, employee2, getOffsetDate(2), actualType, new BigDecimal(8));
    entityManager.persist(manager1);
    entityManager.persist(manager2);
    entityManager.persist(actualType);
    entityManager.persist(employee1);
    entityManager.persist(employee2);
    entityManager.persist(project1);
    entityManager.persist(project2);
    entityManager.persist(hours1);
    entityManager.persist(hours2);
    Map<Employee, List<Employee>> actual = hoursRepository.getManagersForApproveByEmployee(Arrays.asList(employee1), period);
    ListAssert.assertEquals(Arrays.asList(manager1), actual.get(employee1));
}
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) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 52 with HourType

use of com.artezio.arttime.datamodel.HourType 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 53 with HourType

use of com.artezio.arttime.datamodel.HourType in project ART-TIME by Artezio.

the class HourTypeServiceTest method testFind_HourTypeNotExists.

@Test
public void testFind_HourTypeNotExists() {
    HourTypeRepository.HourTypeQuery query = Mockito.mock(HourTypeRepository.HourTypeQuery.class, Mockito.RETURNS_DEEP_STUBS);
    EasyMock.expect(hourTypeRepository.query()).andReturn(query);
    Mockito.when(query.id(1L).getSingleResultOrNull()).thenReturn(null);
    EasyMock.replay(hourTypeRepository);
    HourType actual = hourTypeService.find(1L);
    EasyMock.verify(hourTypeRepository);
    Mockito.verify(query.id(1L)).getSingleResultOrNull();
    assertNull(actual);
}
Also used : HourType(com.artezio.arttime.datamodel.HourType) HourTypeRepository(com.artezio.arttime.repositories.HourTypeRepository) Test(org.junit.Test)

Example 54 with HourType

use of com.artezio.arttime.datamodel.HourType in project ART-TIME by Artezio.

the class HourTypeServiceTest method createHourType.

private HourType createHourType(Long id) {
    HourType hourType = new HourType();
    try {
        setField(hourType, "id", id);
    } catch (NoSuchFieldException e) {
        throw new RuntimeException("Error during creating test HourType", e);
    }
    hourType.setType(id.toString());
    return hourType;
}
Also used : HourType(com.artezio.arttime.datamodel.HourType)

Example 55 with HourType

use of com.artezio.arttime.datamodel.HourType in project ART-TIME by Artezio.

the class HourTypeServiceTest method testFind_HourTypeExists.

@Test
public void testFind_HourTypeExists() {
    HourType hourType = createHourType(1L);
    HourTypeRepository.HourTypeQuery query = Mockito.mock(HourTypeRepository.HourTypeQuery.class, Mockito.RETURNS_DEEP_STUBS);
    EasyMock.expect(hourTypeRepository.query()).andReturn(query);
    Mockito.when(query.id(1L).getSingleResultOrNull()).thenReturn(hourType);
    EasyMock.replay(hourTypeRepository);
    HourType actual = hourTypeService.find(1L);
    EasyMock.verify(hourTypeRepository);
    Mockito.verify(query.id(1L)).getSingleResultOrNull();
    assertEquals(hourType, actual);
}
Also used : HourType(com.artezio.arttime.datamodel.HourType) HourTypeRepository(com.artezio.arttime.repositories.HourTypeRepository) Test(org.junit.Test)

Aggregations

HourType (com.artezio.arttime.datamodel.HourType)172 Test (org.junit.Test)158 Project (com.artezio.arttime.datamodel.Project)120 Employee (com.artezio.arttime.datamodel.Employee)115 Hours (com.artezio.arttime.datamodel.Hours)103 Date (java.util.Date)60 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)54 Period (com.artezio.arttime.datamodel.Period)45 BigDecimal (java.math.BigDecimal)41 CalendarUtils.createPeriod (com.artezio.arttime.test.utils.CalendarUtils.createPeriod)21 HashMap (java.util.HashMap)16 HoursRepository (com.artezio.arttime.repositories.HoursRepository)13 Map (java.util.Map)11 Arrays.asList (java.util.Arrays.asList)10 List (java.util.List)10 Filter (com.artezio.arttime.filter.Filter)7 Mail (com.artezio.arttime.services.mailing.Mail)7 ArrayList (java.util.ArrayList)7 HourTypeRepository (com.artezio.arttime.repositories.HourTypeRepository)6 RangePeriodSelector (com.artezio.arttime.web.criteria.RangePeriodSelector)6