use of com.artezio.arttime.services.repositories.ProjectRepository in project ART-TIME by Artezio.
the class ManageProjectPermissionFilterTest method testGetProjectRepository_ifNull.
@Test
public void testGetProjectRepository_ifNull() throws NoSuchFieldException {
setField(filter, "projectRepository", null);
PowerMock.mockStatic(CDIUtils.class);
expect(CDIUtils.getBean(ProjectRepository.class)).andReturn(projectRepository);
PowerMock.replayAll(CDIUtils.class);
ProjectRepository actual = filter.getProjectRepository();
PowerMock.verifyAll();
assertNotNull(actual);
assertSame(projectRepository, actual);
}
use of com.artezio.arttime.services.repositories.ProjectRepository in project ART-TIME by Artezio.
the class ManageProjectPermissionFilterTest method testGetProjectRepository_ifNotNull.
@Test
public void testGetProjectRepository_ifNotNull() throws NoSuchFieldException {
setField(filter, "projectRepository", projectRepository);
ProjectRepository actual = filter.getProjectRepository();
assertNotNull(actual);
assertSame(projectRepository, actual);
}
use of com.artezio.arttime.services.repositories.ProjectRepository in project ART-TIME by Artezio.
the class ProjectServiceTest method testGetAvailableProjects_userIsPM_expectManagedProjects.
@Test
public void testGetAvailableProjects_userIsPM_expectManagedProjects() throws NoSuchFieldException {
Employee currentEmployee = new Employee("curr", "fn", "ln", "mail");
Employee manager1 = new Employee("man1", "fn1", "ln1", "mail1");
Employee manager2 = new Employee("man2", "fn2", "ln2", "mail2");
Project project1 = createProject(1L, null);
Project project2 = createProject(2L, null);
Project project3 = createProject(3L, null);
project1.setManagers(Arrays.asList(manager1, currentEmployee));
project2.setManagers(Arrays.asList(manager2));
project3.setManagers(Arrays.asList(currentEmployee));
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(true);
expect(projectRepository.getManagedProjects(currentEmployee)).andReturn(Arrays.asList(project1, project3));
List<Project> expected = Arrays.asList(project1, 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 testGetAvailableProjects_userIsExec_expectAllProjects.
@Test
public void testGetAvailableProjects_userIsExec_expectAllProjects() throws NoSuchFieldException {
Employee currentEmployee = new Employee("curr", "fn", "ln", "mail");
Employee manager1 = new Employee("man1", "fn1", "ln1", "mail1");
Employee manager2 = new Employee("man2", "fn2", "ln2", "mail2");
Project project1 = createProject(1L, null);
Project project2 = createProject(2L, null);
Project project3 = createProject(3L, null);
project1.setManagers(Arrays.asList(manager1));
project2.setManagers(Arrays.asList(manager2));
project3.setManagers(Arrays.asList(currentEmployee));
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(true);
expect(projectRepository.getAll()).andReturn(Arrays.asList(project1, project2, project3));
List<Project> expected = Arrays.asList(project1, project2, 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 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));
}
Aggregations