use of com.artezio.arttime.repositories.HoursRepository in project ART-TIME by Artezio.
the class HoursServiceTest method testReportHours_HoursNotExistWhenSaving.
@Test
public void testReportHours_HoursNotExistWhenSaving() throws Exception {
Employee employee = new Employee();
Project project = new Project();
HourType hourType = new HourType();
Date date = new Date();
Hours hours = createHours(1L, project, date, employee, hourType, true);
List<Hours> persistedHours = emptyList();
HoursRepository.HoursQuery query = Mockito.mock(HoursRepository.HoursQuery.class, Mockito.RETURNS_DEEP_STUBS);
EasyMock.expect(hoursRepository.query()).andReturn(query).anyTimes();
Mockito.when(query.projects(singleton(project)).period(new Period(date, date)).employees(singleton(employee)).uncached().list()).thenReturn(persistedHours);
hoursRepository.lock(employee);
EasyMock.expectLastCall();
EasyMock.expect(hoursRepository.create(hours)).andReturn(hours);
EasyMock.replay(sessionContext, hoursRepository);
hoursService.reportHours(asList(hours));
EasyMock.verify(sessionContext, hoursRepository);
}
use of com.artezio.arttime.repositories.HoursRepository in project ART-TIME by Artezio.
the class HoursServiceTest method testManageHours_HoursWithoutAnyValues.
@Test
public void testManageHours_HoursWithoutAnyValues() throws Exception {
Employee employee = new Employee();
Project project = new Project();
HourType hourType = new HourType();
Date date = new Date();
Hours hours = createHours(1L, project, date, employee, hourType, false);
Hours persistedHours = createHours(2L, project, date, employee, hourType, true);
List<Hours> hoursList = asList(hours);
List<Hours> persistedHoursList = asList(persistedHours);
HoursRepository.HoursQuery query = Mockito.mock(HoursRepository.HoursQuery.class, Mockito.RETURNS_DEEP_STUBS);
EasyMock.expect(hoursRepository.query()).andReturn(query).anyTimes();
Mockito.when(query.projects(singleton(project)).period(new Period(date, date)).employees(singleton(employee)).uncached().list()).thenReturn(persistedHoursList);
hoursRepository.lock(employee);
hoursRepository.remove(hours);
EasyMock.replay(hoursRepository);
hoursService.manageHours(hoursList);
EasyMock.verifyUnexpectedCalls(hoursRepository);
}
use of com.artezio.arttime.repositories.HoursRepository in project ART-TIME by Artezio.
the class HoursServiceTest method testManageHours_HoursNotExistWhenSaving.
@Test
public void testManageHours_HoursNotExistWhenSaving() throws Exception {
Employee employee = new Employee();
Project project = new Project();
HourType hourType = new HourType();
Date date = new Date();
Hours hours = createHours(1L, project, date, employee, hourType, true);
List<Hours> persistedHours = emptyList();
HoursRepository.HoursQuery query = Mockito.mock(HoursRepository.HoursQuery.class, Mockito.RETURNS_DEEP_STUBS);
EasyMock.expect(hoursRepository.query()).andReturn(query).anyTimes();
Mockito.when(query.projects(singleton(project)).period(new Period(date, date)).employees(singleton(employee)).uncached().list()).thenReturn(persistedHours);
hoursRepository.lock(employee);
EasyMock.expectLastCall();
EasyMock.expect(hoursRepository.create(hours)).andReturn(hours);
EasyMock.replay(hoursRepository);
hoursService.manageHours(asList(hours));
EasyMock.verify(hoursRepository);
}
use of com.artezio.arttime.repositories.HoursRepository in project ART-TIME by Artezio.
the class HoursServiceTest method testApply_HoursExists_quantityIsNull_commentIsNull.
@Test
public void testApply_HoursExists_quantityIsNull_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(-8.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(null);
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();
hoursRepository.remove(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());
assertNull(persistedHours.getQuantity());
}
use of com.artezio.arttime.repositories.HoursRepository in project ART-TIME by Artezio.
the class WorkTimeServiceTest method testGetActualTime.
@Test
public void testGetActualTime() throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Employee employee = new Employee("username");
Date start = sdf.parse("2014-11-01");
WorkdaysCalendar calendar = new WorkdaysCalendar("calendar");
Project project = createActiveProjectWithTeamMember(employee, calendar);
HourType actualType = new HourType("actual");
actualType.setActualTime(true);
HourType notActualType = new HourType("not_actual");
Hours approved = createHours(project, employee, sdf.parse("2014-11-02"), actualType, new BigDecimal("8"));
approved.setApproved(true);
Period period = new Period(start, sdf.parse("2014-11-30"));
HoursRepository.HoursQuery hoursQuery = createMock(HoursRepository.HoursQuery.class);
expect(hoursRepository.tupleQuery()).andReturn(hoursQuery);
expect(hoursQuery.period(period)).andReturn(hoursQuery);
expect(hoursQuery.employee(employee)).andReturn(hoursQuery);
expect(hoursQuery.actualTime()).andReturn(hoursQuery);
expect(hoursQuery.getTime()).andReturn(BigDecimal.valueOf(24.00));
replay(hoursRepository, hoursQuery);
BigDecimal actual = workTimeService.getActualWorkHours(employee, period);
verify(hoursRepository);
assertTrue(BigDecimal.valueOf(24.00d).compareTo(actual) == 0);
}
Aggregations