コード例 #1
1
 @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);
 }
コード例 #2
0
 @Test
 public void testSetStartDate_null() {
   Date startDate = cal.getStartDate();
   cal.setStartDate(null);
   assertNotNull(cal.getStartDate());
   assertSame(startDate, cal.getStartDate());
 }
コード例 #3
0
 @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());
 }
コード例 #4
0
 @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);
 }
コード例 #5
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());
 }
コード例 #6
0
ファイル: DateParserTest.java プロジェクト: mihxil/mmutil
 @Test
 public void today() {
   try {
     Calendar today = Calendar.getInstance();
     beginOfDay(today);
     assertTrue(sufficientlyEqual(DynamicDate.getInstance("today"), today.getTime()));
   } catch (Exception e) {
     fail(e.getMessage());
   }
 }
コード例 #7
0
 @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);
 }
コード例 #8
0
  @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));
  }
コード例 #9
0
ファイル: UserTest.java プロジェクト: rathrio/ese2011-warmup
 @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));
 }
コード例 #10
0
 @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);
 }
コード例 #11
0
  @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!!"));
  }
コード例 #12
0
 @Test
 public void testIsArchive() {
   assertEquals(
       "isArchive must return the isArchive value given in " + "the constructor call",
       isArchiv,
       cal.isArchive());
 }
コード例 #13
0
 @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();
 }
コード例 #14
0
 @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
   }
 }
コード例 #15
0
  @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));
  }
コード例 #16
0
  @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
  }
コード例 #17
0
 @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);
 }
コード例 #18
0
 @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());
 }
コード例 #19
0
ファイル: UserTest.java プロジェクト: rathrio/ese2011-warmup
 @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));
 }
コード例 #20
0
ファイル: UserTest.java プロジェクト: rathrio/ese2011-warmup
 @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));
 }
コード例 #21
0
 @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);
 }
コード例 #22
0
 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();
 }
コード例 #23
0
  @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();
  }
コード例 #24
0
ファイル: DateParserTest.java プロジェクト: mihxil/mmutil
 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;
 }
コード例 #25
0
ファイル: DateParserTest.java プロジェクト: mihxil/mmutil
  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))
    };
  }
コード例 #26
0
 @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);
 }
コード例 #27
0
ファイル: DateParserTest.java プロジェクト: mihxil/mmutil
 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);
 }