Search in sources :

Example 11 with HoursRepository

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

the class HoursServiceTest method testReportHours_HoursWithoutAnyValues_ApprovedHoursNotExist.

@Test
public void testReportHours_HoursWithoutAnyValues_ApprovedHoursNotExist() throws Exception {
    Employee employee = new Employee();
    Project project = new Project();
    HourType hourType = new HourType();
    Date date = new Date();
    Period period = new Period(date, date);
    Hours hours = createHours(1L, project, date, employee, hourType, false);
    List<Hours> hoursList = asList(hours);
    Set<Project> projects = singleton(project);
    Set<Employee> employees = singleton(employee);
    HoursRepository.HoursQuery query = Mockito.mock(HoursRepository.HoursQuery.class, Mockito.RETURNS_DEEP_STUBS);
    EasyMock.expect(hoursRepository.query()).andReturn(query).anyTimes();
    Mockito.when(query.projects(projects).period(period).employees(employees).uncached().list()).thenReturn(emptyList());
    hoursRepository.lock(employee);
    hoursRepository.remove(hours);
    EasyMock.replay(hoursRepository);
    hoursService.reportHours(hoursList);
    EasyMock.verifyUnexpectedCalls(hoursRepository);
    Mockito.verify(query.projects(projects).period(period).employees(employees).uncached()).list();
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) Hours(com.artezio.arttime.datamodel.Hours) Period(com.artezio.arttime.datamodel.Period) CalendarUtils.createPeriod(com.artezio.arttime.test.utils.CalendarUtils.createPeriod) HoursRepository(com.artezio.arttime.repositories.HoursRepository) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 12 with HoursRepository

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

the class HoursServiceTest method testApply_HoursNotExists.

@Test
public void testApply_HoursNotExists() {
    Employee employee = new Employee("empl1");
    Project project = new Project();
    project.setCode("BBBCode");
    HourType hourType = new HourType("off");
    Date date1 = new GregorianCalendar(2016, 5, 5).getTime();
    Hours hours = new Hours(project, date1, employee, hourType);
    HoursChange hoursChange = new HoursChange(project.getCode(), date1, employee.getUserName(), 1L);
    hoursChange.setQuantityDelta(BigDecimal.valueOf(5.0));
    ProjectRepository.ProjectQuery projectQuery = Mockito.mock(ProjectRepository.ProjectQuery.class, Mockito.RETURNS_DEEP_STUBS);
    HoursRepository.HoursQuery hoursQuery = Mockito.mock(HoursRepository.HoursQuery.class, Mockito.RETURNS_DEEP_STUBS);
    EasyMock.expect(projectRepository.query()).andReturn(projectQuery);
    EasyMock.expect(hoursRepository.query()).andReturn(hoursQuery);
    Mockito.when(hoursQuery.employee(hoursChange.getEmployeeUsername()).project(hoursChange.getProjectCode()).hourType(hoursChange.getTypeId()).date(hoursChange.getDate()).uncached().getSingleResultOrNull()).thenReturn(null);
    Mockito.when(projectQuery.code(project.getCode()).getSingleResult()).thenReturn(project);
    hoursRepository.lock(employee);
    EasyMock.expect(hoursRepository.create(hours)).andReturn(hours);
    EasyMock.expect(employeeRepository.get(employee.getUserName())).andReturn(employee).times(2);
    EasyMock.expect(hourTypeService.find(anyLong())).andReturn(hourType);
    EasyMock.replay(hoursRepository, employeeRepository, hourTypeService, projectRepository);
    hoursService.apply(hoursChange);
    EasyMock.verify(hoursRepository, employeeRepository, hourTypeService, projectRepository);
    Mockito.verify(hoursQuery.employee(hoursChange.getEmployeeUsername()).project(hoursChange.getProjectCode()).hourType(hoursChange.getTypeId()).date(hoursChange.getDate()).uncached()).getSingleResultOrNull();
    Mockito.verify(projectQuery.code(project.getCode())).getSingleResult();
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) ProjectRepository(com.artezio.arttime.repositories.ProjectRepository) Hours(com.artezio.arttime.datamodel.Hours) GregorianCalendar(java.util.GregorianCalendar) HoursRepository(com.artezio.arttime.repositories.HoursRepository) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 13 with HoursRepository

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

the class HoursServiceTest method testApply_HoursExists_quantityIsNotNull_commentIsNull.

@Test
public void testApply_HoursExists_quantityIsNotNull_commentIsNull() {
    Employee employee = new Employee("empl1");
    Project project = new Project();
    project.setCode("CodeProject");
    HourType hourType = new HourType("off");
    Date date1 = new GregorianCalendar(2016, 5, 5).getTime();
    ;
    HoursChange hoursChange = new HoursChange(project.getCode(), date1, employee.getUserName(), 4L);
    hoursChange.setQuantityDelta(BigDecimal.valueOf(5.0));
    Hours persistedHours = new Hours(project, date1, employee, hourType);
    persistedHours.setQuantity(BigDecimal.valueOf(8.0));
    Hours expectedHours = new Hours(project, date1, employee, hourType);
    expectedHours.setQuantity(BigDecimal.valueOf(13.0));
    HoursRepository.HoursQuery query = Mockito.mock(HoursRepository.HoursQuery.class, Mockito.RETURNS_DEEP_STUBS);
    EasyMock.expect(hoursRepository.query()).andReturn(query);
    Mockito.when(query.employee(hoursChange.getEmployeeUsername()).project(hoursChange.getProjectCode()).hourType(hoursChange.getTypeId()).date(hoursChange.getDate()).uncached().getSingleResultOrNull()).thenReturn(persistedHours);
    hoursRepository.lock(employee);
    EasyMock.expect(employeeRepository.get(employee.getUserName())).andReturn(employee).anyTimes();
    EasyMock.expect(hoursRepository.update(expectedHours)).andReturn(expectedHours);
    EasyMock.replay(hoursRepository, employeeRepository);
    hoursService.apply(hoursChange);
    EasyMock.verify(hoursRepository, employeeRepository);
    Mockito.verify(query.employee(hoursChange.getEmployeeUsername()).project(hoursChange.getProjectCode()).hourType(hoursChange.getTypeId()).date(hoursChange.getDate()).uncached()).getSingleResultOrNull();
    assertEquals(expectedHours, persistedHours);
    assertNull(persistedHours.getComment());
    assertEquals(expectedHours.getQuantity(), persistedHours.getQuantity());
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) Hours(com.artezio.arttime.datamodel.Hours) GregorianCalendar(java.util.GregorianCalendar) HoursRepository(com.artezio.arttime.repositories.HoursRepository) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 14 with HoursRepository

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

the class HoursServiceTest method testGetHours.

@Test
public void testGetHours() {
    HourType hourType = new HourType("1");
    List<HourType> hourTypes = Collections.singletonList(hourType);
    Project project = new Project();
    project.setAccountableHours(hourTypes);
    Employee employee = new Employee();
    Hours hour = new Hours(project, new Date(), employee, hourType);
    RangePeriodSelector rangePeriodSelector = new RangePeriodSelector(createPeriod(-1, 1));
    Filter filter = new Filter();
    filter.setRangePeriodSelector(rangePeriodSelector);
    filter.setHourTypes(hourTypes);
    filter.setProjects(Collections.singletonList(project));
    HoursRepository.HoursQuery hoursQuery = Mockito.mock(HoursRepository.HoursQuery.class, Mockito.RETURNS_DEEP_STUBS);
    EasyMock.expect(hoursRepository.query()).andReturn(hoursQuery);
    Mockito.when(hoursQuery.approved(filter.isApproved()).projects(Mockito.anyList()).departments(Mockito.anyList()).types(Mockito.anyList()).period(filter.getPeriod()).employees(Mockito.anyList()).list()).thenReturn(asList(hour));
    EasyMock.replay(hoursRepository);
    List<Hours> actual = hoursService.getHours(filter);
    List<Hours> expected = Collections.singletonList(hour);
    EasyMock.verify(hoursRepository);
    Mockito.verify(hoursQuery.approved(filter.isApproved()).projects(Mockito.anyList()).departments(filter.getDepartments()).types(filter.getHourTypes()).period(filter.getPeriod()).employees(filter.getEmployees())).list();
    assertEquals(expected, actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) HourType(com.artezio.arttime.datamodel.HourType) Employee(com.artezio.arttime.datamodel.Employee) Hours(com.artezio.arttime.datamodel.Hours) Filter(com.artezio.arttime.filter.Filter) RangePeriodSelector(com.artezio.arttime.web.criteria.RangePeriodSelector) HoursRepository(com.artezio.arttime.repositories.HoursRepository) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Aggregations

HoursRepository (com.artezio.arttime.repositories.HoursRepository)14 Date (java.util.Date)14 Test (org.junit.Test)14 Employee (com.artezio.arttime.datamodel.Employee)13 HourType (com.artezio.arttime.datamodel.HourType)13 Hours (com.artezio.arttime.datamodel.Hours)13 Project (com.artezio.arttime.datamodel.Project)13 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)13 Period (com.artezio.arttime.datamodel.Period)7 CalendarUtils.createPeriod (com.artezio.arttime.test.utils.CalendarUtils.createPeriod)7 GregorianCalendar (java.util.GregorianCalendar)5 Filter (com.artezio.arttime.filter.Filter)1 ProjectRepository (com.artezio.arttime.repositories.ProjectRepository)1 CalendarUtils.createHours (com.artezio.arttime.test.utils.CalendarUtils.createHours)1 RangePeriodSelector (com.artezio.arttime.web.criteria.RangePeriodSelector)1 BigDecimal (java.math.BigDecimal)1 SimpleDateFormat (java.text.SimpleDateFormat)1