CAMEL-8050 - google calendar component
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d3589e83 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d3589e83 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d3589e83 Branch: refs/heads/master Commit: d3589e8382a6ceab36dad0fc068505ca1427d02b Parents: 4b1725b Author: Jonathan Anstey <jans...@gmail.com> Authored: Fri Nov 14 10:59:21 2014 -0330 Committer: Jonathan Anstey <jans...@gmail.com> Committed: Fri Nov 14 14:41:40 2014 -0330 ---------------------------------------------------------------------- components/camel-google-calendar/pom.xml | 259 +++++++++++++++++++ .../BatchGoogleCalendarClientFactory.java | 68 +++++ .../calendar/GoogleCalendarClientFactory.java | 27 ++ .../calendar/GoogleCalendarComponent.java | 74 ++++++ .../calendar/GoogleCalendarConfiguration.java | 100 +++++++ .../google/calendar/GoogleCalendarConsumer.java | 47 ++++ .../google/calendar/GoogleCalendarEndpoint.java | 116 +++++++++ .../google/calendar/GoogleCalendarProducer.java | 48 ++++ .../internal/GoogleCalendarConstants.java | 29 +++ .../GoogleCalendarPropertiesHelper.java | 39 +++ .../org/apache/camel/component/google-calendar | 1 + .../AbstractGoogleCalendarTestSupport.java | 121 +++++++++ .../calendar/CalendarAclIntegrationTest.java | 74 ++++++ .../CalendarCalendarListIntegrationTest.java | 91 +++++++ .../CalendarCalendarsIntegrationTest.java | 89 +++++++ .../calendar/CalendarColorsIntegrationTest.java | 53 ++++ .../calendar/CalendarEventsIntegrationTest.java | 162 ++++++++++++ .../CalendarFreebusyIntegrationTest.java | 70 +++++ .../CalendarSettingsIntegrationTest.java | 68 +++++ .../src/test/resources/log4j.properties | 14 + .../src/test/resources/test-options.properties | 26 ++ parent/pom.xml | 2 +- 22 files changed, 1577 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/pom.xml b/components/camel-google-calendar/pom.xml new file mode 100644 index 0000000..0037924 --- /dev/null +++ b/components/camel-google-calendar/pom.xml @@ -0,0 +1,259 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>components</artifactId> + <version>2.15-SNAPSHOT</version> + </parent> + + <artifactId>camel-google-calendar</artifactId> + <packaging>bundle</packaging> + <name>Camel GoogleCalendar Component</name> + <description>Camel Component for GoogleCalendar</description> + + <properties> + <schemeName>google-calendar</schemeName> + <componentName>GoogleCalendar</componentName> + <componentPackage>org.apache.camel.component.google.calendar</componentPackage> + <outPackage>org.apache.camel.component.google.calendar.internal</outPackage> + <camel.osgi.private.pkg>org.apache.camel.component.google.calendar.internal</camel.osgi.private.pkg> + <camel.osgi.export.pkg>org.apache.camel.component.google.calendar</camel.osgi.export.pkg> + <camel.osgi.export.service> + org.apache.camel.spi.ComponentResolver;component=google-calendar + </camel.osgi.export.service> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core</artifactId> + </dependency> + <dependency> + <groupId>com.google.api-client</groupId> + <artifactId>google-api-client</artifactId> + <version>${google-api-client-version}</version> + </dependency> + <dependency> + <groupId>com.google.oauth-client</groupId> + <artifactId>google-oauth-client-jetty</artifactId> + <version>${google-api-client-version}</version> + </dependency> + <dependency> + <groupId>com.google.http-client</groupId> + <artifactId>google-http-client-jackson2</artifactId> + <version>${google-api-client-version}</version> + </dependency> + <dependency> + <groupId>com.google.apis</groupId> + <artifactId>google-api-services-calendar</artifactId> + <version>v3-rev99-1.19.0</version> + </dependency> + + <!-- Camel annotations in provided scope to avoid compile errors in IDEs --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>spi-annotations</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + + <!-- Component API javadoc in provided scope to read API signatures --> + <dependency> + <groupId>com.google.apis</groupId> + <artifactId>google-api-services-calendar</artifactId> + <version>v3-rev99-1.19.0</version> + <classifier>javadoc</classifier> + <scope>provided</scope> + </dependency> + + <!-- logging --> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <scope>test</scope> + </dependency> + + <!-- testing --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <defaultGoal>install</defaultGoal> + + <plugins> + + <!-- generate Component source and test source --> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-api-component-maven-plugin</artifactId> + <executions> + <execution> + <id>generate-test-component-classes</id> + <goals> + <goal>fromApis</goal> + </goals> + <configuration> + <apis> + <api> + <apiName>acl</apiName> + <proxyClass>com.google.api.services.calendar.Calendar$Acl</proxyClass> + <fromJavadoc /> + </api> + <api> + <apiName>list</apiName> + <proxyClass>com.google.api.services.calendar.Calendar$CalendarList</proxyClass> + <fromJavadoc /> + </api> + <api> + <apiName>calendars</apiName> + <proxyClass>com.google.api.services.calendar.Calendar$Calendars</proxyClass> + <fromJavadoc /> + </api> + <api> + <apiName>channels</apiName> + <proxyClass>com.google.api.services.calendar.Calendar$Channels</proxyClass> + <fromJavadoc /> + </api> + <api> + <apiName>colors</apiName> + <proxyClass>com.google.api.services.calendar.Calendar$Colors</proxyClass> + <fromJavadoc /> + </api> + <api> + <apiName>freebusy</apiName> + <proxyClass>com.google.api.services.calendar.Calendar$Freebusy</proxyClass> + <fromJavadoc /> + </api> + <api> + <apiName>events</apiName> + <proxyClass>com.google.api.services.calendar.Calendar$Events</proxyClass> + <fromJavadoc /> + </api> + <api> + <apiName>settings</apiName> + <proxyClass>com.google.api.services.calendar.Calendar$Settings</proxyClass> + <fromJavadoc /> + </api> + </apis> + <substitutions> + <substitution> + <method>^.+$</method> + <argName>content</argName> + <argType>com.google.api.services.calendar.model.Channel</argType> + <replacement>contentChannel</replacement> + </substitution> + </substitutions> + </configuration> + </execution> + </executions> + </plugin> + + <!-- add generated source and test source to build --> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <version>1.8</version> + <executions> + <execution> + <id>add-generated-sources</id> + <goals> + <goal>add-source</goal> + </goals> + <configuration> + <sources> + <source>${project.build.directory}/generated-sources/camel-component</source> + </sources> + </configuration> + </execution> + <execution> + <id>add-generated-test-sources</id> + <goals> + <goal>add-test-source</goal> + </goals> + <configuration> + <sources> + <source>${project.build.directory}/generated-test-sources/camel-component</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + + </plugins> + + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-api-component-maven-plugin</artifactId> + <version>${project.version}</version> + <configuration> + <scheme>${schemeName}</scheme> + <componentName>${componentName}</componentName> + <componentPackage>${componentPackage}</componentPackage> + <outPackage>${outPackage}</outPackage> + </configuration> + </plugin> + </plugins> + </pluginManagement> + + </build> + + <reporting> + <plugins> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-api-component-maven-plugin</artifactId> + <version>${project.version}</version> + <configuration> + <scheme>${schemeName}</scheme> + <componentName>${componentName}</componentName> + <componentPackage>${componentPackage}</componentPackage> + <outPackage>${outPackage}</outPackage> + </configuration> + </plugin> + </plugins> + </reporting> + + <profiles> + <profile> + <id>google-calendar-test</id> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <childDelegation>false</childDelegation> + <useFile>true</useFile> + <forkMode>once</forkMode> + <forkedProcessTimeoutInSeconds>300</forkedProcessTimeoutInSeconds> + <excludes> + <exclude>**/*XXXTest.java</exclude> + </excludes> + <includes> + <include>**/*Test.java</include> + </includes> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> + +</project> http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/BatchGoogleCalendarClientFactory.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/BatchGoogleCalendarClientFactory.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/BatchGoogleCalendarClientFactory.java new file mode 100644 index 0000000..34577fd --- /dev/null +++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/BatchGoogleCalendarClientFactory.java @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.google.calendar; + +import java.util.Collection; + +import com.google.api.client.auth.oauth2.Credential; +import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; +import com.google.api.client.http.javanet.NetHttpTransport; +import com.google.api.client.json.jackson2.JacksonFactory; +import com.google.api.services.calendar.Calendar; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BatchGoogleCalendarClientFactory implements GoogleCalendarClientFactory { + private static final Logger LOG = LoggerFactory.getLogger(BatchGoogleCalendarClientFactory.class); + private NetHttpTransport transport; + private JacksonFactory jsonFactory; + + public BatchGoogleCalendarClientFactory() { + this.transport = new NetHttpTransport(); + this.jsonFactory = new JacksonFactory(); + } + + @Override + public Calendar makeClient(String clientId, String clientSecret, Collection<String> scopes, String applicationName, String refreshToken, String accessToken) { + Credential credential; + try { + credential = authorize(clientId, clientSecret, scopes); + + if (refreshToken != null && !"".equals(refreshToken)) { + credential.setRefreshToken(refreshToken); + } + if (accessToken != null && !"".equals(accessToken)) { + credential.setAccessToken(accessToken); + } + return new Calendar.Builder(transport, jsonFactory, credential).setApplicationName(applicationName).build(); + } catch (Exception e) { + LOG.error("Could not create Google Drive client.", e); + } + return null; + } + + // Authorizes the installed application to access user's protected data. + private Credential authorize(String clientId, String clientSecret, Collection<String> scopes) throws Exception { + // authorize + return new GoogleCredential.Builder() + .setJsonFactory(jsonFactory) + .setTransport(transport) + .setClientSecrets(clientId, clientSecret) + .build(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarClientFactory.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarClientFactory.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarClientFactory.java new file mode 100644 index 0000000..5f4dd30 --- /dev/null +++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarClientFactory.java @@ -0,0 +1,27 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.google.calendar; + +import java.util.Collection; + +import com.google.api.services.calendar.Calendar; + +public interface GoogleCalendarClientFactory { + + Calendar makeClient(String clientId, String clientSecret, Collection<String> scopes, String applicationName, String refreshToken, String accessToken); + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarComponent.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarComponent.java new file mode 100644 index 0000000..c5fe412 --- /dev/null +++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarComponent.java @@ -0,0 +1,74 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.google.calendar; + +import com.google.api.services.calendar.Calendar; + +import org.apache.camel.CamelContext; +import org.apache.camel.Endpoint; +import org.apache.camel.component.google.calendar.internal.GoogleCalendarApiCollection; +import org.apache.camel.component.google.calendar.internal.GoogleCalendarApiName; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.util.component.AbstractApiComponent; + +/** + * Represents the component that manages {@link GoogleCalendarEndpoint}. + */ +@UriEndpoint(scheme = "google-calendar", consumerClass = GoogleCalendarConsumer.class, consumerPrefix = "consumer") +public class GoogleCalendarComponent extends AbstractApiComponent<GoogleCalendarApiName, GoogleCalendarConfiguration, GoogleCalendarApiCollection> { + + private Calendar client; + private GoogleCalendarClientFactory clientFactory; + + public GoogleCalendarComponent() { + super(GoogleCalendarEndpoint.class, GoogleCalendarApiName.class, GoogleCalendarApiCollection.getCollection()); + } + + public GoogleCalendarComponent(CamelContext context) { + super(context, GoogleCalendarEndpoint.class, GoogleCalendarApiName.class, GoogleCalendarApiCollection.getCollection()); + } + + @Override + protected GoogleCalendarApiName getApiName(String apiNameStr) throws IllegalArgumentException { + return GoogleCalendarApiName.fromValue(apiNameStr); + } + + public Calendar getClient() { + if (client == null) { + client = getClientFactory().makeClient(configuration.getClientId(), configuration.getClientSecret(), configuration.getScopes(), + configuration.getApplicationName(), configuration.getRefreshToken(), configuration.getAccessToken()); + } + return client; + } + + public GoogleCalendarClientFactory getClientFactory() { + if (clientFactory == null) { + clientFactory = new BatchGoogleCalendarClientFactory(); + } + return clientFactory; + } + + public void setClientFactory(GoogleCalendarClientFactory clientFactory) { + this.clientFactory = clientFactory; + } + + @Override + protected Endpoint createEndpoint(String uri, String methodName, GoogleCalendarApiName apiName, + GoogleCalendarConfiguration endpointConfiguration) { + return new GoogleCalendarEndpoint(uri, this, apiName, methodName, endpointConfiguration); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarConfiguration.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarConfiguration.java new file mode 100644 index 0000000..c31c89b --- /dev/null +++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarConfiguration.java @@ -0,0 +1,100 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.google.calendar; + +import java.util.Arrays; +import java.util.List; + +import com.google.api.services.calendar.CalendarScopes; + +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriParams; + +/** + * Component configuration for GoogleCalendar component. + */ +@UriParams +public class GoogleCalendarConfiguration { + private static final List<String> DEFAULT_SCOPES = Arrays.asList(CalendarScopes.CALENDAR); + + @UriParam + private List<String> scopes = DEFAULT_SCOPES; + + @UriParam + private String clientId; + + @UriParam + private String clientSecret; + + @UriParam + private String accessToken; + + @UriParam + private String refreshToken; + + @UriParam + private String applicationName; + + public String getClientId() { + return clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getClientSecret() { + return clientSecret; + } + + public void setClientSecret(String clientSecret) { + this.clientSecret = clientSecret; + } + + public String getAccessToken() { + return accessToken; + } + + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + + public String getRefreshToken() { + return refreshToken; + } + + public void setRefreshToken(String refreshToken) { + this.refreshToken = refreshToken; + } + + public String getApplicationName() { + return applicationName; + } + + public void setApplicationName(String applicationName) { + this.applicationName = applicationName; + } + + public List<String> getScopes() { + return scopes; + } + + public void setScopes(List<String> scopes) { + this.scopes = scopes; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarConsumer.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarConsumer.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarConsumer.java new file mode 100644 index 0000000..bfaaca4 --- /dev/null +++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarConsumer.java @@ -0,0 +1,47 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.google.calendar; + +import java.io.IOException; +import java.util.Map; + +import com.google.api.client.googleapis.services.AbstractGoogleClientRequest; + +import org.apache.camel.Processor; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.component.google.calendar.internal.GoogleCalendarApiName; +import org.apache.camel.util.component.AbstractApiConsumer; + +/** + * The GoogleCalendar consumer. + */ +public class GoogleCalendarConsumer extends AbstractApiConsumer<GoogleCalendarApiName, GoogleCalendarConfiguration> { + + public GoogleCalendarConsumer(GoogleCalendarEndpoint endpoint, Processor processor) { + super(endpoint, processor); + } + + @Override + protected Object doInvokeMethod(Map<String, Object> properties) throws RuntimeCamelException { + AbstractGoogleClientRequest request = (AbstractGoogleClientRequest) super.doInvokeMethod(properties); + try { + return request.execute(); + } catch (IOException e) { + throw new RuntimeCamelException(e); + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarEndpoint.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarEndpoint.java new file mode 100644 index 0000000..317eb16 --- /dev/null +++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarEndpoint.java @@ -0,0 +1,116 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.google.calendar; + +import java.util.Map; + +import com.google.api.services.calendar.Calendar; + +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.component.google.calendar.internal.GoogleCalendarApiCollection; +import org.apache.camel.component.google.calendar.internal.GoogleCalendarApiName; +import org.apache.camel.component.google.calendar.internal.GoogleCalendarConstants; +import org.apache.camel.component.google.calendar.internal.GoogleCalendarPropertiesHelper; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.util.component.AbstractApiEndpoint; +import org.apache.camel.util.component.ApiMethod; +import org.apache.camel.util.component.ApiMethodPropertiesHelper; + +/** + * Represents a GoogleCalendar endpoint. + */ +@UriEndpoint(scheme = "google-calendar", consumerClass = GoogleCalendarConsumer.class, consumerPrefix = "consumer") +public class GoogleCalendarEndpoint extends AbstractApiEndpoint<GoogleCalendarApiName, GoogleCalendarConfiguration> { + + private Object apiProxy; + + public GoogleCalendarEndpoint(String uri, GoogleCalendarComponent component, + GoogleCalendarApiName apiName, String methodName, GoogleCalendarConfiguration endpointConfiguration) { + super(uri, component, apiName, methodName, GoogleCalendarApiCollection.getCollection().getHelper(apiName), endpointConfiguration); + + } + + @Override + public Producer createProducer() throws Exception { + return new GoogleCalendarProducer(this); + } + + @Override + public Consumer createConsumer(Processor processor) throws Exception { + // make sure inBody is not set for consumers + if (inBody != null) { + throw new IllegalArgumentException("Option inBody is not supported for consumer endpoint"); + } + final GoogleCalendarConsumer consumer = new GoogleCalendarConsumer(this, processor); + // also set consumer.* properties + configureConsumer(consumer); + return consumer; + } + + @Override + protected ApiMethodPropertiesHelper<GoogleCalendarConfiguration> getPropertiesHelper() { + return GoogleCalendarPropertiesHelper.getHelper(); + } + + @Override + protected String getThreadProfileName() { + return GoogleCalendarConstants.THREAD_PROFILE_NAME; + } + + @Override + protected void afterConfigureProperties() { + switch (apiName) { + case LIST: + apiProxy = getClient().calendarList(); + break; + case ACL: + apiProxy = getClient().acl(); + break; + case CALENDARS: + apiProxy = getClient().calendars(); + break; + case CHANNELS: + apiProxy = getClient().channels(); + break; + case COLORS: + apiProxy = getClient().colors(); + break; + case EVENTS: + apiProxy = getClient().events(); + break; + case FREEBUSY: + apiProxy = getClient().freebusy(); + break; + case SETTINGS: + apiProxy = getClient().settings(); + break; + default: + throw new IllegalArgumentException("Invalid API name " + apiName); + } + } + + public Calendar getClient() { + return ((GoogleCalendarComponent)getComponent()).getClient(); + } + + @Override + public Object getApiProxy(ApiMethod method, Map<String, Object> args) { + return apiProxy; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarProducer.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarProducer.java new file mode 100644 index 0000000..c786bc1 --- /dev/null +++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarProducer.java @@ -0,0 +1,48 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.google.calendar; + +import java.io.IOException; +import java.util.Map; + +import com.google.api.client.googleapis.services.AbstractGoogleClientRequest; + +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.component.google.calendar.internal.GoogleCalendarApiName; +import org.apache.camel.component.google.calendar.internal.GoogleCalendarPropertiesHelper; +import org.apache.camel.util.component.AbstractApiProducer; +import org.apache.camel.util.component.ApiMethod; + +/** + * The GoogleCalendar producer. + */ +public class GoogleCalendarProducer extends AbstractApiProducer<GoogleCalendarApiName, GoogleCalendarConfiguration> { + + public GoogleCalendarProducer(GoogleCalendarEndpoint endpoint) { + super(endpoint, GoogleCalendarPropertiesHelper.getHelper()); + } + + @Override + protected Object doInvokeMethod(ApiMethod method, Map<String, Object> properties) throws RuntimeCamelException { + AbstractGoogleClientRequest request = (AbstractGoogleClientRequest) super.doInvokeMethod(method, properties); + try { + return request.execute(); + } catch (IOException e) { + throw new RuntimeCamelException(e); + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/internal/GoogleCalendarConstants.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/internal/GoogleCalendarConstants.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/internal/GoogleCalendarConstants.java new file mode 100644 index 0000000..b604ad0 --- /dev/null +++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/internal/GoogleCalendarConstants.java @@ -0,0 +1,29 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.google.calendar.internal; + +/** + * Constants for GoogleCalendar component. + */ +public interface GoogleCalendarConstants { + + // suffix for parameters when passed as exchange header properties + String PROPERTY_PREFIX = "CamelGoogleCalendar."; + + // thread profile name for this component + String THREAD_PROFILE_NAME = "CamelGoogleCalendar"; +} http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/internal/GoogleCalendarPropertiesHelper.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/internal/GoogleCalendarPropertiesHelper.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/internal/GoogleCalendarPropertiesHelper.java new file mode 100644 index 0000000..14ff225 --- /dev/null +++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/internal/GoogleCalendarPropertiesHelper.java @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.google.calendar.internal; + +import org.apache.camel.component.google.calendar.GoogleCalendarConfiguration; +import org.apache.camel.util.component.ApiMethodPropertiesHelper; + +/** + * Singleton {@link ApiMethodPropertiesHelper} for GoogleCalendar component. + */ +public final class GoogleCalendarPropertiesHelper extends ApiMethodPropertiesHelper<GoogleCalendarConfiguration> { + + private static GoogleCalendarPropertiesHelper helper; + + private GoogleCalendarPropertiesHelper() { + super(GoogleCalendarConfiguration.class, GoogleCalendarConstants.PROPERTY_PREFIX); + } + + public static synchronized GoogleCalendarPropertiesHelper getHelper() { + if (helper == null) { + helper = new GoogleCalendarPropertiesHelper(); + } + return helper; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/main/resources/META-INF/services/org/apache/camel/component/google-calendar ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/main/resources/META-INF/services/org/apache/camel/component/google-calendar b/components/camel-google-calendar/src/main/resources/META-INF/services/org/apache/camel/component/google-calendar new file mode 100644 index 0000000..8fc7880 --- /dev/null +++ b/components/camel-google-calendar/src/main/resources/META-INF/services/org/apache/camel/component/google-calendar @@ -0,0 +1 @@ +class=org.apache.camel.GoogleCalendarComponent http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/AbstractGoogleCalendarTestSupport.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/AbstractGoogleCalendarTestSupport.java b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/AbstractGoogleCalendarTestSupport.java new file mode 100644 index 0000000..7392776 --- /dev/null +++ b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/AbstractGoogleCalendarTestSupport.java @@ -0,0 +1,121 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.google.calendar; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.Random; + +import com.google.api.services.calendar.model.Calendar; + +import org.apache.camel.CamelContext; +import org.apache.camel.CamelExecutionException; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.util.IntrospectionSupport; +import org.junit.After; +import org.junit.Before; + +/** + * Abstract base class for GoogleCalendar Integration tests generated by Camel + * API component maven plugin. + */ +public class AbstractGoogleCalendarTestSupport extends CamelTestSupport { + + private static final String TEST_OPTIONS_PROPERTIES = "/test-options.properties"; + private Calendar calendar; + + @Before + public void createTestCalendar() { + Calendar calendar = new Calendar(); + Random rand = new Random(); + + calendar.setSummary("camel-calendar-" + rand.nextInt()); + calendar.setTimeZone("America/St_Johns"); + + this.calendar = requestBody("google-calendar://calendars/insert?inBody=content", calendar); + } + + @After + public void deleteTestCalendar() { + try { + if (calendar != null) { + requestBody("google-calendar://calendars/delete?inBody=calendarId", getCalendar().getId()); + setCalendar(null); + } + } catch (Exception e) { + } + } + + @Override + protected CamelContext createCamelContext() throws Exception { + + final CamelContext context = super.createCamelContext(); + + // read GoogleCalendar component configuration from + // TEST_OPTIONS_PROPERTIES + final Properties properties = new Properties(); + try { + properties.load(getClass().getResourceAsStream(TEST_OPTIONS_PROPERTIES)); + } catch (Exception e) { + throw new IOException(String.format("%s could not be loaded: %s", TEST_OPTIONS_PROPERTIES, e.getMessage()), e); + } + + Map<String, Object> options = new HashMap<String, Object>(); + for (Map.Entry<Object, Object> entry : properties.entrySet()) { + options.put(entry.getKey().toString(), entry.getValue()); + } + + final GoogleCalendarConfiguration configuration = new GoogleCalendarConfiguration(); + IntrospectionSupport.setProperties(configuration, options); + + // add GoogleCalendarComponent to Camel context + final GoogleCalendarComponent component = new GoogleCalendarComponent(context); + component.setConfiguration(configuration); + context.addComponent("google-calendar", component); + + return context; + } + + @Override + public boolean isCreateCamelContextPerClass() { + // only create the context once for this class + return true; + } + + @SuppressWarnings("unchecked") + protected <T> T requestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers) throws CamelExecutionException { + return (T) template().requestBodyAndHeaders(endpointUri, body, headers); + } + + @SuppressWarnings("unchecked") + protected <T> T requestBody(String endpoint, Object body) throws CamelExecutionException { + return (T) template().requestBody(endpoint, body); + } + + public Calendar getCalendar() { + if (calendar == null) { + createTestCalendar(); + } + return calendar; + } + + public void setCalendar(Calendar calendar) { + this.calendar = calendar; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarAclIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarAclIntegrationTest.java b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarAclIntegrationTest.java new file mode 100644 index 0000000..6d60527 --- /dev/null +++ b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarAclIntegrationTest.java @@ -0,0 +1,74 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.google.calendar; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.google.calendar.internal.CalendarAclApiMethod; +import org.apache.camel.component.google.calendar.internal.GoogleCalendarApiCollection; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test class for {@link com.google.api.services.calendar.Calendar$Acl} APIs. + */ +public class CalendarAclIntegrationTest extends AbstractGoogleCalendarTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(CalendarAclIntegrationTest.class); + private static final String PATH_PREFIX = GoogleCalendarApiCollection.getCollection().getApiName(CalendarAclApiMethod.class).getName(); + + @Test + public void testList() throws Exception { + // using String message body for single parameter "calendarId" + final com.google.api.services.calendar.model.Acl result = requestBody("direct://LIST", getCalendar().getId()); + + // should have at least one rule (reader, owner, etc.) for the calendar + // or we wouldn't be able to view it! + assertTrue(result.getItems().size() > 0); + LOG.debug("list: " + result); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + // test route for delete + from("direct://DELETE").to("google-calendar://" + PATH_PREFIX + "/delete"); + + // test route for get + from("direct://GET").to("google-calendar://" + PATH_PREFIX + "/get"); + + // test route for insert + from("direct://INSERT").to("google-calendar://" + PATH_PREFIX + "/insert"); + + // test route for list + from("direct://LIST").to("google-calendar://" + PATH_PREFIX + "/list?inBody=calendarId"); + + // test route for patch + from("direct://PATCH").to("google-calendar://" + PATH_PREFIX + "/patch"); + + // test route for update + from("direct://UPDATE").to("google-calendar://" + PATH_PREFIX + "/update"); + + // test route for watch + from("direct://WATCH").to("google-calendar://" + PATH_PREFIX + "/watch"); + + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarCalendarListIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarCalendarListIntegrationTest.java b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarCalendarListIntegrationTest.java new file mode 100644 index 0000000..ac27d44 --- /dev/null +++ b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarCalendarListIntegrationTest.java @@ -0,0 +1,91 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.google.calendar; + + +import com.google.api.services.calendar.model.Calendar; +import com.google.api.services.calendar.model.CalendarList; +import com.google.api.services.calendar.model.CalendarListEntry; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.google.calendar.internal.CalendarCalendarListApiMethod; +import org.apache.camel.component.google.calendar.internal.GoogleCalendarApiCollection; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test class for {@link com.google.api.services.calendar.Calendar$CalendarList} APIs. + */ +public class CalendarCalendarListIntegrationTest extends AbstractGoogleCalendarTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(CalendarCalendarListIntegrationTest.class); + private static final String PATH_PREFIX = GoogleCalendarApiCollection.getCollection().getApiName(CalendarCalendarListApiMethod.class).getName(); + + @Test + public void testCalendarList() throws Exception { + Calendar calendar = getCalendar(); + assertTrue("Test calendar should be in the list", isCalendarInList(calendar)); + + CalendarListEntry calendarFromGet = requestBody("direct://GET", calendar.getId()); + assertTrue(calendar.getId().equals(calendarFromGet.getId())); + } + + protected boolean isCalendarInList(Calendar calendar) { + CalendarList calendarList = requestBody("direct://LIST", null); + + java.util.List<CalendarListEntry> items = calendarList.getItems(); + + boolean found = false; + for (CalendarListEntry calendarListEntry : items) { + if (calendar.getSummary().equals(calendarListEntry.getSummary())) { + found = true; + } + } + return found; + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + // test route for delete + from("direct://DELETE").to("google-calendar://" + PATH_PREFIX + "/delete?inBody=calendarId"); + + // test route for get + from("direct://GET").to("google-calendar://" + PATH_PREFIX + "/get?inBody=calendarId"); + + // test route for insert + from("direct://INSERT").to("google-calendar://" + PATH_PREFIX + "/insert?inBody=content"); + + // test route for list + from("direct://LIST").to("google-calendar://" + PATH_PREFIX + "/list"); + + // test route for patch + from("direct://PATCH").to("google-calendar://" + PATH_PREFIX + "/patch"); + + // test route for update + from("direct://UPDATE").to("google-calendar://" + PATH_PREFIX + "/update"); + + // test route for watch + from("direct://WATCH").to("google-calendar://" + PATH_PREFIX + "/watch?inBody=contentChannel"); + + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarCalendarsIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarCalendarsIntegrationTest.java b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarCalendarsIntegrationTest.java new file mode 100644 index 0000000..baa3a48 --- /dev/null +++ b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarCalendarsIntegrationTest.java @@ -0,0 +1,89 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.google.calendar; + +import java.util.HashMap; +import java.util.Map; + +import com.google.api.services.calendar.model.Calendar; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.google.calendar.internal.CalendarCalendarsApiMethod; +import org.apache.camel.component.google.calendar.internal.GoogleCalendarApiCollection; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test class for {@link com.google.api.services.calendar.Calendar$Calendars} APIs. + */ +public class CalendarCalendarsIntegrationTest extends AbstractGoogleCalendarTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(CalendarCalendarsIntegrationTest.class); + private static final String PATH_PREFIX = GoogleCalendarApiCollection.getCollection().getApiName(CalendarCalendarsApiMethod.class).getName(); + + @Test + public void testCalendars() throws Exception { + Calendar calendar = getCalendar(); + Calendar calendarFromGet = requestBody("direct://GET", calendar.getId()); + assertTrue(calendar.getId().equals(calendarFromGet.getId())); + + final Map<String, Object> headers = new HashMap<String, Object>(); + // parameter type is String + headers.put("CamelGoogleCalendar.calendarId", calendar.getId()); + // parameter type is com.google.api.services.calendar.model.Calendar + headers.put("CamelGoogleCalendar.content", calendar.setDescription("foo")); + + Calendar result = requestBodyAndHeaders("direct://UPDATE", null, headers); + assertTrue("foo".equals(result.getDescription())); + + requestBody("direct://DELETE", calendar.getId()); + try { + calendarFromGet = requestBody("direct://GET", calendar.getId()); + assertTrue("Should have not found deleted calendar.", false); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + // test route for clear + from("direct://CLEAR").to("google-calendar://" + PATH_PREFIX + "/clear?inBody=calendarId"); + + // test route for delete + from("direct://DELETE").to("google-calendar://" + PATH_PREFIX + "/delete?inBody=calendarId"); + + // test route for get + from("direct://GET").to("google-calendar://" + PATH_PREFIX + "/get?inBody=calendarId"); + + // test route for insert + from("direct://INSERT").to("google-calendar://" + PATH_PREFIX + "/insert?inBody=content"); + + // test route for patch + from("direct://PATCH").to("google-calendar://" + PATH_PREFIX + "/patch"); + + // test route for update + from("direct://UPDATE").to("google-calendar://" + PATH_PREFIX + "/update"); + + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarColorsIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarColorsIntegrationTest.java b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarColorsIntegrationTest.java new file mode 100644 index 0000000..cc99355 --- /dev/null +++ b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarColorsIntegrationTest.java @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.google.calendar; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.google.calendar.internal.CalendarColorsApiMethod; +import org.apache.camel.component.google.calendar.internal.GoogleCalendarApiCollection; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test class for {@link com.google.api.services.calendar.Calendar$Colors} APIs. + */ +public class CalendarColorsIntegrationTest extends AbstractGoogleCalendarTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(CalendarColorsIntegrationTest.class); + private static final String PATH_PREFIX = GoogleCalendarApiCollection.getCollection().getApiName(CalendarColorsApiMethod.class).getName(); + + @Test + public void testGet() throws Exception { + com.google.api.services.calendar.model.Colors result = requestBody("direct://GET", null); + + assertNotNull("get result", result); + LOG.debug("get: " + result); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + // test route for get + from("direct://GET").to("google-calendar://" + PATH_PREFIX + "/get"); + + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarEventsIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarEventsIntegrationTest.java b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarEventsIntegrationTest.java new file mode 100644 index 0000000..9d15619 --- /dev/null +++ b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarEventsIntegrationTest.java @@ -0,0 +1,162 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.google.calendar; + +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.TimeZone; + +import com.google.api.client.util.DateTime; +import com.google.api.services.calendar.model.Event; +import com.google.api.services.calendar.model.EventAttendee; +import com.google.api.services.calendar.model.EventDateTime; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.google.calendar.internal.CalendarEventsApiMethod; +import org.apache.camel.component.google.calendar.internal.GoogleCalendarApiCollection; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test class for {@link com.google.api.services.calendar.Calendar$Events} APIs. + */ +public class CalendarEventsIntegrationTest extends AbstractGoogleCalendarTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(CalendarEventsIntegrationTest.class); + private static final String PATH_PREFIX = GoogleCalendarApiCollection.getCollection().getApiName(CalendarEventsApiMethod.class).getName(); + + @Test + public void testInsert() throws Exception { + Event event = new Event(); + + event.setSummary("Feed the Camel"); + event.setLocation("Somewhere"); + + ArrayList<EventAttendee> attendees = new ArrayList<EventAttendee>(); + attendees.add(new EventAttendee().setEmail("camel-google-calendar.jans...@gmail.com")); + event.setAttendees(attendees); + + Date startDate = new Date(); + Date endDate = new Date(startDate.getTime() + 3600000); + DateTime start = new DateTime(startDate, TimeZone.getTimeZone("UTC")); + event.setStart(new EventDateTime().setDateTime(start)); + DateTime end = new DateTime(endDate, TimeZone.getTimeZone("UTC")); + event.setEnd(new EventDateTime().setDateTime(end)); + + final Map<String, Object> headers = new HashMap<String, Object>(); + // parameter type is String + headers.put("CamelGoogleCalendar.calendarId", getCalendar().getId()); + // parameter type is com.google.api.services.calendar.model.Event + headers.put("CamelGoogleCalendar.content", event); + + final com.google.api.services.calendar.model.Event result = requestBodyAndHeaders("direct://INSERT", null, headers); + + assertEquals("Feed the Camel", result.getSummary()); + LOG.debug("insert: " + result); + } + + @Test + public void testManipulatingAnEvent() throws Exception { + // Add an event + Map<String, Object> headers = new HashMap<String, Object>(); + // parameter type is String + headers.put("CamelGoogleCalendar.calendarId", getCalendar().getId()); + // parameter type is String + headers.put("CamelGoogleCalendar.text", "Feed the Camel"); + com.google.api.services.calendar.model.Event result = requestBodyAndHeaders("direct://QUICKADD", null, headers); + assertNotNull("quickAdd result", result); + + // Check if it is in the list of events for this calendar + com.google.api.services.calendar.model.Events events = requestBody("direct://LIST", getCalendar().getId()); + Event item = events.getItems().get(0); + String eventId = item.getId(); + assertEquals("Feed the Camel", item.getSummary()); + + // Get the event metadata + headers = new HashMap<String, Object>(); + // parameter type is String + headers.put("CamelGoogleCalendar.calendarId", getCalendar().getId()); + // parameter type is String + headers.put("CamelGoogleCalendar.eventId", eventId); + result = requestBodyAndHeaders("direct://GET", null, headers); + assertEquals("Feed the Camel", result.getSummary()); + + // Change the event + result.setSummary("Feed the Camel later"); + // parameter type is com.google.api.services.calendar.model.Event + headers.put("CamelGoogleCalendar.content", result); + Event newResult = requestBodyAndHeaders("direct://UPDATE", null, headers); + assertEquals("Feed the Camel later", newResult.getSummary()); + + // Delete the event + headers = new HashMap<String, Object>(); + // parameter type is String + headers.put("CamelGoogleCalendar.calendarId", getCalendar().getId()); + // parameter type is String + headers.put("CamelGoogleCalendar.eventId", eventId); + result = requestBodyAndHeaders("direct://DELETE", null, headers); + + // Check if it is NOT in the list of events for this calendar + events = requestBody("direct://LIST", getCalendar().getId()); + assertEquals(0, events.getItems().size()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + // test route for calendarImport + from("direct://CALENDARIMPORT").to("google-calendar://" + PATH_PREFIX + "/calendarImport"); + + // test route for delete + from("direct://DELETE").to("google-calendar://" + PATH_PREFIX + "/delete"); + + // test route for get + from("direct://GET").to("google-calendar://" + PATH_PREFIX + "/get"); + + // test route for insert + from("direct://INSERT").to("google-calendar://" + PATH_PREFIX + "/insert"); + + // test route for instances + from("direct://INSTANCES").to("google-calendar://" + PATH_PREFIX + "/instances"); + + // test route for list + from("direct://LIST").to("google-calendar://" + PATH_PREFIX + "/list?inBody=calendarId"); + + // test route for move + from("direct://MOVE").to("google-calendar://" + PATH_PREFIX + "/move"); + + // test route for patch + from("direct://PATCH").to("google-calendar://" + PATH_PREFIX + "/patch"); + + // test route for quickAdd + from("direct://QUICKADD").to("google-calendar://" + PATH_PREFIX + "/quickAdd"); + + // test route for update + from("direct://UPDATE").to("google-calendar://" + PATH_PREFIX + "/update"); + + // test route for watch + from("direct://WATCH").to("google-calendar://" + PATH_PREFIX + "/watch"); + + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarFreebusyIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarFreebusyIntegrationTest.java b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarFreebusyIntegrationTest.java new file mode 100644 index 0000000..9bfc5ea --- /dev/null +++ b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarFreebusyIntegrationTest.java @@ -0,0 +1,70 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.google.calendar; + +import java.util.ArrayList; +import java.util.List; + +import com.google.api.client.util.DateTime; +import com.google.api.services.calendar.model.FreeBusyRequest; +import com.google.api.services.calendar.model.FreeBusyRequestItem; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.google.calendar.internal.CalendarFreebusyApiMethod; +import org.apache.camel.component.google.calendar.internal.GoogleCalendarApiCollection; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The class source won't be generated again if the generator MOJO finds it under src/test/java. + */ +public class CalendarFreebusyIntegrationTest extends AbstractGoogleCalendarTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(CalendarFreebusyIntegrationTest.class); + private static final String PATH_PREFIX = GoogleCalendarApiCollection.getCollection().getApiName(CalendarFreebusyApiMethod.class).getName(); + + @Test + public void testQuery() throws Exception { + // using com.google.api.services.calendar.model.FreeBusyRequest message + // body for single parameter "content" + com.google.api.services.calendar.model.FreeBusyRequest request = new FreeBusyRequest(); + List<FreeBusyRequestItem> items = new ArrayList<FreeBusyRequestItem>(); + items.add(new FreeBusyRequestItem().setId(getCalendar().getId())); + request.setItems(items); + + request.setTimeMin(DateTime.parseRfc3339("2014-11-10T20:45:30-00:00")); + request.setTimeMax(DateTime.parseRfc3339("2014-11-10T21:45:30-00:00")); + + final com.google.api.services.calendar.model.FreeBusyResponse result = requestBody("direct://QUERY", request); + + assertNotNull("query result", result); + LOG.debug("query: " + result); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + // test route for query + from("direct://QUERY").to("google-calendar://" + PATH_PREFIX + "/query?inBody=content"); + + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarSettingsIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarSettingsIntegrationTest.java b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarSettingsIntegrationTest.java new file mode 100644 index 0000000..96b958c --- /dev/null +++ b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarSettingsIntegrationTest.java @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.google.calendar; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.google.calendar.internal.CalendarSettingsApiMethod; +import org.apache.camel.component.google.calendar.internal.GoogleCalendarApiCollection; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test class for {@link com.google.api.services.calendar.Calendar$Settings} APIs. + */ +public class CalendarSettingsIntegrationTest extends AbstractGoogleCalendarTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(CalendarSettingsIntegrationTest.class); + private static final String PATH_PREFIX = GoogleCalendarApiCollection.getCollection().getApiName(CalendarSettingsApiMethod.class).getName(); + + @Test + public void testGet() throws Exception { + // using String message body for single parameter "setting" + final com.google.api.services.calendar.model.Setting result = requestBody("direct://GET", "timezone"); + + assertNotNull("get result", result); + LOG.debug("get: " + result); + } + + @Test + public void testList() throws Exception { + final com.google.api.services.calendar.model.Settings result = requestBody("direct://LIST", null); + + assertNotNull("list result", result); + LOG.debug("list: " + result); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + // test route for get + from("direct://GET").to("google-calendar://" + PATH_PREFIX + "/get?inBody=setting"); + + // test route for list + from("direct://LIST").to("google-calendar://" + PATH_PREFIX + "/list"); + + // test route for watch + from("direct://WATCH").to("google-calendar://" + PATH_PREFIX + "/watch?inBody=contentChannel"); + + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/test/resources/log4j.properties b/components/camel-google-calendar/src/test/resources/log4j.properties new file mode 100644 index 0000000..3b1bd38 --- /dev/null +++ b/components/camel-google-calendar/src/test/resources/log4j.properties @@ -0,0 +1,14 @@ +# +# The logging properties used +# +log4j.rootLogger=INFO, out + +# uncomment the following line to turn on Camel debugging +#log4j.logger.org.apache.camel=DEBUG + +# CONSOLE appender not used by default +log4j.appender.out=org.apache.log4j.ConsoleAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n +#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n + http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/components/camel-google-calendar/src/test/resources/test-options.properties ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/test/resources/test-options.properties b/components/camel-google-calendar/src/test/resources/test-options.properties new file mode 100644 index 0000000..b24be6f --- /dev/null +++ b/components/camel-google-calendar/src/test/resources/test-options.properties @@ -0,0 +1,26 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +##################################### +## Login properties for Google Calendar Component +##################################### +## Application client id and secret +clientId= +clientSecret= +applicationName=camel-google-calendar/1.0 +#accessToken= +refreshToken= http://git-wip-us.apache.org/repos/asf/camel/blob/d3589e83/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index be9775e..906d2db 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -174,7 +174,7 @@ <google-gdata-version>1.41.5.w1</google-gdata-version> <google-gdata-bundle-version>1.41.1_1</google-gdata-bundle-version> <google-guava-version>18.0</google-guava-version> - <google-api-client-version>1.18.0-rc</google-api-client-version> + <google-api-client-version>1.19.0</google-api-client-version> <google-api-services-drive-version>v2-rev123-1.18.0-rc</google-api-services-drive-version> <grizzly-websockets-version>2.3.17</grizzly-websockets-version> <groovy-version>2.3.7</groovy-version>