Search in sources :

Example 11 with ProjectRepository

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

Example 12 with ProjectRepository

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);
}
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 13 with ProjectRepository

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

Example 14 with ProjectRepository

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();
}
Also used : ProjectRepository(com.artezio.arttime.services.repositories.ProjectRepository) WorkdaysCalendarRepository(com.artezio.arttime.services.repositories.WorkdaysCalendarRepository) HoursRepository(com.artezio.arttime.services.repositories.HoursRepository) Before(org.junit.Before)

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