Search in sources :

Example 36 with Period

use of com.artezio.arttime.datamodel.Period 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 37 with Period

use of com.artezio.arttime.datamodel.Period 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 38 with Period

use of com.artezio.arttime.datamodel.Period 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 39 with Period

use of com.artezio.arttime.datamodel.Period in project ART-TIME by Artezio.

the class NotificationSchedulerTest method testNotifyAboutUnapprovedHours.

@Test
public void testNotifyAboutUnapprovedHours() {
    List<Employee> managers = Arrays.asList(new Employee("test_user"));
    Date start = new GregorianCalendar(2020, 1, 1).getTime();
    Date finish = new GregorianCalendar(2020, 1, 29).getTime();
    Period period = new Period(start, finish);
    expect(settingsService.getSettings()).andReturn(settings);
    expect(settings.isUnapprovedHoursNotificationEnabled()).andReturn(true);
    expect(notificationScheduler.getPeriodForPreviousMonth()).andReturn(period);
    expect(hoursService.getManagersForUnapprovedHours(period)).andReturn(managers);
    notificationManager.notifyAboutUnapprovedHours(managers, period);
    expectLastCall().once();
    replayAll();
    notificationScheduler.notifyAboutUnapprovedHours();
    verifyAll();
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) GregorianCalendar(java.util.GregorianCalendar) Period(com.artezio.arttime.datamodel.Period) Date(java.util.Date) Test(org.junit.Test)

Example 40 with Period

use of com.artezio.arttime.datamodel.Period in project ART-TIME by Artezio.

the class MonthSelectorTest method testInit.

@Test
public void testInit() throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
    monthSelector = createMockBuilder(MonthSelector.class).addMockedMethod("getAttributes").createMock();
    Period period = new Period(sdf.parse("1-01-2015"), sdf.parse("31-01-2015"));
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put("period", period);
    expect(monthSelector.getAttributes()).andReturn(attrs);
    replay(monthSelector);
    monthSelector.init();
    verify(monthSelector);
    assertEquals(period, getField(monthSelector, "period"));
}
Also used : HashMap(java.util.HashMap) Period(com.artezio.arttime.datamodel.Period) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Aggregations

Period (com.artezio.arttime.datamodel.Period)93 Test (org.junit.Test)87 Employee (com.artezio.arttime.datamodel.Employee)59 Date (java.util.Date)56 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)44 HourType (com.artezio.arttime.datamodel.HourType)43 Project (com.artezio.arttime.datamodel.Project)42 Hours (com.artezio.arttime.datamodel.Hours)40 BigDecimal (java.math.BigDecimal)34 CalendarUtils.createPeriod (com.artezio.arttime.test.utils.CalendarUtils.createPeriod)22 Day (com.artezio.arttime.datamodel.Day)17 HashMap (java.util.HashMap)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 WorkdaysCalendar (com.artezio.arttime.datamodel.WorkdaysCalendar)13 List (java.util.List)13 Map (java.util.Map)11 ArrayList (java.util.ArrayList)8 GregorianCalendar (java.util.GregorianCalendar)8 HoursRepository (com.artezio.arttime.repositories.HoursRepository)7 Mail (com.artezio.arttime.services.mailing.Mail)7