Search in sources :

Example 1 with HoursRepository

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

Example 2 with 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);
}
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) Period(com.artezio.arttime.datamodel.Period) CalendarUtils.createPeriod(com.artezio.arttime.test.utils.CalendarUtils.createPeriod) HoursRepository(com.artezio.arttime.repositories.HoursRepository) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 3 with 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);
}
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) Period(com.artezio.arttime.datamodel.Period) CalendarUtils.createPeriod(com.artezio.arttime.test.utils.CalendarUtils.createPeriod) HoursRepository(com.artezio.arttime.repositories.HoursRepository) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 4 with 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());
}
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 5 with HoursRepository

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);
}
Also used : CalendarUtils.createHours(com.artezio.arttime.test.utils.CalendarUtils.createHours) HoursRepository(com.artezio.arttime.repositories.HoursRepository) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

HoursRepository (com.artezio.arttime.repositories.HoursRepository)14 Date (java.util.Date)14 Test (org.junit.Test)14 Employee (com.artezio.arttime.datamodel.Employee)13 HourType (com.artezio.arttime.datamodel.HourType)13 Hours (com.artezio.arttime.datamodel.Hours)13 Project (com.artezio.arttime.datamodel.Project)13 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)13 Period (com.artezio.arttime.datamodel.Period)7 CalendarUtils.createPeriod (com.artezio.arttime.test.utils.CalendarUtils.createPeriod)7 GregorianCalendar (java.util.GregorianCalendar)5 Filter (com.artezio.arttime.filter.Filter)1 ProjectRepository (com.artezio.arttime.repositories.ProjectRepository)1 CalendarUtils.createHours (com.artezio.arttime.test.utils.CalendarUtils.createHours)1 RangePeriodSelector (com.artezio.arttime.web.criteria.RangePeriodSelector)1 BigDecimal (java.math.BigDecimal)1 SimpleDateFormat (java.text.SimpleDateFormat)1