Ejemplo n.º 1
0
  @Test
  public void equals() {
    Date start = new Date();
    Date end = new Date();
    Duration duration = new Duration.Builder().hours(1).build();

    List<ICalProperty> properties = new ArrayList<ICalProperty>();

    FreeBusy property = new FreeBusy();
    properties.add(property);

    property = new FreeBusy();
    property.addValue(start, end);
    properties.add(property);

    property = new FreeBusy();
    property.addValue(start, duration);
    properties.add(property);

    property = new FreeBusy();
    property.addValue(start, end);
    property.addValue(start, end);
    properties.add(property);

    assertNothingIsEqual(properties);

    // @formatter:off
    assertEqualsMethod(FreeBusy.class)
        .constructor()
        .test()
        .method("addValue", new Period(start, duration))
        .test();
    // @formatter:on
  }
Ejemplo n.º 2
0
  @Test
  public void copy() {
    FreeBusy original = new FreeBusy();
    assertCopy(original).notSameDeep("getValues");

    original = new FreeBusy();
    original.addValue(new Date(), new Date());
    original.addValue(new Date(), (Date) null);
    original.addValue(new Date(), new Duration.Builder().build());
    original.addValue(new Date(), (Duration) null);
    assertCopy(original).notSameDeep("getValues");
  }
Ejemplo n.º 3
0
  @Test
  public void validate() {
    FreeBusy property = new FreeBusy();
    assertValidate(property).run(38);

    property = new FreeBusy();
    property.addValue(null, (Date) null);
    assertValidate(property).run(39, 40);

    property = new FreeBusy();
    property.addValue(new Date(), (Date) null);
    assertValidate(property).run(40);

    property = new FreeBusy();
    property.addValue(null, new Date());
    assertValidate(property).run(39);

    property = new FreeBusy();
    property.addValue(new Date(), new Date());
    assertValidate(property).run();

    property = new FreeBusy();
    property.addValue(null, (Duration) null);
    assertValidate(property).run(39, 40);

    property = new FreeBusy();
    property.addValue(new Date(), (Duration) null);
    assertValidate(property).run(40);

    property = new FreeBusy();
    property.addValue(null, new Duration.Builder().build());
    assertValidate(property).run(39);

    property = new FreeBusy();
    property.addValue(new Date(), new Duration.Builder().build());
    assertValidate(property).run();
  }
Ejemplo n.º 4
0
  public static FreeBusy getWorkingHours(
      Account authAcct, boolean asAdmin, Account account, String name, long start, long end)
      throws ServiceException {
    // If free/busy viewing is blocked, so is viewing working hours.
    AccessManager accessMgr = AccessManager.getInstance();
    boolean accountAceAllowed = accessMgr.canDo(authAcct, account, User.R_viewFreeBusy, asAdmin);
    if (!accountAceAllowed) return FreeBusy.nodataFreeBusy(account.getName(), start, end);

    // Get the working hours preference and parse it.
    String workingHoursPref = account.getPrefCalendarWorkingHours();
    HoursByDay workingHoursByDay = new HoursByDay(workingHoursPref);

    // Build a recurrence rule for each day of the week and expand over the time range.
    IntervalList intervals = new IntervalList(start, end);
    ICalTimeZone tz = Util.getAccountTimeZone(account);
    TimeZoneMap tzmap = new TimeZoneMap(tz);
    StartSpec startSpec = new StartSpec(start, tz);
    for (int day = 1; day <= 7; ++day) {
      TimeRange timeRange = workingHoursByDay.getHoursForDay(day);
      if (timeRange.enabled) {
        IRecurrence rrule = getRecurrenceForDay(day, startSpec, timeRange, tz, tzmap);
        List<Instance> instances = rrule.expandInstances(0, start, end);
        for (Instance inst : instances) {
          Interval ival =
              new Interval(inst.getStart(), inst.getEnd(), IcalXmlStrMap.FBTYPE_BUSY_UNAVAILABLE);
          intervals.addInterval(ival);
        }
      }
    }
    // Invert FREE and BUSY_UNAVAILABLE in the intervals so that working hours are displayed as free
    // and non-working
    // hours are shown as out-of-office.
    for (Iterator<Interval> iter = intervals.iterator(); iter.hasNext(); ) {
      Interval interval = iter.next();
      String status = interval.getStatus();
      interval.setStatus(invertStatus(status));
    }
    return new FreeBusy(name, intervals, start, end);
  }
Ejemplo n.º 5
0
 @Test(expected = NullPointerException.class)
 public void addValue_null() {
   FreeBusy property = new FreeBusy();
   property.addValue(null);
 }
Ejemplo n.º 6
0
  @Test
  public void set_value() {
    FreeBusy property = new FreeBusy();
    Date start = new Date();
    Date end = new Date();
    Duration duration = new Duration.Builder().hours(1).build();

    Period period = new Period(start, duration);
    property.addValue(period);
    assertEquals(Arrays.asList(period), property.getValues());
    assertNull(property.getType());

    property.addValue(start, duration);
    assertEquals(Arrays.asList(period, period), property.getValues());
    assertNull(property.getType());

    Period period2 = new Period(start, end);
    property.addValue(start, end);
    assertEquals(Arrays.asList(period, period, period2), property.getValues());
    assertNull(property.getType());

    Period period3 = new Period(start, (Date) null);
    property.addValue(period3);
    assertEquals(Arrays.asList(period, period, period2, period3), property.getValues());
    assertNull(property.getType());

    Period period4 = new Period(start, (Duration) null);
    property.addValue(period4);
    assertEquals(Arrays.asList(period, period, period2, period3, period4), property.getValues());
    assertNull(property.getType());

    property.setType(FreeBusyType.BUSY);
    assertEquals(Arrays.asList(period, period, period2, period3, period4), property.getValues());
    assertEquals(FreeBusyType.BUSY, property.getType());

    property.setType(null);
    assertEquals(Arrays.asList(period, period, period2, period3, period4), property.getValues());
    assertNull(property.getType());
  }
Ejemplo n.º 7
0
 @Test
 public void constructors() throws Exception {
   FreeBusy property = new FreeBusy();
   assertEquals(Arrays.asList(), property.getValues());
 }
Ejemplo n.º 8
0
 @Test
 public void toStringValues() {
   FreeBusy property = new FreeBusy();
   assertFalse(property.toStringValues().isEmpty());
 }