use of com.artezio.arttime.repositories.HoursRepository in project ART-TIME by Artezio.
the class HoursServiceTest method testManageHours_HoursExistWhenSaving.
@Test
public void testManageHours_HoursExistWhenSaving() 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);
Hours persistedHours = createHours(2L, project, date, employee, hourType, true);
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);
EasyMock.expect(hoursRepository.update(hours)).andReturn(hours);
EasyMock.replay(sessionContext, hoursRepository);
hoursService.manageHours(asList(hours));
EasyMock.verify(sessionContext, hoursRepository);
assertEquals(persistedHours, hours);
}
use of com.artezio.arttime.repositories.HoursRepository in project ART-TIME by Artezio.
the class HoursServiceTest method testApply_HoursExists_quantityIsNotNull_commentIsNotNull.
@Test
public void testApply_HoursExists_quantityIsNotNull_commentIsNotNull() {
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));
hoursChange.setComment("comment");
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));
expectedHours.setComment("comment");
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);
assertEquals(expectedHours.getComment(), persistedHours.getComment());
assertEquals(expectedHours.getQuantity(), persistedHours.getQuantity());
}
use of com.artezio.arttime.repositories.HoursRepository in project ART-TIME by Artezio.
the class HoursServiceTest method testReportHours_HoursExistWhenSaving.
@Test(expected = SaveApprovedHoursException.class)
public void testReportHours_HoursExistWhenSaving() 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);
Hours persistedHours = createHours(2L, project, date, employee, hourType, true);
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);
EasyMock.expect(hoursRepository.create(hours)).andReturn(hours);
EasyMock.replay(sessionContext, hoursRepository);
hoursService.reportHours(asList(hours));
EasyMock.verifyUnexpectedCalls(sessionContext, hoursRepository);
}
use of com.artezio.arttime.repositories.HoursRepository in project ART-TIME by Artezio.
the class HoursServiceTest method testReportHours_HoursWithoutAnyValues_ApprovedHoursExist.
@Test(expected = SaveApprovedHoursException.class)
public void testReportHours_HoursWithoutAnyValues_ApprovedHoursExist() 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);
EasyMock.replay(hoursRepository);
hoursService.reportHours(hoursList);
EasyMock.verifyUnexpectedCalls(hoursRepository);
}
use of com.artezio.arttime.repositories.HoursRepository in project ART-TIME by Artezio.
the class HoursServiceTest method testApply_HoursExists_quantityIsNull_commentIsNotNull.
@Test
public void testApply_HoursExists_quantityIsNull_commentIsNotNull() {
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));
hoursChange.setComment("comment");
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);
expectedHours.setComment("comment");
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);
assertEquals(expectedHours.getComment(), persistedHours.getComment());
assertNull(persistedHours.getQuantity());
}
Aggregations