protected void addCalendarBooking(
      String uuid,
      long calendarBookingId,
      long companyId,
      long groupId,
      long userId,
      String userName,
      Date createDate,
      Date modifiedDate,
      long calendarId,
      long calendarResourceId,
      String title,
      String description,
      String location,
      long startTime,
      long endTime,
      boolean allDay,
      String recurrence,
      int firstReminder,
      NotificationType firstReminderType,
      int secondReminder,
      NotificationType secondReminderType)
      throws SystemException {

    CalendarBooking calendarBooking = calendarBookingPersistence.create(calendarBookingId);

    calendarBooking.setUuid(uuid);
    calendarBooking.setCompanyId(companyId);
    calendarBooking.setGroupId(groupId);
    calendarBooking.setUserId(userId);
    calendarBooking.setUserName(userName);
    calendarBooking.setCreateDate(createDate);
    calendarBooking.setModifiedDate(modifiedDate);
    calendarBooking.setCalendarId(calendarId);
    calendarBooking.setCalendarResourceId(calendarResourceId);
    calendarBooking.setParentCalendarBookingId(calendarBookingId);
    calendarBooking.setTitle(title);
    calendarBooking.setDescription(description);
    calendarBooking.setLocation(location);
    calendarBooking.setStartTime(startTime);
    calendarBooking.setEndTime(endTime);
    calendarBooking.setAllDay(allDay);
    calendarBooking.setRecurrence(recurrence);
    calendarBooking.setFirstReminder(firstReminder);
    calendarBooking.setFirstReminderType(firstReminderType.toString());
    calendarBooking.setSecondReminder(secondReminder);
    calendarBooking.setSecondReminderType(secondReminderType.toString());
    calendarBooking.setStatus(WorkflowConstants.STATUS_APPROVED);
    calendarBooking.setStatusByUserId(userId);
    calendarBooking.setStatusByUserName(userName);
    calendarBooking.setStatusDate(createDate);

    calendarBookingPersistence.update(calendarBooking);
  }
  @Test
  public void testRecurrenceIsNull() throws ParseException {
    Calendar calendar = Calendar.getInstance();

    CalendarBooking calendarBooking = new CalendarBookingImpl();

    calendarBooking.setStartTime(calendar.getTimeInMillis());
    calendarBooking.setRecurrence(null);

    CalendarBookingIterator calendarBookingIterator = new CalendarBookingIterator(calendarBooking);

    int count = 0;

    while (calendarBookingIterator.hasNext()) {
      calendarBookingIterator.next();

      count++;
    }

    Assert.assertEquals(1, count);
  }
  /**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static CalendarBooking toModel(CalendarBookingSoap soapModel) {
    if (soapModel == null) {
      return null;
    }

    CalendarBooking model = new CalendarBookingImpl();

    model.setUuid(soapModel.getUuid());
    model.setCalendarBookingId(soapModel.getCalendarBookingId());
    model.setGroupId(soapModel.getGroupId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setUserId(soapModel.getUserId());
    model.setUserName(soapModel.getUserName());
    model.setCreateDate(soapModel.getCreateDate());
    model.setModifiedDate(soapModel.getModifiedDate());
    model.setCalendarId(soapModel.getCalendarId());
    model.setCalendarResourceId(soapModel.getCalendarResourceId());
    model.setParentCalendarBookingId(soapModel.getParentCalendarBookingId());
    model.setTitle(soapModel.getTitle());
    model.setDescription(soapModel.getDescription());
    model.setLocation(soapModel.getLocation());
    model.setStartTime(soapModel.getStartTime());
    model.setEndTime(soapModel.getEndTime());
    model.setAllDay(soapModel.getAllDay());
    model.setRecurrence(soapModel.getRecurrence());
    model.setFirstReminder(soapModel.getFirstReminder());
    model.setFirstReminderType(soapModel.getFirstReminderType());
    model.setSecondReminder(soapModel.getSecondReminder());
    model.setSecondReminderType(soapModel.getSecondReminderType());
    model.setStatus(soapModel.getStatus());
    model.setStatusByUserId(soapModel.getStatusByUserId());
    model.setStatusByUserName(soapModel.getStatusByUserName());
    model.setStatusDate(soapModel.getStatusDate());

    return model;
  }
  @Test
  public void testRecurrenceStartsMondayRepeatsWednesday() throws ParseException {

    Calendar calendar = Calendar.getInstance();

    calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

    CalendarBooking calendarBooking = new CalendarBookingImpl();

    calendarBooking.setStartTime(calendar.getTimeInMillis());
    calendarBooking.setRecurrence("RRULE:FREQ=WEEKLY;COUNT=2;INTERVAL=1;BYDAY=WE");

    CalendarBookingIterator calendarBookingIterator = new CalendarBookingIterator(calendarBooking);

    int count = 0;

    while (calendarBookingIterator.hasNext()) {
      calendarBookingIterator.next();

      count++;
    }

    Assert.assertEquals(2, count);
  }