Search in sources :

Example 16 with Project

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

the class FilterBeanTest method testSetSelectedProjects_FilterHasEmptyProjectList.

@Test
public void testSetSelectedProjects_FilterHasEmptyProjectList() throws NoSuchFieldException {
    List<Project> emptyProjectList = Collections.emptyList();
    Filter filter = new Filter();
    setField(filterBean, "currentFilter", filter);
    expect(projectService.getSubprojectsByProjects(emptyProjectList)).andReturn(Collections.emptyList()).anyTimes();
    replay(externalContext, projectService);
    filterBean.setSelectedProjects(emptyProjectList);
    verify(externalContext, projectService);
    ListAssert.assertEquals(emptyProjectList, 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 17 with Project

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

the class ProjectBeanTest method testChangeRecordWithArrayValueToListValueInParticipations_allRemoved_expectClear.

@Test
public void testChangeRecordWithArrayValueToListValueInParticipations_allRemoved_expectClear() throws NoSuchFieldException {
    Map<Employee, Project[]> participations = new HashMap<>();
    Employee employee = new Employee("empl");
    Project oldProject = new Project();
    setField(oldProject, "id", 33L);
    oldProject.addTeamMember(employee);
    Project oldProject2 = new Project();
    oldProject2.addTeamMember(employee);
    setField(oldProject2, "id", 44L);
    participations.put(employee, new Project[] {});
    setField(bean, "participations", participations);
    setField(bean, "projects", Arrays.asList(oldProject, oldProject2));
    List<Project> newParticipations = Collections.emptyList();
    bean.changeRecordWithArrayValueToListValueInParticipations(employee, newParticipations);
    assertTrue(bean.getParticipations().containsKey(employee));
    List<Project> actualParticipations = bean.getParticipations().get(employee);
    assertFalse(actualParticipations.contains(oldProject2));
    assertFalse(actualParticipations.contains(oldProject));
    assertFalse(oldProject.isTeamMember(employee));
    assertFalse(oldProject2.isTeamMember(employee));
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) Test(org.junit.Test)

Example 18 with Project

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

the class ProjectBeanTest method testChangeRecordWithArrayValueToListValueInParticipations_allNew_expectAddAll.

@Test
public void testChangeRecordWithArrayValueToListValueInParticipations_allNew_expectAddAll() throws NoSuchFieldException {
    Map<Employee, List<Project>> participations = new HashMap<>();
    Employee employee = new Employee();
    Project newProject = new Project();
    setField(bean, "participations", participations);
    setField(bean, "projects", Arrays.asList(newProject));
    List<Project> expectedParticipations = Arrays.asList(newProject);
    bean.changeRecordWithArrayValueToListValueInParticipations(employee, expectedParticipations);
    assertTrue(bean.getParticipations().containsKey(employee));
    List<Project> actualParticipations = bean.getParticipations().get(employee);
    assertTrue(actualParticipations.contains(newProject));
    assertTrue(newProject.isTeamMember(employee));
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) Test(org.junit.Test)

Example 19 with Project

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

the class ProjectBeanTest method testChangeRecordWithArrayValueToListValueInParticipations_someNew_someRemoved_expectAddAndRemove.

@Test
public void testChangeRecordWithArrayValueToListValueInParticipations_someNew_someRemoved_expectAddAndRemove() throws NoSuchFieldException {
    Map<Employee, Project[]> participations = new HashMap<>();
    Employee employee = new Employee("empl");
    Project newProject = new Project();
    setField(newProject, "id", 22L);
    Project oldProject = new Project();
    oldProject.addTeamMember(employee);
    setField(oldProject, "id", 33L);
    Project oldProject2 = new Project();
    oldProject2.addTeamMember(employee);
    setField(oldProject2, "id", 44L);
    participations.put(employee, new Project[] { newProject, oldProject2 });
    setField(bean, "participations", participations);
    setField(bean, "projects", Arrays.asList(newProject, oldProject, oldProject2));
    List<Project> newParticipations = Arrays.asList(newProject, oldProject2);
    bean.changeRecordWithArrayValueToListValueInParticipations(employee, newParticipations);
    assertTrue(bean.getParticipations().containsKey(employee));
    List<Project> actualParticipations = bean.getParticipations().get(employee);
    assertTrue(actualParticipations.contains(newProject));
    assertTrue(actualParticipations.contains(oldProject2));
    assertFalse(actualParticipations.contains(oldProject));
    assertTrue(newProject.isTeamMember(employee));
    assertTrue(oldProject2.isTeamMember(employee));
    assertFalse(oldProject.isTeamMember(employee));
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) Test(org.junit.Test)

Example 20 with Project

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

the class ProjectsBeanTest method testGetProjects_ifProjectsNull_andUserInRolePM.

@Test
public void testGetProjects_ifProjectsNull_andUserInRolePM() throws NoSuchFieldException {
    List<Project> expected = new ArrayList<Project>();
    Employee loggedEmployee = new Employee();
    setField(projectBean, "projects", null);
    setField(projectBean, "loggedEmployee", loggedEmployee);
    setField(projectBean, "externalContext", externalContext);
    setField(projectBean, "projectRepository", projectRepository);
    expect(externalContext.isUserInRole("exec")).andReturn(false);
    expect(projectRepository.getManagedProjects(loggedEmployee)).andReturn(expected);
    replay(externalContext, projectRepository);
    List<Project> actual = projectBean.getProjects();
    verify(externalContext, projectRepository);
    assertSame(expected, actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) ArrayList(java.util.ArrayList) Test(org.junit.Test)

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