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