Search in sources :

Example 6 with ProjectRepository

use of com.artezio.arttime.services.repositories.ProjectRepository 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 7 with ProjectRepository

use of com.artezio.arttime.services.repositories.ProjectRepository in project ART-TIME by Artezio.

the class FilterRepositoryTest method setUp.

@Before
public void setUp() throws Exception {
    filterRepository = new FilterRepository();
    projectRepository = EasyMock.createMock(ProjectRepository.class);
    setField(filterRepository, "projectRepository", projectRepository);
    Map<String, String> properties = new HashMap<String, String>();
    properties.put("javax.persistence.validation.mode", "none");
    entityManagerFactory = Persistence.createEntityManagerFactory("test", properties);
    entityManager = entityManagerFactory.createEntityManager();
    setField(filterRepository, "entityManager", entityManager);
    entityManager.getTransaction().begin();
}
Also used : ProjectRepository(com.artezio.arttime.services.repositories.ProjectRepository) FilterRepository(com.artezio.arttime.services.repositories.FilterRepository) HashMap(java.util.HashMap) Before(org.junit.Before)

Example 8 with ProjectRepository

use of com.artezio.arttime.services.repositories.ProjectRepository in project ART-TIME by Artezio.

the class ActiveDirectoryRealmTest method testGetProjectRepository_ifNotNull.

@Test
public void testGetProjectRepository_ifNotNull() throws NoSuchFieldException {
    setField(activeDirectoryRealm, "projectRepository", projectRepository);
    ProjectRepository actual = activeDirectoryRealm.getProjectRepository();
    assertSame(projectRepository, actual);
}
Also used : ProjectRepository(com.artezio.arttime.services.repositories.ProjectRepository) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with ProjectRepository

use of com.artezio.arttime.services.repositories.ProjectRepository in project ART-TIME by Artezio.

the class ActiveDirectoryRealmTest method testGetProjectRepository_ifNull.

@Test
public void testGetProjectRepository_ifNull() throws NoSuchFieldException {
    setField(activeDirectoryRealm, "projectRepository", null);
    PowerMock.mockStatic(CDIUtils.class);
    expect(CDIUtils.getBean(ProjectRepository.class)).andReturn(projectRepository);
    PowerMock.replayAll();
    ProjectRepository actual = activeDirectoryRealm.getProjectRepository();
    PowerMock.verifyAll();
    assertSame(projectRepository, actual);
}
Also used : ProjectRepository(com.artezio.arttime.services.repositories.ProjectRepository) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with ProjectRepository

use of com.artezio.arttime.services.repositories.ProjectRepository in project ART-TIME by Artezio.

the class ProjectServiceTest method testGetAvailableProjects_userIsEmployee_hasNoProjects_expectMemberProjects.

@Test
public void testGetAvailableProjects_userIsEmployee_hasNoProjects_expectMemberProjects() throws NoSuchFieldException {
    Employee currentEmployee = new Employee("curr", "fn", "ln", "mail");
    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(Collections.emptyList());
    List<Project> expected = Arrays.asList();
    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)

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