Search in sources :

Example 51 with Project

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

the class LdapAdapterTest method testListEmployeesByTeamCodes.

@Test
public void testListEmployeesByTeamCodes() throws Exception {
    Logger log = createMock(Logger.class);
    setField(ldapImpl, "log", log);
    Project project = new Project();
    TeamFilter teamFilter = new TeamFilter(FilterType.PROJECT_CODES, "_ART-PRJ-ART-TIME-PG");
    project.setTeamFilter(teamFilter);
    setField(ldapImpl, "workdaysCalendarRepository", workdaysCalendarRepository);
    expect(workdaysCalendarRepository.findDefaultCalendar(anyObject(Employee.class))).andReturn(null).anyTimes();
    replay(workdaysCalendarRepository);
    List<Employee> team = ldapImpl.getTeam(project);
    verify(workdaysCalendarRepository);
    assertTrue(team.size() > 0);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) TeamFilter(com.artezio.arttime.datamodel.TeamFilter) Logger(java.util.logging.Logger) Test(org.junit.Test)

Example 52 with Project

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

the class EmployeeRepositoryTest method testGetEmployeesByDepartments_ifEmployeesDepartmentsAreEmpty.

@Test
public void testGetEmployeesByDepartments_ifEmployeesDepartmentsAreEmpty() {
    Employee employee1 = new Employee("employee1");
    employee1.setDepartment("department1");
    Employee employee2 = new Employee("employee2");
    employee2.setDepartment("department2");
    Employee employee3 = new Employee("employee3");
    employee3.setDepartment("department3");
    Project project1 = new Project();
    project1.addTeamMember(employee1);
    project1.addTeamMember(employee2);
    Project project2 = new Project();
    project2.addTeamMember(employee1);
    project2.addTeamMember(employee3);
    Filter filter = new Filter();
    filter.setEmployees(Collections.emptyList());
    filter.setDepartments(Collections.emptyList());
    entityManager.persist(project1);
    entityManager.persist(project2);
    entityManager.persist(employee1);
    entityManager.persist(employee2);
    entityManager.persist(employee3);
    entityManager.flush();
    List<Employee> expected = Arrays.asList(employee1, employee2, employee3);
    List<Employee> actual = employeeRepository.getEmployeesByDepartments(filter);
    ListAssert.assertEquals(expected, actual);
}
Also used : 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 Project

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

the class FilterRepositoryTest method testFetchDetails.

@Test
public void testFetchDetails() throws NoSuchMethodException, SecurityException, NoSuchFieldException {
    Filter filter = new Filter();
    Project project = new Project();
    List<Project> projects = Arrays.asList(project);
    filter.setProjects(projects);
    Project projectLoaded = new Project();
    List<Project> projectsLoaded = Arrays.asList(projectLoaded);
    entityManager.persist(project);
    entityManager.persist(projectLoaded);
    entityManager.persist(filter);
    Method fetchCompleteMethod = ProjectRepository.class.getMethod("fetchComplete", List.class);
    projectRepository = EasyMock.createMockBuilder(ProjectRepository.class).addMockedMethod(fetchCompleteMethod).createMock();
    setField(filterRepository, "projectRepository", projectRepository);
    PowerMock.mockStatic(Hibernate.class);
    Hibernate.initialize(filter.getDepartments());
    Hibernate.initialize(filter.getEmployees());
    Hibernate.initialize(filter.getProjects());
    Hibernate.initialize(filter.getHourTypes());
    EasyMock.expect(projectRepository.fetchComplete(projects)).andReturn(projectsLoaded);
    PowerMock.replayAll(Hibernate.class, projectRepository);
    filterRepository.fetchDetails(filter);
    PowerMock.verifyAll();
    assertSame(projectLoaded, filter.getProjects().get(0));
}
Also used : Project(com.artezio.arttime.datamodel.Project) ProjectRepository(com.artezio.arttime.services.repositories.ProjectRepository) Filter(com.artezio.arttime.filter.Filter) Method(java.lang.reflect.Method) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 54 with Project

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

the class FilterRepositoryTest method testFetchDetails_ifFilterNoPersisted.

@Test
public void testFetchDetails_ifFilterNoPersisted() throws NoSuchMethodException, SecurityException, NoSuchFieldException {
    Filter filter = new Filter();
    Project project = new Project();
    List<Project> projects = Arrays.asList(project);
    filter.setProjects(projects);
    Project projectLoaded = new Project();
    List<Project> projectsLoaded = Arrays.asList(projectLoaded);
    entityManager.persist(project);
    entityManager.persist(projectLoaded);
    Method fetchCompleteMethod = ProjectRepository.class.getMethod("fetchComplete", List.class);
    projectRepository = EasyMock.createMockBuilder(ProjectRepository.class).addMockedMethod(fetchCompleteMethod).createMock();
    setField(filterRepository, "projectRepository", projectRepository);
    EasyMock.expect(projectRepository.fetchComplete(projects)).andReturn(projectsLoaded);
    EasyMock.replay(projectRepository);
    filterRepository.fetchDetails(filter);
    EasyMock.verify(projectRepository);
    assertSame(projectLoaded, filter.getProjects().get(0));
}
Also used : Project(com.artezio.arttime.datamodel.Project) ProjectRepository(com.artezio.arttime.services.repositories.ProjectRepository) Filter(com.artezio.arttime.filter.Filter) Method(java.lang.reflect.Method) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 55 with Project

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

the class HourTypeRepositoryTest method testRemoveHourType_RemoveForbidden.

@Test(expected = PersistenceException.class)
public void testRemoveHourType_RemoveForbidden() throws ActualTimeRemovalException {
    HourType hourType = new HourType();
    Project project = new Project();
    project.addAccountableHours(hourType);
    entityManager.persist(hourType);
    entityManager.persist(project);
    hourTypeRepository.remove(hourType);
}
Also used : Project(com.artezio.arttime.datamodel.Project) HourType(com.artezio.arttime.datamodel.HourType) Test(org.junit.Test)

Aggregations

Project (com.artezio.arttime.datamodel.Project)310 Test (org.junit.Test)278 Employee (com.artezio.arttime.datamodel.Employee)195 HourType (com.artezio.arttime.datamodel.HourType)119 Hours (com.artezio.arttime.datamodel.Hours)108 Date (java.util.Date)61 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)56 Period (com.artezio.arttime.datamodel.Period)43 BigDecimal (java.math.BigDecimal)39 Filter (com.artezio.arttime.filter.Filter)33 TeamFilter (com.artezio.arttime.datamodel.TeamFilter)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)25 CalendarUtils.createPeriod (com.artezio.arttime.test.utils.CalendarUtils.createPeriod)21 ArrayList (java.util.ArrayList)18 Arrays.asList (java.util.Arrays.asList)18 ProjectRepository (com.artezio.arttime.repositories.ProjectRepository)17 List (java.util.List)17 HoursRepository (com.artezio.arttime.repositories.HoursRepository)13 HashMap (java.util.HashMap)13 Map (java.util.Map)11