listRequest = getOrCreateCalendarInterface(authData).calendarList().list();
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(); } }
@Override public void checkCalendarSyncSettings(CalendarSettings calendarSettings) { googleCalendarClient = getOrCreateGoogleCalendarClient(); if (googleCalendarClient != null) { String calendarId = settingsService.getSettings().getCalendarSettings().getGoogleCalendarSettings().getCalendarId(); try { HttpResponse httpResponse = googleCalendarClient.calendarList().get(calendarId).executeUsingHead(); if (httpResponse.getStatusCode() == SC_OK) { LOG.info("Calendar sync successfully activated!"); } else { throw new IOException(httpResponse.getStatusMessage()); } } catch (IOException e) { LOG.warn(String.format("Could not connect to calendar with calendar id '%s'", calendarId), e); } } }
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); }
verify(calendarCalendarList).list(); verify(calendarListRequest).execute();
@Before public void setup() throws IOException { calendarClient = mock(Calendar.class); calendarCalendars = mock(Calendar.Calendars.class); calendarCalendarList = mock(Calendar.CalendarList.class); calendarListRequest = mock(Calendar.CalendarList.List.class); calendarEvents = mock(Calendar.Events.class); eventListRequest = mock(Calendar.Events.List.class); credentialFactory = mock(GoogleCredentialFactory.class); googleCalendarExporter = new GoogleCalendarExporter(credentialFactory, calendarClient); when(calendarClient.calendars()).thenReturn(calendarCalendars); when(calendarClient.calendarList()).thenReturn(calendarCalendarList); when(calendarCalendarList.list()).thenReturn(calendarListRequest); when(calendarClient.events()).thenReturn(calendarEvents); when(calendarEvents.list(CALENDAR_ID)).thenReturn(eventListRequest); when(eventListRequest.setMaxAttendees(MAX_ATTENDEES)).thenReturn(eventListRequest); verifyZeroInteractions(credentialFactory); }