listResult = listRequest.execute(); } catch (IOException e) { return new ExportResult<>(e);
/** 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); }
verify(calendarListRequest).execute();
calendars = client.calendarList().list().execute();
@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()); } }
@Override @SuppressWarnings("PMD.AvoidCatchingGenericException") protected Result verifyConnectivity(Map<String, Object> parameters) { ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY); try { GoogleCalendarStreamConfiguration configuration = setProperties(new GoogleCalendarStreamConfiguration(), parameters); GoogleCalendarClientFactory clientFactory = new BatchGoogleCalendarClientFactory(); Calendar client = clientFactory.makeClient(configuration.getClientId(), configuration.getClientSecret(), configuration.getScopes(), configuration.getApplicationName(), configuration.getRefreshToken(), configuration.getAccessToken(), null, null, "me"); client.calendarList().list().execute(); } catch (Exception e) { ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, e.getMessage()) .detail("google_calendar_exception", e.getMessage()).detail(VerificationError.ExceptionAttribute.EXCEPTION_CLASS, e.getClass().getName()) .detail(VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE, e); builder.error(errorBuilder.build()); } return builder.build(); } }
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; }
private static void showCalendars() throws IOException { View.header("Show Calendars"); CalendarList feed = client.calendarList().list().execute(); View.display(feed); }
@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(); }