Search in sources :

Example 11 with WorkdaysCalendar

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

the class WorkdaysCalendarRepositoryTest method testCreateOrUpdateDays_Update.

@Test
public void testCreateOrUpdateDays_Update() {
    WorkdaysCalendar workdaysCalendar = new WorkdaysCalendar("calendar-testCreateOrUpdateDays_Update");
    Day day = new Day(new Date(), workdaysCalendar);
    entityManager.persist(workdaysCalendar);
    entityManager.persist(day);
    WorkdaysCalendar calendar = new WorkdaysCalendar();
    String expected = "expected calendar name";
    calendar.setName(expected);
    entityManager.persist(calendar);
    day.setWorkdaysCalendar(calendar);
    workdaysCalendarRepository.update(Arrays.asList(day));
    assertEquals(expected, day.getWorkdaysCalendar().getName());
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Day(com.artezio.arttime.datamodel.Day) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 12 with WorkdaysCalendar

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

the class WorkdaysCalendarBean method init.

@PostConstruct
public void init() {
    Map<String, String> requestParams = externalContext.getRequestParameterMap();
    String calendarId = requestParams.get("calendar");
    if (calendarId == null) {
        this.workdaysCalendar = new WorkdaysCalendar();
    } else {
        this.workdaysCalendar = workdaysCalendarService.findById(Long.parseLong(calendarId));
        Date start = CalendarUtils.firstDayOfMonth(new Date());
        Date finish = CalendarUtils.lastDayOfMonth(new Date());
        updatePeriod(start, finish);
    }
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) PostConstruct(javax.annotation.PostConstruct)

Example 13 with WorkdaysCalendar

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

the class WorkdaysCalendarServiceTest method testCreateDays.

@Test
public void testCreateDays() {
    Date date1 = new GregorianCalendar(2011, 1, 3).getTime();
    Date date2 = new GregorianCalendar(2011, 1, 0).getTime();
    List<Date> dates = Arrays.asList(date1, date2);
    WorkdaysCalendar workdaysCalendar = new WorkdaysCalendar("calendar");
    List<Day> actuals = workdaysCalendarService.createDays(dates, workdaysCalendar);
    assertEquals(2, actuals.size());
    Day actual = actuals.get(0);
    assertEquals(date1, actual.getDate());
    assertEquals(workdaysCalendar.getName(), actual.getWorkdaysCalendar().getName());
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Day(com.artezio.arttime.datamodel.Day) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 14 with WorkdaysCalendar

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

the class WorkdaysCalendarServiceTest method testGetCalendarsByDepartments.

@Test
public void testGetCalendarsByDepartments() {
    WorkdaysCalendar calendar1 = new WorkdaysCalendar("cal1");
    calendar1.getDepartments().add("Minsk");
    calendar1.getDepartments().add("Moscow");
    WorkdaysCalendar calendar2 = new WorkdaysCalendar("cal2");
    calendar2.getDepartments().add("Vitebsk");
    Map<String, WorkdaysCalendar> expected = new HashMap<>();
    expected.put("Minsk", calendar1);
    expected.put("Moscow", calendar1);
    expected.put("Vitebsk", calendar2);
    expect(workdaysCalendarRepository.getWorkdaysCalendars()).andReturn(Arrays.asList(calendar1, calendar2));
    replay(workdaysCalendarRepository);
    Map<String, WorkdaysCalendar> actual = workdaysCalendarService.getCalendarsByDepartments();
    assertEquals(expected, actual);
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Test(org.junit.Test)

Example 15 with WorkdaysCalendar

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

the class ProjectRepositoryTest method testCreateProject.

@Test
public void testCreateProject() throws NoSuchFieldException {
    HourType hourType = new HourType("type");
    WorkdaysCalendar calendar = new WorkdaysCalendar("calendar");
    entityManager.persist(hourType);
    entityManager.persist(calendar);
    entityManager.flush();
    entityManager.clear();
    Employee manager = new Employee("manager");
    Employee resource = new Employee("slave");
    resource.setCalendar(calendar);
    Project project = new Project();
    project.addManager(manager);
    project.getAccountableHours().add(hourType);
    project.addTeamMember(resource);
    assertNull(project.getId());
    setField(projectRepository, "employeeRepository", employeeRepository);
    expect(employeeRepository.create(resource)).andReturn(getPersisted(resource));
    expect(employeeRepository.create(manager)).andReturn(getPersisted(manager));
    replay(employeeRepository);
    Project actual = projectRepository.create(project);
    entityManager.flush();
    verify(employeeRepository);
    assertNotNull(actual.getId());
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Project(com.artezio.arttime.datamodel.Project) HourType(com.artezio.arttime.datamodel.HourType) Employee(com.artezio.arttime.datamodel.Employee) Test(org.junit.Test)

Aggregations

WorkdaysCalendar (com.artezio.arttime.datamodel.WorkdaysCalendar)76 Test (org.junit.Test)65 Day (com.artezio.arttime.datamodel.Day)23 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)17 Employee (com.artezio.arttime.datamodel.Employee)16 Period (com.artezio.arttime.datamodel.Period)11 Date (java.util.Date)10 Project (com.artezio.arttime.datamodel.Project)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 SimpleDateFormat (java.text.SimpleDateFormat)5 DateFormat (java.text.DateFormat)3 Before (org.junit.Before)3 HourType (com.artezio.arttime.datamodel.HourType)2 Hours (com.artezio.arttime.datamodel.Hours)2 EmployeeRepository (com.artezio.arttime.repositories.EmployeeRepository)2 BigDecimal (java.math.BigDecimal)2 GregorianCalendar (java.util.GregorianCalendar)2 HashMap (java.util.HashMap)2 WebCached (com.artezio.arttime.admin_tool.cache.WebCached)1 Scope (com.artezio.arttime.admin_tool.cache.WebCached.Scope)1