use of com.artezio.arttime.datamodel.HourType in project ART-TIME by Artezio.
the class HoursServiceTest method testExistApprovedHours_DifferentHourTypes.
@Test
public void testExistApprovedHours_DifferentHourTypes() throws NoSuchFieldException {
Employee employee = new Employee("employee");
Project project = new Project();
setField(project, "id", 1L);
HourType hourType1 = new HourType("regular");
HourType hourType2 = new HourType("overtime");
Date date = new Date();
Hours persisted = new Hours(project, date, employee, hourType1);
persisted.setApproved(true);
Hours newHour = new Hours(project, date, employee, hourType2);
hoursService = new HoursService();
boolean actual = hoursService.existApprovedHours(asList(newHour), asList(persisted));
assertFalse(actual);
}
use of com.artezio.arttime.datamodel.HourType in project ART-TIME by Artezio.
the class HoursServiceTest method testExistApprovedHours_ifNotExists.
@Test
public void testExistApprovedHours_ifNotExists() throws NoSuchFieldException {
Employee employee = new Employee("employee");
Project project = new Project();
setField(project, "id", 1L);
HourType hourType = new HourType("regular");
Hours hour1 = new Hours(project, getOffsetDate(-1), employee, hourType);
Hours hour2 = new Hours(project, getOffsetDate(1), employee, hourType);
List<Hours> persisted = asList(hour1, hour2);
Hours hour3 = new Hours(project, getOffsetDate(1), employee, hourType);
hoursService = new HoursService();
boolean actual = hoursService.existApprovedHours(asList(hour3), persisted);
assertFalse(actual);
}
use of com.artezio.arttime.datamodel.HourType 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.datamodel.HourType in project ART-TIME by Artezio.
the class HourTypeRepositoryTest method testRemoveHourType.
@Test
public void testRemoveHourType() throws ActualTimeRemovalException {
HourType hourType = new HourType();
entityManager.persist(hourType);
Long id = hourType.getId();
hourTypeRepository.remove(hourType);
HourType actual = entityManager.find(HourType.class, id);
assertNull(actual);
}
use of com.artezio.arttime.datamodel.HourType in project ART-TIME by Artezio.
the class HourTypeRepositoryTest method testResetActualTime.
@Test
public void testResetActualTime() {
HourType notActualTime = new HourType();
HourType actualTime = new HourType();
actualTime.setActualTime(true);
entityManager.persist(notActualTime);
entityManager.persist(actualTime);
entityManager.flush();
entityManager.clear();
entityManager.createQuery("UPDATE HourType h SET h.actualTime = false").executeUpdate();
List<HourType> actual = entityManager.createQuery("SELECT ht FROM HourType ht", HourType.class).getResultList();
assertFalse(actual.get(0).isActualTime());
assertFalse(actual.get(1).isActualTime());
}
Aggregations