Search in sources :

Example 1 with ProjectRepository

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

Example 2 with ProjectRepository

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

Example 3 with ProjectRepository

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);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) ProjectRepository(com.artezio.arttime.services.repositories.ProjectRepository) Subject(org.apache.shiro.subject.Subject) TestSubject(org.easymock.TestSubject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with ProjectRepository

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);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) ProjectRepository(com.artezio.arttime.services.repositories.ProjectRepository) Subject(org.apache.shiro.subject.Subject) TestSubject(org.easymock.TestSubject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with ProjectRepository

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));
}
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)

Aggregations

ProjectRepository (com.artezio.arttime.services.repositories.ProjectRepository)14 Test (org.junit.Test)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 Project (com.artezio.arttime.datamodel.Project)8 Employee (com.artezio.arttime.datamodel.Employee)4 Subject (org.apache.shiro.subject.Subject)4 TestSubject (org.easymock.TestSubject)4 Filter (com.artezio.arttime.filter.Filter)2 Method (java.lang.reflect.Method)2 EntityManager (javax.persistence.EntityManager)2 Before (org.junit.Before)2 FilterRepository (com.artezio.arttime.services.repositories.FilterRepository)1 HoursRepository (com.artezio.arttime.services.repositories.HoursRepository)1 WorkdaysCalendarRepository (com.artezio.arttime.services.repositories.WorkdaysCalendarRepository)1 HashMap (java.util.HashMap)1