Search in sources :

Example 11 with Project

use of com.artezio.arttime.datamodel.Project in project ART-TIME by Artezio.

the class UniqueConstraintValidatorTest method testIsValid.

@Test
public void testIsValid() throws Exception {
    Project project1 = new Project();
    project1.setCode("project1");
    entityManager.persist(project1);
    entityManager.flush();
    entityManager.clear();
    setField(uniqueConstraintValidator, "entityManager", entityManager);
    setField(uniqueConstraintValidator, "uniqueFields", new String[] { "code", "master" });
    Project project2 = new Project();
    project1.setCode("project2");
    boolean actual = uniqueConstraintValidator.isValid(project2, null);
    assertTrue(actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Test(org.junit.Test)

Example 12 with Project

use of com.artezio.arttime.datamodel.Project in project ART-TIME by Artezio.

the class UniqueConstraintValidatorTest method testIsValid_notValidAfterChangeCode.

@Test
public void testIsValid_notValidAfterChangeCode() throws Exception {
    Project project1 = new Project();
    project1.setCode("project");
    Project project2 = new Project();
    project2.setCode("project2");
    entityManager.persist(project1);
    entityManager.persist(project2);
    entityManager.flush();
    entityManager.clear();
    setField(uniqueConstraintValidator, "entityManager", entityManager);
    setField(uniqueConstraintValidator, "uniqueFields", new String[] { "code", "master" });
    project2.setCode("project");
    boolean actual = uniqueConstraintValidator.isValid(project2, null);
    assertFalse(actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Test(org.junit.Test)

Example 13 with Project

use of com.artezio.arttime.datamodel.Project in project ART-TIME by Artezio.

the class FilterBeanTest method testSetSelectedProjects_FilterHasFilledProjectList_EmployeeIsPM.

@Test
public void testSetSelectedProjects_FilterHasFilledProjectList_EmployeeIsPM() throws NoSuchFieldException {
    Project project1 = createProject(1L, null, "project1");
    Project project11 = createProject(2L, project1, "project11");
    Project project12 = createProject(3L, project1, "project12");
    Project project2 = createProject(5L, null, "project2");
    List<Project> projects = Arrays.asList(project11, project12, project2);
    Filter filter = new Filter();
    setField(filterBean, "currentFilter", filter);
    expect(externalContext.isUserInRole("exec")).andReturn(false);
    expect(projectService.getSubprojectsByProjects(projects)).andReturn(projects);
    replay(externalContext, projectService);
    filterBean.setSelectedProjects(projects);
    verify(externalContext, projectService);
    assertSame(projects, filter.getProjects());
}
Also used : Project(com.artezio.arttime.datamodel.Project) Filter(com.artezio.arttime.filter.Filter) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 14 with Project

use of com.artezio.arttime.datamodel.Project in project ART-TIME by Artezio.

the class FilterBeanTest method testGetCurrentFilter_CurrentFilterIsNull.

@Test
public final void testGetCurrentFilter_CurrentFilterIsNull() throws NoSuchFieldException {
    setField(filterBean, "currentFilter", null);
    Filter expected = new Filter();
    List<Project> projects = Collections.emptyList();
    expected.setProjects(projects);
    expect(filterService.getActiveProjectsFilter(loggedEmployee)).andReturn(expected);
    expect(filterRepository.fetchDetails(expected)).andReturn(expected);
    expect(projectService.getSubprojectsByProjects(projects)).andReturn(projects).anyTimes();
    replay(filterService, filterRepository, externalContext, projectService);
    Filter actual = filterBean.getCurrentFilter();
    verify(filterService, filterRepository, externalContext, projectService);
    assertSame(expected, actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Filter(com.artezio.arttime.filter.Filter) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 15 with Project

use of com.artezio.arttime.datamodel.Project in project ART-TIME by Artezio.

the class FilterBeanTest method testGetAvailableProjects.

@Test
public final void testGetAvailableProjects() throws NoSuchFieldException {
    Project project1 = createProject(1L, null, "project1");
    project1.setStatus(FROZEN);
    Project project11 = createProject(2L, project1, "project11");
    Project project12 = createProject(3L, project1, "project12");
    Project project111 = createProject(4L, project11, "project111");
    Project project2 = createProject(5L, null, "project2");
    Project project21 = createProject(6L, project2, "project21");
    Project project3 = createProject(7L, null, "project3");
    List<Project> projects = Arrays.asList(project1, project11, project12, project111, project2, project21, project3);
    List<Project> onlyActiveProjects = projects.subList(1, projects.size() - 1);
    List<Project> expected = Arrays.asList(project1, project2, project3);
    expect(projectService.getAvailableProjects(anyObject())).andReturn(projects);
    expect(projectService.getActiveOnly(projects)).andReturn(onlyActiveProjects);
    expect(projectService.getHighlevelOnly(onlyActiveProjects)).andReturn(expected);
    replay(projectService);
    List<Project> actual = filterBean.getAvailableProjects();
    verify(projectService);
    ListAssert.assertEquals(expected, actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Project (com.artezio.arttime.datamodel.Project)310 Test (org.junit.Test)278 Employee (com.artezio.arttime.datamodel.Employee)195 HourType (com.artezio.arttime.datamodel.HourType)119 Hours (com.artezio.arttime.datamodel.Hours)108 Date (java.util.Date)61 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)56 Period (com.artezio.arttime.datamodel.Period)43 BigDecimal (java.math.BigDecimal)39 Filter (com.artezio.arttime.filter.Filter)33 TeamFilter (com.artezio.arttime.datamodel.TeamFilter)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)25 CalendarUtils.createPeriod (com.artezio.arttime.test.utils.CalendarUtils.createPeriod)21 ArrayList (java.util.ArrayList)18 Arrays.asList (java.util.Arrays.asList)18 ProjectRepository (com.artezio.arttime.repositories.ProjectRepository)17 List (java.util.List)17 HoursRepository (com.artezio.arttime.repositories.HoursRepository)13 HashMap (java.util.HashMap)13 Map (java.util.Map)11