@Test
 public void testGetAllEvents() throws XWikiException {
   ArrayList<EventApi> eventList = new ArrayList<EventApi>();
   IEvent event = createMock(IEvent.class);
   event.setLanguage(eq("de"));
   expectLastCall().once();
   IEvent event2 = createMock(IEvent.class);
   event2.setLanguage(eq("de"));
   expectLastCall().once();
   IEvent event3 = createMock(IEvent.class);
   event3.setLanguage(eq("de"));
   expectLastCall().once();
   IEvent event4 = createMock(IEvent.class);
   event4.setLanguage(eq("de"));
   expectLastCall().once();
   DocumentReference cal2DocRef =
       new DocumentReference(context.getDatabase(), "MyCalDoc2Space", "MyCal2Doc");
   Calendar cal2 = new Calendar(cal2DocRef, isArchiv);
   cal2.setCalendarUtils(calUtils);
   cal2.inject_getEventCmd(eventMgrMock);
   expect(eventMgrMock.getEvents(same(cal2), eq(0), eq(0))).andReturn(eventList);
   replayAll(event, event2, event3, event4);
   eventList.add(new EventApi(event, context));
   eventList.add(new EventApi(event2, context));
   eventList.add(new EventApi(event3, context));
   eventList.add(new EventApi(event4, context));
   List<EventApi> events = cal2.getAllEvents();
   verifyAll(event, event2, event3, event4);
   assertEquals("expecting complete eventList", eventList, events);
 }
 @Test
 public void testSetStartDate_null() {
   Date startDate = cal.getStartDate();
   cal.setStartDate(null);
   assertNotNull(cal.getStartDate());
   assertSame(startDate, cal.getStartDate());
 }
 @Test
 public void testNewCalendar() {
   DocumentReference calDocRef =
       new DocumentReference(context.getDatabase(), "mySpace", "myCalDoc");
   cal = new Calendar(calDocRef, isArchiv);
   assertEquals(calDocRef, cal.getDocumentReference());
   assertEquals(isArchiv, cal.isArchive());
 }
 @Test
 public void testGetStartDate() {
   Date startDateBefore = new Date();
   cal = new Calendar(calDocRef, isArchiv);
   Date startDateAfter = new Date();
   assertTrue(startDateBefore.compareTo(cal.getStartDate()) <= 0);
   assertTrue(startDateAfter.compareTo(cal.getStartDate()) >= 0);
 }
 @Test
 public void testSetStartDate() {
   Date startDate = cal.getStartDate();
   Date newStartDate = new Date();
   cal.setStartDate(newStartDate);
   assertNotNull(cal.getStartDate());
   assertNotSame(startDate, cal.getStartDate());
   assertSame(newStartDate, cal.getStartDate());
 }
Beispiel #6
0
 @Test
 public void today() {
   try {
     Calendar today = Calendar.getInstance();
     beginOfDay(today);
     assertTrue(sufficientlyEqual(DynamicDate.getInstance("today"), today.getTime()));
   } catch (Exception e) {
     fail(e.getMessage());
   }
 }
 @Before
 public void setUp_CalendarTest() throws Exception {
   eventList = new ArrayList<EventApi>();
   context = getContext();
   xwiki = createMock(XWiki.class);
   context.setWiki(xwiki);
   calDocRef = new DocumentReference(context.getDatabase(), "MyCalSpace", "MyCalDoc");
   cal = new Calendar(calDocRef, isArchiv);
   calUtils = createMock(CalendarUtils.class);
   cal.setCalendarUtils(calUtils);
   eventMgrMock = createMock(IEventManager.class);
   cal.inject_getEventCmd(eventMgrMock);
 }
  @Test
  public void testConvertStringToTimestamp() throws Exception {
    final Date today = new Date();
    final Calendar todayCalendar = new GregorianCalendar();
    todayCalendar.setTime(today);
    final String datePart = DateUtil.convertDateToString(today);

    final Timestamp time = (Timestamp) converter.convert(Timestamp.class, datePart + " 01:02:03.4");
    final Calendar cal = new GregorianCalendar();
    cal.setTimeInMillis(time.getTime());
    assertEquals(todayCalendar.get(Calendar.YEAR), cal.get(Calendar.YEAR));
    assertEquals(todayCalendar.get(Calendar.MONTH), cal.get(Calendar.MONTH));
    assertEquals(todayCalendar.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH));
  }
Beispiel #9
0
 @Test
 public void shouldGetEventPartiallyMatchingDay() {
   Date startDate = firstUser.parseStringToDate("23.09.11 17:00");
   Date endDate = firstUser.parseStringToDate("24.09.11 18:00");
   Date startDate2 = firstUser.parseStringToDate("24.09.11 17:00");
   Date endDate2 = firstUser.parseStringToDate("25.09.11 18:00");
   Event event = new Event("event1", startDate, endDate, true);
   Event event2 = new Event("event2", startDate2, endDate2, true);
   firstCalendar.addEvent(event);
   firstCalendar.addEvent(event2);
   Date testDay = secondUser.parseStringToDate("24.09.11 13:30");
   eventsVisibleToSecondUser = secondUser.getVisibleEventsOnSpecificDayFrom(firstUser, testDay);
   assertTrue(eventsVisibleToSecondUser.contains(event));
   assertTrue(eventsVisibleToSecondUser.contains(event2));
 }
 @Test
 public void testGetNrOfEvents_nonEmptyList() throws XWikiException {
   ArrayList<Long> eventList = new ArrayList<Long>();
   eventList.add(123l);
   DocumentReference cal2DocRef =
       new DocumentReference(context.getDatabase(), "MyCalDoc2Space", "MyCal2Doc");
   Calendar cal2 = new Calendar(cal2DocRef, isArchiv);
   cal2.setCalendarUtils(calUtils);
   cal2.inject_getEventCmd(eventMgrMock);
   expect(eventMgrMock.countEvents(eq(cal2DocRef), eq(isArchiv), eq(cal2.getStartDate())))
       .andReturn(123l);
   replayAll();
   long numEvents = cal2.getNrOfEvents();
   verifyAll();
   assertEquals("Expecting size of eventList.", 123l, numEvents);
 }
  @Test
  public void testAddBirthdayNotification() {
    FacePamphletProfile test = new FacePamphletProfile("Test Profile");
    FacePamphletProfile jimmy = new FacePamphletProfile("Jimmy");

    Calendar currentDate = Calendar.getInstance();
    SimpleDateFormat formatter = new SimpleDateFormat("MM/dd");
    String dateNow = formatter.format(currentDate.getTime());

    jimmy.setBirthday(12, 4);

    test.addFriend(jimmy);
    test.addBirthdayNotifications();

    assertTrue(test.getNotifications().contains("Jimmy's birthday is coming up on 12/4!!"));
  }
 @Test
 public void testIsArchive() {
   assertEquals(
       "isArchive must return the isArchive value given in " + "the constructor call",
       isArchiv,
       cal.isArchive());
 }
 @Test
 public void testGetNrOfEvents_emptyList() {
   expect(eventMgrMock.countEvents(eq(calDocRef), eq(false), isA(Date.class))).andReturn(0L);
   replayAll();
   assertEquals("must be zero for empty list.", 0, cal.getNrOfEvents());
   verifyAll();
 }
 @Test
 public void testConvertNotSupported() throws Exception {
   final Calendar cal = new GregorianCalendar(2005, 0, 16);
   try {
     converter.convert(Object.class, cal.getTime());
     fail("Object.class is not supported");
   } catch (final Exception e) {
     // expected
   }
   try {
     converter.convertToDate(Object.class, cal.getTime(), "");
     fail("Object.class is not supported");
   } catch (final Exception e) {
     // expected
   }
 }
  @Test
  public void testConvertStringToDate() throws Exception {
    final Date today = new Date();
    final Calendar todayCalendar = new GregorianCalendar();
    todayCalendar.setTime(today);
    final String datePart = DateUtil.convertDateToString(today);
    // test empty time
    Date date = (Date) converter.convert(Date.class, "");
    assertNull(date);
    date = (Date) converter.convert(Date.class, datePart);

    final Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    assertEquals(todayCalendar.get(Calendar.YEAR), cal.get(Calendar.YEAR));
    assertEquals(todayCalendar.get(Calendar.MONTH), cal.get(Calendar.MONTH));
    assertEquals(todayCalendar.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH));
  }
  @Test
  public void testDecodeQualificationForXML() throws IOException {
    assumeTrue(TestUtil.testdataAvailable());

    Date startDate = Calendar.getInstance().getTime();
    DecodeQualification decodeQualification =
        plugIn.getDecodeQualification(
            TestUtil.getTestFile(productsFolder + "dimap/test_ST4_MT.xml"));
    assertEquals(DecodeQualification.UNABLE, decodeQualification);
    decodeQualification =
        plugIn.getDecodeQualification(
            TestUtil.getTestFile(productsFolder + "SPOT4_HRVIR1_XS_88888888_N1A.tgz"));
    assertEquals(DecodeQualification.INTENDED, decodeQualification);
    Date endDate = Calendar.getInstance().getTime();
    assertTrue(
        "The decoding time for the file is too big!",
        (endDate.getTime() - startDate.getTime()) / 1000 < 30); // 30 sec
  }
 @Test
 public void testGetAllEvents_informationHidingSecurity() throws XWikiException {
   List<EventApi> list = Collections.emptyList();
   expect(eventMgrMock.getEvents(same(cal), eq(0), eq(0))).andReturn(list).once();
   replayAll();
   List<EventApi> events = cal.getAllEvents();
   verifyAll();
   assertNotSame("getAllEvents may not leak internal data references.", eventList, events);
 }
 @Test
 @Deprecated
 public void testNewCalendar_deprecated_constructor() {
   DocumentReference calDocRef =
       new DocumentReference(context.getDatabase(), "mySpace", "myCalDoc");
   XWikiDocument calDoc = new XWikiDocument(calDocRef);
   cal = new Calendar(calDoc, isArchiv, context);
   assertEquals(calDocRef, cal.getDocumentReference());
 }
Beispiel #19
0
 @Test
 public void shouldGetEventsOverMultipleDays() {
   Date startDate = firstUser.parseStringToDate("22.09.11 17:00");
   Date endDate = firstUser.parseStringToDate("26.09.11 18:00");
   Event event = new Event("event", startDate, endDate, true);
   firstCalendar.addEvent(event);
   Date testDay = secondUser.parseStringToDate("24.09.11 13:30");
   eventsVisibleToSecondUser = secondUser.getVisibleEventsOnSpecificDayFrom(firstUser, testDay);
   assertTrue(eventsVisibleToSecondUser.contains(event));
 }
Beispiel #20
0
 @Test
 public void shouldNotGetPrivateEvent() {
   Date startDate = firstUser.parseStringToDate("23.09.11 18:00");
   Date endDate = firstUser.parseStringToDate("30.09.11 17:00");
   Event event = new Event("event", startDate, endDate, false);
   firstCalendar.addEvent(event);
   Date testDay = secondUser.parseStringToDate("24.09.11 13:30");
   eventsVisibleToSecondUser = secondUser.getVisibleEventsOnSpecificDayFrom(firstUser, testDay);
   assertFalse(eventsVisibleToSecondUser.contains(event));
 }
 @Test
 public void testGetEvents_illegalStartValue() throws XWikiException {
   ArrayList<EventApi> eventList = new ArrayList<EventApi>();
   IEvent event = createMock(IEvent.class);
   event.setLanguage(eq("de"));
   expectLastCall().once();
   DocumentReference cal2DocRef =
       new DocumentReference(context.getDatabase(), "MyCalDoc2Space", "MyCal2Doc");
   Calendar cal2 = new Calendar(cal2DocRef, isArchiv);
   cal2.setCalendarUtils(calUtils);
   cal2.inject_getEventCmd(eventMgrMock);
   expect(eventMgrMock.getEvents(same(cal2), eq(5), eq(1))).andReturn(eventList);
   replayAll(event);
   eventList.add(new EventApi(event, context));
   int start = 5;
   int nb = 1;
   List<EventApi> events = cal2.getEvents(start, nb);
   verifyAll(event);
   assertEquals("Expecting to get the full eventlist", eventList, events);
 }
 private Date getNewDate(int increment) throws ParseException {
   SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
   Calendar c = Calendar.getInstance();
   c.setTimeZone(TimeZone.getTimeZone("GMT"));
   c.setTime(sdf.parse(START_DATE));
   c.add(Calendar.DATE, increment);
   return c.getTime();
 }
  @Before
  public void setUp() {
    controller = new Controller(35.0);
    Calendar cal = Calendar.getInstance();
    cal.set(2012, Calendar.JANUARY, 1, 1, 1, 0);

    Date d1, d2;
    d1 = cal.getTime();
    t1 = d1.getTime();

    cal.set(2012, Calendar.JANUARY, 1, 1, 1, 2);
    d2 = cal.getTime();
    t2 = d2.getTime();
  }
Beispiel #24
0
 protected Collection compare(Date date, int[] fields) {
   List result = new ArrayList();
   Calendar cal = Calendar.getInstance();
   cal.setLenient(true);
   cal.setTime(date);
   if (fields[0] != IGN && cal.get(Calendar.YEAR) != fields[0])
     result.add("year " + cal.get(Calendar.YEAR) + " != " + fields[0]);
   if (fields[1] != IGN && cal.get(Calendar.MONTH) != fields[1])
     result.add("month " + cal.get(Calendar.MONTH) + " != " + fields[1]);
   if (fields[2] != IGN && cal.get(Calendar.DAY_OF_MONTH) != fields[2])
     result.add("day of month " + cal.get(Calendar.DAY_OF_MONTH) + " != " + fields[2]);
   if (fields[3] != IGN && cal.get(Calendar.HOUR_OF_DAY) != fields[3])
     result.add("hour of day " + cal.get(Calendar.HOUR_OF_DAY) + " != " + fields[3]);
   if (fields[4] != IGN && cal.get(Calendar.MINUTE) != fields[4])
     result.add("minute " + cal.get(Calendar.MINUTE) + " != " + fields[4]);
   if (fields[5] != IGN && cal.get(Calendar.SECOND) != fields[5])
     result.add("second " + cal.get(Calendar.SECOND) + " != " + fields[5]);
   return result;
 }
Beispiel #25
0
  protected int[] getNow(int[] n) {
    Calendar cal = Calendar.getInstance();
    if (n[0] != NULL && n[0] != IGN) cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + n[0]);
    if (n[1] != NULL && n[1] != IGN) cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + n[1]);
    if (n[2] != NULL && n[2] != IGN)
      cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) + n[2]);
    if (n[3] != NULL && n[3] != IGN)
      cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) + n[3]);
    if (n[4] != NULL && n[4] != IGN) cal.set(Calendar.MINUTE, cal.get(Calendar.MINUTE) + n[4]);
    if (n[5] != NULL && n[5] != IGN) cal.set(Calendar.SECOND, cal.get(Calendar.SECOND) + n[5]);

    return new int[] {
      n[0] == NULL ? 0 : (n[0] == IGN ? IGN : cal.get(Calendar.YEAR)),
      n[1] == NULL ? 0 : (n[1] == IGN ? IGN : cal.get(Calendar.MONTH)),
      n[2] == NULL ? 0 : (n[2] == IGN ? IGN : cal.get(Calendar.DAY_OF_MONTH)),
      n[3] == NULL ? 0 : (n[3] == IGN ? IGN : cal.get(Calendar.HOUR_OF_DAY)),
      n[4] == NULL ? 0 : (n[4] == IGN ? IGN : cal.get(Calendar.MINUTE)),
      n[5] == NULL ? 0 : (n[5] == IGN ? IGN : cal.get(Calendar.SECOND))
    };
  }
 @Test
 public void testConvertDateToString() throws Exception {
   final Calendar cal = new GregorianCalendar(2005, 0, 16);
   final String date = (String) converter.convert(String.class, cal.getTime());
   assertEquals(DateUtil.convertDateToString(cal.getTime()), date);
 }
Beispiel #27
0
 protected void beginOfDay(Calendar cal) {
   cal.set(Calendar.MILLISECOND, 0);
   cal.set(Calendar.SECOND, 0);
   cal.set(Calendar.MINUTE, 0);
   cal.set(Calendar.HOUR_OF_DAY, 0);
 }