Search in sources :

Example 6 with EmployeeRepository

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()));
}
Also used : EmployeeRepository(com.artezio.arttime.repositories.EmployeeRepository) Employee(com.artezio.arttime.datamodel.Employee) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with EmployeeRepository

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);
}
Also used : EmployeeRepository(com.artezio.arttime.repositories.EmployeeRepository) Employee(com.artezio.arttime.datamodel.Employee) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

EmployeeRepository (com.artezio.arttime.repositories.EmployeeRepository)7 Test (org.junit.Test)7 Employee (com.artezio.arttime.datamodel.Employee)4 Filter (com.artezio.arttime.filter.Filter)3 ProjectRepository (com.artezio.arttime.repositories.ProjectRepository)3 WorkTime (com.artezio.arttime.services.WorkTimeService.WorkTime)3 Arrays.asList (java.util.Arrays.asList)3 Collections.emptyList (java.util.Collections.emptyList)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Tuple (javax.persistence.Tuple)3 WorkdaysCalendar (com.artezio.arttime.datamodel.WorkdaysCalendar)2 BigDecimal (java.math.BigDecimal)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2