Search in sources :

Example 26 with WorkdaysCalendar

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

the class DepartmentServiceTest method testSetCalendar_departmentHadNoCalendar.

@Test
public void testSetCalendar_departmentHadNoCalendar() throws NoSuchFieldException {
    String department = "ExpectedDepartment";
    WorkdaysCalendar otherStoredCalendar = new WorkdaysCalendar("OtherStoredCalendar");
    setField(otherStoredCalendar, "id", 2L);
    WorkdaysCalendar newCalendar = new WorkdaysCalendar("NewCalendar");
    setField(newCalendar, "id", 3L);
    Set<String> newDepts = new HashSet<>();
    newDepts.add("SomeDepartment");
    newCalendar.setDepartments(newDepts);
    Employee employee1 = new Employee();
    Employee employee2 = new Employee();
    Employee employee3 = new Employee();
    employee3.setCalendar(otherStoredCalendar);
    List<Employee> employees = asList(employee1, employee2, employee3);
    EmployeeRepository.EmployeeQuery query = Mockito.mock(EmployeeRepository.EmployeeQuery.class, RETURNS_DEEP_STUBS);
    Mockito.when(query.department(department).list()).thenReturn(employees);
    EasyMock.expect(employeeRepository.query()).andReturn(query);
    EasyMock.expect(workdaysCalendarRepository.findByDepartment(department)).andReturn(null);
    EasyMock.expect(workdaysCalendarRepository.attachAndRefresh(newCalendar)).andReturn(newCalendar);
    EasyMock.replay(employeeRepository, workdaysCalendarRepository);
    departmentService.setCalendarToDepartment(department, newCalendar);
    EasyMock.verify(employeeRepository, workdaysCalendarRepository);
    assertTrue(newCalendar.getDepartments().contains(department));
    assertEquals(newCalendar, employee1.getCalendar());
    assertEquals(newCalendar, employee2.getCalendar());
    assertEquals(otherStoredCalendar, employee3.getCalendar());
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) EmployeeRepository(com.artezio.arttime.repositories.EmployeeRepository) Employee(com.artezio.arttime.datamodel.Employee) Test(org.junit.Test)

Example 27 with WorkdaysCalendar

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

the class DepartmentServiceTest method testSetCalendar_departmentHadCalendar.

@Test
public void testSetCalendar_departmentHadCalendar() throws NoSuchFieldException {
    String department = "ExpectedDepartment";
    WorkdaysCalendar storedCalendar = new WorkdaysCalendar("StoredCalendar");
    setField(storedCalendar, "id", 1L);
    WorkdaysCalendar otherStoredCalendar = new WorkdaysCalendar("OtherStoredCalendar");
    setField(otherStoredCalendar, "id", 2L);
    WorkdaysCalendar newCalendar = new WorkdaysCalendar("NewCalendar");
    setField(newCalendar, "id", 3L);
    Set<String> newDepts = new HashSet<>();
    newDepts.add("SomeDepartment");
    newCalendar.setDepartments(newDepts);
    Set<String> storedDepts = new HashSet<>();
    storedDepts.add(department);
    storedCalendar.setDepartments(storedDepts);
    Employee employee1 = new Employee();
    employee1.setCalendar(storedCalendar);
    Employee employee2 = new Employee();
    Employee employee3 = new Employee();
    employee3.setCalendar(otherStoredCalendar);
    List<Employee> employees = asList(employee1, employee2, employee3);
    EmployeeRepository.EmployeeQuery query = Mockito.mock(EmployeeRepository.EmployeeQuery.class, RETURNS_DEEP_STUBS);
    Mockito.when(query.department(department).list()).thenReturn(employees);
    EasyMock.expect(employeeRepository.query()).andReturn(query);
    EasyMock.expect(workdaysCalendarRepository.findByDepartment(department)).andReturn(storedCalendar);
    EasyMock.expect(workdaysCalendarRepository.attachAndRefresh(newCalendar)).andReturn(newCalendar);
    EasyMock.replay(employeeRepository, workdaysCalendarRepository);
    departmentService.setCalendarToDepartment(department, newCalendar);
    EasyMock.verify(employeeRepository, workdaysCalendarRepository);
    assertTrue(newCalendar.getDepartments().contains(department));
    assertEquals(newCalendar, employee1.getCalendar());
    assertEquals(newCalendar, employee2.getCalendar());
    assertEquals(otherStoredCalendar, employee3.getCalendar());
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) EmployeeRepository(com.artezio.arttime.repositories.EmployeeRepository) Employee(com.artezio.arttime.datamodel.Employee) Test(org.junit.Test)

Example 28 with WorkdaysCalendar

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

the class WorkdaysCalendarsBeanTest method testGetWorkdaysCalendarsByDepartments_whenNull.

@Test
public void testGetWorkdaysCalendarsByDepartments_whenNull() throws NoSuchFieldException {
    Map<String, WorkdaysCalendar> calendarMap = new HashMap<>();
    String departmentWithCalendar = "Dept1";
    String departmentWithoutCalendar = "Dept2";
    WorkdaysCalendar calendar = new WorkdaysCalendar("Cal1");
    calendarMap.put(departmentWithCalendar, calendar);
    expect(workdaysCalendarService.getCalendarsByDepartments()).andReturn(calendarMap);
    expect(departmentService.getAll()).andReturn(Arrays.asList(departmentWithCalendar, departmentWithoutCalendar));
    replay(workdaysCalendarService, departmentService);
    Map<String, WorkdaysCalendar> actual = bean.getWorkdaysCalendarsByDepartments();
    verify(workdaysCalendarService, departmentService);
    assertTrue(actual.containsKey(departmentWithCalendar));
    assertTrue(actual.containsKey(departmentWithoutCalendar));
    assertEquals(calendar, actual.get(departmentWithCalendar));
    assertNull(actual.get(departmentWithoutCalendar));
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Test(org.junit.Test)

Example 29 with WorkdaysCalendar

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

the class WorkdaysCalendarsBeanTest method testRemove.

@Test
public void testRemove() {
    WorkdaysCalendar workdaysCalendar = new WorkdaysCalendar();
    workdaysCalendarService.remove(workdaysCalendar);
    replay(workdaysCalendarService);
    bean.remove(workdaysCalendar);
    verify(workdaysCalendarService);
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Test(org.junit.Test)

Example 30 with WorkdaysCalendar

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

the class WorkdaysCalendarBeanTest method testUpdateWorkdaysCalendar.

@Test
public void testUpdateWorkdaysCalendar() throws NoSuchFieldException {
    WorkdaysCalendar workdaysCalendar = new WorkdaysCalendar();
    List<Day> days = new ArrayList<Day>();
    setField(calendarBean, "workdaysCalendar", workdaysCalendar);
    workdaysCalendarService.update(workdaysCalendar, days);
    replay(workdaysCalendarService);
    calendarBean.updateWorkdaysCalendar(days);
    verify(workdaysCalendarService);
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Day(com.artezio.arttime.datamodel.Day) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

WorkdaysCalendar (com.artezio.arttime.datamodel.WorkdaysCalendar)76 Test (org.junit.Test)65 Day (com.artezio.arttime.datamodel.Day)23 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)17 Employee (com.artezio.arttime.datamodel.Employee)16 Period (com.artezio.arttime.datamodel.Period)11 Date (java.util.Date)10 Project (com.artezio.arttime.datamodel.Project)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 SimpleDateFormat (java.text.SimpleDateFormat)5 DateFormat (java.text.DateFormat)3 Before (org.junit.Before)3 HourType (com.artezio.arttime.datamodel.HourType)2 Hours (com.artezio.arttime.datamodel.Hours)2 EmployeeRepository (com.artezio.arttime.repositories.EmployeeRepository)2 BigDecimal (java.math.BigDecimal)2 GregorianCalendar (java.util.GregorianCalendar)2 HashMap (java.util.HashMap)2 WebCached (com.artezio.arttime.admin_tool.cache.WebCached)1 Scope (com.artezio.arttime.admin_tool.cache.WebCached.Scope)1