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();
}
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();
}
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());
}
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);
}
Aggregations