@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); }
@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 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 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); }