CAMEL-10381 - fix NPE from calendar component configuration

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/37c1da95
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/37c1da95
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/37c1da95

Branch: refs/heads/camel-2.17.x
Commit: 37c1da9552b9b526358b93ad25980b60f4506641
Parents: 65cb2c3
Author: Jonathan Anstey <jans...@gmail.com>
Authored: Tue Oct 11 23:32:37 2016 -0230
Committer: Jonathan Anstey <jans...@gmail.com>
Committed: Tue Oct 11 23:47:30 2016 -0230

----------------------------------------------------------------------
 .../calendar/GoogleCalendarComponent.java       | 15 +++--
 .../google/calendar/GoogleCalendarEndpoint.java |  2 +-
 .../calendar/CalendarConfigurationTest.java     | 66 ++++++++++++++++++++
 3 files changed, 76 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/37c1da95/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
index d140ee4..84e3092 100644
--- 
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
@@ -44,13 +44,13 @@ public class GoogleCalendarComponent extends 
AbstractApiComponent<GoogleCalendar
         return GoogleCalendarApiName.fromValue(apiNameStr);
     }
 
-    public Calendar getClient() {
+    public Calendar getClient(GoogleCalendarConfiguration config) {
         if (client == null) {
-            client = getClientFactory().makeClient(configuration.getClientId(),
-                    configuration.getClientSecret(), configuration.getScopes(),
-                    configuration.getApplicationName(), 
configuration.getRefreshToken(),
-                    configuration.getAccessToken(), 
configuration.getEmailAddress(),
-                    configuration.getP12FileName(), configuration.getUser());
+            client = getClientFactory().makeClient(config.getClientId(),
+                    config.getClientSecret(), config.getScopes(),
+                    config.getApplicationName(), config.getRefreshToken(),
+                    config.getAccessToken(), config.getEmailAddress(),
+                    config.getP12FileName(), config.getUser());
         }
         return client;
     }
@@ -64,6 +64,9 @@ public class GoogleCalendarComponent extends 
AbstractApiComponent<GoogleCalendar
 
     @Override
     public GoogleCalendarConfiguration getConfiguration() {
+        if (configuration == null) {
+            configuration = new GoogleCalendarConfiguration();
+        }
         return super.getConfiguration();
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/37c1da95/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
index e955f6c..7ad7f9d 100644
--- 
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
@@ -111,7 +111,7 @@ public class GoogleCalendarEndpoint extends 
AbstractApiEndpoint<GoogleCalendarAp
     }
 
     public Calendar getClient() {
-        return ((GoogleCalendarComponent)getComponent()).getClient();
+        return 
((GoogleCalendarComponent)getComponent()).getClient(configuration);
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/37c1da95/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarConfigurationTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarConfigurationTest.java
 
b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarConfigurationTest.java
new file mode 100644
index 0000000..a70934e
--- /dev/null
+++ 
b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarConfigurationTest.java
@@ -0,0 +1,66 @@
+/**
+ * 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.CamelContext;
+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.apache.camel.impl.DefaultCamelContext;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CalendarConfigurationTest extends 
AbstractGoogleCalendarTestSupport {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CalendarConfigurationTest.class);
+    private static final String PATH_PREFIX = 
GoogleCalendarApiCollection.getCollection().getApiName(CalendarCalendarsApiMethod.class).getName();
+    private static final String TEST_URI = "google-calendar://" + PATH_PREFIX 
+ 
"/get?clientId=a&clientSecret=b&applicationName=c&accessToken=d&refreshToken=e";
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        final CamelContext context = new DefaultCamelContext(createRegistry());
+
+        // add GoogleCalendarComponent to Camel context but don't set up 
configuration
+        final GoogleCalendarComponent component = new 
GoogleCalendarComponent(context);
+        context.addComponent("google-drive", component);
+
+        return context;
+    }
+    
+    @Test
+    public void testConfiguration() throws Exception {
+        GoogleCalendarEndpoint endpoint = getMandatoryEndpoint(TEST_URI, 
GoogleCalendarEndpoint.class);
+        GoogleCalendarConfiguration configuration = 
endpoint.getConfiguration();
+        assertNotNull(configuration);
+        assertEquals("a", configuration.getClientId());
+        assertEquals("b", configuration.getClientSecret());
+        assertEquals("c", configuration.getApplicationName());
+        assertEquals("d", configuration.getAccessToken());
+        assertEquals("e", configuration.getRefreshToken());        
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct://COPY").to(TEST_URI);
+            }
+        };
+    }
+}

Reply via email to