コード例 #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
 @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);
 }
コード例 #7
0
 @Test
 public void testIsArchive() {
   assertEquals(
       "isArchive must return the isArchive value given in " + "the constructor call",
       isArchiv,
       cal.isArchive());
 }
コード例 #8
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);
 }
コード例 #9
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();
 }
コード例 #10
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);
 }
コード例 #11
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());
 }
コード例 #12
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);
 }