use of com.artezio.arttime.repositories.EmployeeRepository in project ART-TIME by Artezio.
the class EmployeeServiceTest method testGetEmployeesHavingAccessToAnyDepartment.
@Test
public void testGetEmployeesHavingAccessToAnyDepartment() throws NoSuchFieldException {
employeeRepository = new EmployeeRepository();
setField(employeeRepository, "entityManager", entityManager);
setField(employeeService, "employeeRepository", employeeRepository);
String department1 = "dep1";
String department2 = "dep2";
Employee expected1 = new Employee("uname1", "fname1", "lname1", "email1");
expected1.setAccessibleDepartments(Sets.newHashSet(department1));
Employee expected2 = new Employee("uname2", "fname2", "lname2", "email2");
expected2.setAccessibleDepartments(Sets.newHashSet(department2));
Employee unexpected = new Employee("uxname3", "fname3", "lname3", "email3");
entityManager.persist(expected1);
entityManager.persist(expected2);
entityManager.persist(unexpected);
entityManager.flush();
List<Employee> actual = employeeService.getEmployeesHavingAccessToAnyDepartment();
assertTrue(actual.contains(expected1));
assertTrue(actual.contains(expected2));
assertFalse(actual.contains(unexpected));
Employee actual1 = actual.get(actual.indexOf(expected1));
Employee actual2 = actual.get(actual.indexOf(expected2));
assertTrue(Hibernate.isInitialized(actual1.getAccessibleDepartments()));
assertTrue(Hibernate.isInitialized(actual2.getAccessibleDepartments()));
}
use of com.artezio.arttime.repositories.EmployeeRepository in project ART-TIME by Artezio.
the class EmployeeServiceTest method testGetCurrent.
@Test
public void testGetCurrent() throws Exception {
Employee currentEmployee1 = new Employee("uname1", "fname1", "lname1", "email1");
currentEmployee1.setFormer(false);
Employee currentEmployee2 = new Employee("uname2", "fname2", "lname2", "email2");
currentEmployee2.setFormer(false);
Employee formerEmployee = new Employee("uxname3", "fname3", "lname3", "email3");
formerEmployee.setFormer(true);
List<Employee> expected = Arrays.asList(currentEmployee1, currentEmployee2);
employeeRepository = new EmployeeRepository();
setField(employeeRepository, "entityManager", entityManager);
setField(employeeService, "employeeRepository", employeeRepository);
entityManager.persist(currentEmployee1);
entityManager.persist(currentEmployee2);
entityManager.persist(formerEmployee);
entityManager.flush();
List<Employee> actual = employeeService.getCurrent();
assertEquals(expected, actual);
}
Aggregations