if (listResult.getNextPageToken() != null) { nextPageData = new StringPaginationToken(CALENDAR_TOKEN_PREFIX + listResult.getNextPageToken()); List<CalendarModel> calendarModels = new ArrayList<>(listResult.getItems().size()); for (CalendarListEntry calendarData : listResult.getItems()) { CalendarModel model = convertToCalendarModel(calendarData); continuationData.addContainerResource(new IdOnlyContainerResource(calendarData.getId()));
/** Sets up a response with a single calendar, containing a single event */ private void setUpSingleCalendarResponse() throws IOException { setUpSingleEventResponse(); calendarListResponse = new CalendarList().setItems(Collections.singletonList(CALENDAR_LIST_ENTRY)); when(calendarListRequest.execute()).thenReturn(calendarListResponse); }
@Test public void exportCalendarSubsequentSet() throws IOException { setUpSingleCalendarResponse(); // Looking at subsequent page, with no page after it PaginationData paginationData = new StringPaginationToken(CALENDAR_TOKEN_PREFIX + NEXT_TOKEN); ExportInformation exportInformation = new ExportInformation(paginationData, null); calendarListResponse.setNextPageToken(null); // Run test ExportResult<CalendarContainerResource> result = googleCalendarExporter.export(UUID.randomUUID(), null, Optional.of(exportInformation)); // Check results // Verify correct calls were made InOrder inOrder = Mockito.inOrder(calendarListRequest); inOrder.verify(calendarListRequest).setPageToken(NEXT_TOKEN); inOrder.verify(calendarListRequest).execute(); // Check pagination token ContinuationData continuationData = (ContinuationData) result.getContinuationData(); StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData(); assertThat(paginationToken).isNull(); }
@Before public void setUp() { try { CalendarList calendarListModel = new com.google.api.services.calendar.model.CalendarList(); when(client.calendars()).thenReturn(calendars); when(calendars.insert(anyObject())).thenReturn(calendarsInsert); when(calendarsInsert.execute()).thenReturn(new com.google.api.services.calendar.model.Calendar()); when(client.calendarList()).thenReturn(calendarsList); when(calendarsList.list()).thenReturn(calendarsListList); when(calendarsListList.execute()).thenReturn(calendarListModel); when(auth.getAuthorizedCalendar(anyString(), anyString())).thenReturn(client); when(client.events()).thenReturn(clientEvents); when(clientEvents.insert(anyString(), anyObject())).thenReturn(calendarEventsInsert); when(calendarEventsInsert.execute()).thenReturn(new com.google.api.services.calendar.model.Event()); when(clientEvents.list(anyString())).thenReturn(calendarEventsList); when(calendarEventsList.execute()).thenReturn(new com.google.api.services.calendar.model.Events()); } catch (Exception e) { fail(e.getMessage()); } }
private String getCalendarId(final String name) throws IOException { final CalendarList feed = client.calendarList().list().execute(); if (feed.getItems() != null) { for (final CalendarListEntry entry : feed.getItems()) { if (entry.getSummary().equals(name)) { return entry.getId(); } } } return null; }
calendarListResponse.setNextPageToken(NEXT_TOKEN);