use of com.artezio.arttime.services.repositories.ProjectRepository in project ART-TIME by Artezio.
the class ProjectServiceTest method testGetSubprojectsByProjects_forProjectsMixedWithMasters_expectResultDistinct.
@Test
public void testGetSubprojectsByProjects_forProjectsMixedWithMasters_expectResultDistinct() throws NoSuchFieldException {
projectRepository = new ProjectRepository();
EntityManager entityManager = getEntityManager();
setField(projectRepository, "entityManager", entityManager);
setField(projectService, "projectRepository", projectRepository);
entityManager.getTransaction().begin();
Project master1 = new Project(null);
Project master2 = new Project(null);
Project subproject01 = new Project(master1);
Project subproject02 = new Project(master1);
Project subproject11 = new Project(subproject01);
Project subproject21 = new Project(master2);
Project subproject22 = new Project(master2);
entityManager.persist(master1);
entityManager.persist(master2);
entityManager.persist(subproject01);
entityManager.persist(subproject02);
entityManager.persist(subproject11);
entityManager.persist(subproject21);
entityManager.persist(subproject22);
List<Project> expected = Arrays.asList(master1, master2, subproject01, subproject11, subproject02, subproject21, subproject22);
List<Project> actual = projectService.getSubprojectsByProjects(Arrays.asList(master1, master2, subproject01, subproject11, subproject22));
entityManager.getTransaction().commit();
ListAssert.assertEquals(expected, actual);
}
use of com.artezio.arttime.services.repositories.ProjectRepository in project ART-TIME by Artezio.
the class ProjectServiceTest method testGetAvailableProjects_userIsEmployee_hasProjects_expectMemberProjects.
@Test
public void testGetAvailableProjects_userIsEmployee_hasProjects_expectMemberProjects() throws NoSuchFieldException {
Employee currentEmployee = new Employee("curr", "fn", "ln", "mail");
Project project1 = createProject(1L, null);
Project project2 = createProject(2L, null);
Project project3 = createProject(3L, null);
Subject subject = createMock(Subject.class);
PowerMock.mockStatic(SecurityUtils.class);
projectRepository = createMock(ProjectRepository.class);
setField(projectService, "projectRepository", projectRepository);
expect(SecurityUtils.getSubject()).andReturn(subject);
expect(subject.hasRole(UserRoles.EXEC_ROLE)).andReturn(false);
expect(subject.hasRole(UserRoles.PM_ROLE)).andReturn(false);
expect(projectRepository.getActiveProjects(currentEmployee)).andReturn(Arrays.asList(project3));
List<Project> expected = Arrays.asList(project3);
PowerMock.replayAll(projectRepository, subject, SecurityUtils.class);
List<Project> actual = projectService.getAvailableProjects(currentEmployee);
PowerMock.verifyAll();
ListAssert.assertEquals(expected, actual);
}
use of com.artezio.arttime.services.repositories.ProjectRepository in project ART-TIME by Artezio.
the class ProjectServiceTest method testGetProjectsInTree.
@Test
public void testGetProjectsInTree() throws NoSuchFieldException {
projectRepository = new ProjectRepository();
EntityManager entityManager = getEntityManager();
setField(projectRepository, "entityManager", entityManager);
setField(projectService, "projectRepository", projectRepository);
entityManager.getTransaction().begin();
Project master = new Project(null);
Project subproject01 = new Project(master);
Project subproject02 = new Project(master);
Project subproject11 = new Project(subproject01);
entityManager.persist(master);
entityManager.persist(subproject01);
entityManager.persist(subproject02);
entityManager.persist(subproject11);
List<Project> expected = Arrays.asList(master, subproject01, subproject11, subproject02);
List<Project> actual = projectService.getSubprojectsByProject(master);
entityManager.getTransaction().commit();
ListAssert.assertEquals(expected, actual);
}
use of com.artezio.arttime.services.repositories.ProjectRepository in project ART-TIME by Artezio.
the class WorkTimeServiceTest method setUp.
@Before
public void setUp() throws Exception {
workTimeService = new WorkTimeService();
Map<String, String> properties = new HashMap<>();
properties.put("javax.persistence.validation.mode", "none");
entityManagerFactory = Persistence.createEntityManagerFactory("test", properties);
entityManager = entityManagerFactory.createEntityManager();
ProjectRepository projectRepository = new ProjectRepository();
WorkdaysCalendarRepository workdaysCalendarRepository = new WorkdaysCalendarRepository();
HoursRepository hoursRepository = new HoursRepository();
setField(projectRepository, "entityManager", entityManager);
setField(workdaysCalendarRepository, "entityManager", entityManager);
setField(hoursRepository, "entityManager", entityManager);
setField(workTimeService, "projectRepository", projectRepository);
setField(workTimeService, "workdaysCalendarRepository", workdaysCalendarRepository);
setField(workTimeService, "hoursRepository", hoursRepository);
entityManager.getTransaction().begin();
}
Aggregations