Search in sources :

Example 6 with HoursRepository

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);
}
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 7 with HoursRepository

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());
}
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 8 with HoursRepository

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);
}
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 9 with 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);
}
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 10 with 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());
}
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)

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