Search in sources :

Example 6 with WorkdaysCalendar

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

the class WorkdaysCalendarRepositoryTest method testRemoveWorkdaysCalendar.

@Test
public void testRemoveWorkdaysCalendar() {
    WorkdaysCalendar workdaysCalendar = new WorkdaysCalendar("calendar");
    Day day = new Day(new Date(), workdaysCalendar);
    entityManager.persist(workdaysCalendar);
    entityManager.persist(day);
    Long dayId = day.getId();
    Long workdaysCalendarId = workdaysCalendar.getId();
    workdaysCalendarRepository.remove(workdaysCalendar);
    entityManager.flush();
    entityManager.clear();
    WorkdaysCalendar actualCalendar = entityManager.find(WorkdaysCalendar.class, workdaysCalendarId);
    Day actualDay = entityManager.find(Day.class, dayId);
    assertNull(actualCalendar);
    assertNull(actualDay);
}
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 7 with WorkdaysCalendar

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

the class WorkdaysCalendarRepositoryTest method testGetDays.

@Test
public void testGetDays() {
    Date start = new Date();
    Date finish = getOffsetDate(2);
    Period period = new Period(start, finish);
    WorkdaysCalendar calendar = new WorkdaysCalendar("calendar");
    Day day = new Day(new Date(), calendar);
    entityManager.persist(calendar);
    entityManager.persist(day);
    entityManager.flush();
    entityManager.clear();
    List<Day> actual = workdaysCalendarRepository.getDays(calendar, period);
    assertNotNull(actual);
    assertEquals(3, actual.size());
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Period(com.artezio.arttime.datamodel.Period) Day(com.artezio.arttime.datamodel.Day) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 8 with WorkdaysCalendar

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

the class WorkdaysCalendarRepositoryTest method testGetPersistedDays_ShouldFilterByPeriod.

@Test
public void testGetPersistedDays_ShouldFilterByPeriod() {
    WorkdaysCalendar workdaysCalendar = new WorkdaysCalendar();
    workdaysCalendar.setName("calendarName");
    Date start = new GregorianCalendar(2011, 0, 2).getTime();
    Date finish = new GregorianCalendar(2011, 0, 29).getTime();
    Date expectedDate = new GregorianCalendar(2011, 0, 15).getTime();
    Date unexpectedDate1 = new GregorianCalendar(2011, 0, 1).getTime();
    Date unexpectedDate2 = new GregorianCalendar(2011, 0, 30).getTime();
    Period period = new Period(start, finish);
    Day expected1 = new Day(start, workdaysCalendar);
    Day expected2 = new Day(expectedDate, workdaysCalendar);
    Day expected3 = new Day(finish, workdaysCalendar);
    Day unexpected1 = new Day(unexpectedDate1, workdaysCalendar);
    Day unexpected2 = new Day(unexpectedDate2, workdaysCalendar);
    entityManager.persist(workdaysCalendar);
    entityManager.persist(expected1);
    entityManager.persist(expected3);
    entityManager.persist(expected2);
    entityManager.persist(unexpected1);
    entityManager.persist(unexpected2);
    List<Day> actuals = workdaysCalendarRepository.getPersistedDays(workdaysCalendar, period);
    assertEquals(3, actuals.size());
    assertFalse(actuals.contains(unexpected1));
    assertFalse(actuals.contains(unexpected2));
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) GregorianCalendar(java.util.GregorianCalendar) Period(com.artezio.arttime.datamodel.Period) Day(com.artezio.arttime.datamodel.Day) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 9 with WorkdaysCalendar

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

the class WorkdaysCalendarRepositoryTest method testRemoveWorkdaysCalendar_RemoveForbidden.

@Test(expected = PersistenceException.class)
public void testRemoveWorkdaysCalendar_RemoveForbidden() {
    WorkdaysCalendar workdaysCalendar = new WorkdaysCalendar("calendar");
    Project project = new Project();
    Employee employee = new Employee("employee");
    employee.setCalendar(workdaysCalendar);
    project.addTeamMember(employee);
    entityManager.persist(workdaysCalendar);
    entityManager.persist(employee);
    entityManager.persist(project);
    workdaysCalendarRepository.remove(workdaysCalendar);
    entityManager.flush();
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) Test(org.junit.Test)

Example 10 with WorkdaysCalendar

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

the class WorkdaysCalendarRepositoryTest method testRemoveWorkdaysCalendar_NotUsedCalendarWithDepartment.

@Test
public void testRemoveWorkdaysCalendar_NotUsedCalendarWithDepartment() {
    WorkdaysCalendar calendar = new WorkdaysCalendar("calendar");
    calendar.getDepartments().add("minsk");
    entityManager.persist(calendar);
    entityManager.flush();
    entityManager.clear();
    workdaysCalendarRepository.remove(calendar);
    entityManager.flush();
    entityManager.clear();
    WorkdaysCalendar actual = entityManager.find(WorkdaysCalendar.class, calendar.getId());
    assertNull(actual);
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) 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