Search in sources :

Example 61 with HourType

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);
}
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) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 62 with HourType

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);
}
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) Test(org.junit.Test)

Example 63 with HourType

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());
}
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 64 with HourType

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);
}
Also used : HourType(com.artezio.arttime.datamodel.HourType) Test(org.junit.Test)

Example 65 with HourType

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());
}
Also used : HourType(com.artezio.arttime.datamodel.HourType) Test(org.junit.Test)

Aggregations

HourType (com.artezio.arttime.datamodel.HourType)172 Test (org.junit.Test)158 Project (com.artezio.arttime.datamodel.Project)120 Employee (com.artezio.arttime.datamodel.Employee)115 Hours (com.artezio.arttime.datamodel.Hours)103 Date (java.util.Date)60 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)54 Period (com.artezio.arttime.datamodel.Period)45 BigDecimal (java.math.BigDecimal)41 CalendarUtils.createPeriod (com.artezio.arttime.test.utils.CalendarUtils.createPeriod)21 HashMap (java.util.HashMap)16 HoursRepository (com.artezio.arttime.repositories.HoursRepository)13 Map (java.util.Map)11 Arrays.asList (java.util.Arrays.asList)10 List (java.util.List)10 Filter (com.artezio.arttime.filter.Filter)7 Mail (com.artezio.arttime.services.mailing.Mail)7 ArrayList (java.util.ArrayList)7 HourTypeRepository (com.artezio.arttime.repositories.HourTypeRepository)6 RangePeriodSelector (com.artezio.arttime.web.criteria.RangePeriodSelector)6