camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [camel] 02/03: Fixed CS for camel-google-sheets
Date Thu, 06 Jun 2019 14:08:29 GMT
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 56e99a93ee0765efc64b1c57f8de375157ce63cc
Author: Andrea Cosentino <ancosen@gmail.com>
AuthorDate: Thu Jun 6 15:43:17 2019 +0200

    Fixed CS for camel-google-sheets
---
 .../google/sheets/GoogleSheetsEndpoint.java        |  30 +--
 .../sheets/AbstractGoogleSheetsTestSupport.java    |  27 ++-
 .../sheets/server/GoogleSheetsApiTestServer.java   |  45 ++---
 .../server/GoogleSheetsApiTestServerAssert.java    | 224 ++++++---------------
 .../server/GoogleSheetsApiTestServerRule.java      |  23 +--
 5 files changed, 117 insertions(+), 232 deletions(-)

diff --git a/components/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsEndpoint.java
b/components/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsEndpoint.java
index f1e2e08..a0f3f6b 100644
--- a/components/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsEndpoint.java
+++ b/components/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsEndpoint.java
@@ -35,13 +35,7 @@ import org.apache.camel.util.component.ApiMethodPropertiesHelper;
 /**
  * The google-sheets component provides access to Google Sheets.
  */
-@UriEndpoint(firstVersion = "2.23.0",
-        scheme = "google-sheets",
-        title = "Google Sheets",
-        syntax = "google-sheets:apiName/methodName",
-        consumerClass = GoogleSheetsConsumer.class,
-        consumerPrefix = "consumer",
-        label = "api,cloud,sheets")
+@UriEndpoint(firstVersion = "2.23.0", scheme = "google-sheets", title = "Google Sheets",
syntax = "google-sheets:apiName/methodName", consumerPrefix = "consumer", label = "api,cloud,sheets")
 public class GoogleSheetsEndpoint extends AbstractApiEndpoint<GoogleSheetsApiName, GoogleSheetsConfiguration>
{
 
     @UriParam(name = "configuration")
@@ -49,11 +43,7 @@ public class GoogleSheetsEndpoint extends AbstractApiEndpoint<GoogleSheetsApiNam
 
     private Object apiProxy;
 
-    public GoogleSheetsEndpoint(String uri,
-                                GoogleSheetsComponent component,
-                                GoogleSheetsApiName apiName,
-                                String methodName,
-                                GoogleSheetsConfiguration endpointConfiguration) {
+    public GoogleSheetsEndpoint(String uri, GoogleSheetsComponent component, GoogleSheetsApiName
apiName, String methodName, GoogleSheetsConfiguration endpointConfiguration) {
         super(uri, component, apiName, methodName, GoogleSheetsApiCollection.getCollection().getHelper(apiName),
endpointConfiguration);
         this.endpointConfiguration = endpointConfiguration;
     }
@@ -88,14 +78,14 @@ public class GoogleSheetsEndpoint extends AbstractApiEndpoint<GoogleSheetsApiNam
     @Override
     protected void afterConfigureProperties() {
         switch (apiName) {
-            case SPREADSHEETS:
-                apiProxy = getClient().spreadsheets();
-                break;
-            case DATA:
-                apiProxy = getClient().spreadsheets().values();
-                break;
-            default:
-                throw new IllegalArgumentException("Invalid API name " + apiName);
+        case SPREADSHEETS:
+            apiProxy = getClient().spreadsheets();
+            break;
+        case DATA:
+            apiProxy = getClient().spreadsheets().values();
+            break;
+        default:
+            throw new IllegalArgumentException("Invalid API name " + apiName);
         }
     }
 
diff --git a/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/AbstractGoogleSheetsTestSupport.java
b/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/AbstractGoogleSheetsTestSupport.java
index f1e5eb7..d65e0ef 100644
--- a/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/AbstractGoogleSheetsTestSupport.java
+++ b/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/AbstractGoogleSheetsTestSupport.java
@@ -32,6 +32,7 @@ import com.google.api.services.sheets.v4.model.SheetProperties;
 import com.google.api.services.sheets.v4.model.Spreadsheet;
 import com.google.api.services.sheets.v4.model.SpreadsheetProperties;
 import com.google.api.services.sheets.v4.model.ValueRange;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelExecutionException;
 import org.apache.camel.component.google.sheets.internal.GoogleSheetsConstants;
@@ -42,19 +43,19 @@ import org.apache.camel.util.IntrospectionSupport;
 import org.junit.ClassRule;
 
 /**
- * Abstract base class for GoogleSheets Integration tests generated by Camel
- * API component maven plugin.
+ * Abstract base class for GoogleSheets Integration tests generated by Camel API
+ * component maven plugin.
  */
 public class AbstractGoogleSheetsTestSupport extends CamelTestSupport {
 
     protected static final String TEST_SHEET = "TestData";
     private static final String TEST_OPTIONS_PROPERTIES = "/test-options.properties";
-
-    private Spreadsheet spreadsheet;
-
+    
     @ClassRule
     public static GoogleSheetsApiTestServerRule googleSheetsApiTestServerRule = new GoogleSheetsApiTestServerRule(TEST_OPTIONS_PROPERTIES);
 
+    private Spreadsheet spreadsheet;
+
     /**
      * Create test spreadsheet that is used throughout all tests.
      */
@@ -108,13 +109,10 @@ public class AbstractGoogleSheetsTestSupport extends CamelTestSupport
{
 
         // add GoogleSheetsComponent to Camel context and use localhost url
         final GoogleSheetsComponent component = new GoogleSheetsComponent(context);
-        component.setClientFactory(new BatchGoogleSheetsClientFactory(
-                                            new NetHttpTransport.Builder()
-                                                    .trustCertificatesFromJavaKeyStore(
-                                                            getClass().getResourceAsStream("/"
+ GoogleSheetsApiTestServerRule.SERVER_KEYSTORE),
-                                                            GoogleSheetsApiTestServerRule.SERVER_KEYSTORE_PASSWORD)
-                                                    .build(),
-                                            new JacksonFactory()) {
+        component.setClientFactory(new BatchGoogleSheetsClientFactory(new NetHttpTransport.Builder()
+            .trustCertificatesFromJavaKeyStore(getClass().getResourceAsStream("/" + GoogleSheetsApiTestServerRule.SERVER_KEYSTORE),
+                                               GoogleSheetsApiTestServerRule.SERVER_KEYSTORE_PASSWORD)
+            .build(), new JacksonFactory()) {
             @Override
             protected void configure(Sheets.Builder clientBuilder) {
                 clientBuilder.setRootUrl(String.format("https://localhost:%s/", googleSheetsApiTestServerRule.getServerPort()));
@@ -128,6 +126,7 @@ public class AbstractGoogleSheetsTestSupport extends CamelTestSupport
{
 
     /**
      * Read component configuration from TEST_OPTIONS_PROPERTIES.
+     * 
      * @return Map of component options.
      * @throws IOException when TEST_OPTIONS_PROPERTIES could not be loaded.
      */
@@ -155,12 +154,12 @@ public class AbstractGoogleSheetsTestSupport extends CamelTestSupport
{
 
     @SuppressWarnings("unchecked")
     protected <T> T requestBodyAndHeaders(String endpointUri, Object body, Map<String,
Object> headers) throws CamelExecutionException {
-        return (T) template().requestBodyAndHeaders(endpointUri, body, headers);
+        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);
+        return (T)template().requestBody(endpoint, body);
     }
 
     public Spreadsheet getSpreadsheet() {
diff --git a/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/server/GoogleSheetsApiTestServer.java
b/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/server/GoogleSheetsApiTestServer.java
index 00bb91c..8dba22b 100644
--- a/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/server/GoogleSheetsApiTestServer.java
+++ b/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/server/GoogleSheetsApiTestServer.java
@@ -1,4 +1,4 @@
-/*
+/**
  * 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.
@@ -16,15 +16,6 @@
  */
 package org.apache.camel.component.google.sheets.server;
 
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.ReadListener;
-import javax.servlet.ServletException;
-import javax.servlet.ServletInputStream;
-import javax.servlet.ServletRequest;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
-import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.nio.file.Path;
 import java.util.Arrays;
@@ -35,6 +26,16 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.zip.GZIPInputStream;
 
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.ReadListener;
+import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponse;
+
 import com.consol.citrus.Citrus;
 import com.consol.citrus.dsl.runner.DefaultTestRunner;
 import com.consol.citrus.dsl.runner.TestRunner;
@@ -43,6 +44,7 @@ import com.consol.citrus.http.server.HttpServer;
 import com.consol.citrus.http.server.HttpServerBuilder;
 import com.consol.citrus.http.servlet.GzipHttpServletResponseWrapper;
 import com.consol.citrus.http.servlet.RequestCachingServletFilter;
+
 import org.eclipse.jetty.server.HttpConfiguration;
 import org.eclipse.jetty.server.HttpConnectionFactory;
 import org.eclipse.jetty.server.SecureRequestCustomizer;
@@ -64,7 +66,7 @@ import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
 import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore;
 import org.springframework.web.filter.OncePerRequestFilter;
 
-public class GoogleSheetsApiTestServer {
+public final class GoogleSheetsApiTestServer {
 
     private static Citrus citrus = Citrus.newInstance();
 
@@ -98,6 +100,7 @@ public class GoogleSheetsApiTestServer {
 
     /**
      * Obtains the httpServer.
+     * 
      * @return
      */
     public HttpServer getHttpServer() {
@@ -113,8 +116,8 @@ public class GoogleSheetsApiTestServer {
     }
 
     /**
-     * Builder builds server instance from given http server builder adding more setting
options in fluent
-     * builder pattern style.
+     * Builder builds server instance from given http server builder adding more
+     * setting options in fluent builder pattern style.
      */
     public static class Builder {
         private final HttpServerBuilder serverBuilder;
@@ -186,9 +189,8 @@ public class GoogleSheetsApiTestServer {
             HttpConfiguration httpConfiguration = new HttpConfiguration(parent);
             httpConfiguration.setCustomizers(Collections.singletonList(new SecureRequestCustomizer()));
 
-            ServerConnector sslConnector = new ServerConnector(new org.eclipse.jetty.server.Server(),
-                    new SslConnectionFactory(sslContextFactory, "http/1.1"),
-                    new HttpConnectionFactory(httpConfiguration));
+            ServerConnector sslConnector = new ServerConnector(new org.eclipse.jetty.server.Server(),
new SslConnectionFactory(sslContextFactory, "http/1.1"),
+                                                               new HttpConnectionFactory(httpConfiguration));
             sslConnector.setPort(securePort);
 
             serverBuilder.connector(sslConnector);
@@ -218,10 +220,8 @@ public class GoogleSheetsApiTestServer {
             clientDetails.setAccessTokenValiditySeconds(3000);
             clientDetails.setAutoApproveScopes(Arrays.asList("read", "write"));
             clientDetails.setScope(Arrays.asList("read", "write"));
-            clientDetails.setAuthorities(Arrays.asList(new SimpleGrantedAuthority("client_credentials"),
-                                                        new SimpleGrantedAuthority("authorization_code"),
-                                                        new SimpleGrantedAuthority("password"),
-                                                        new SimpleGrantedAuthority("refresh_token")));
+            clientDetails.setAuthorities(Arrays.asList(new SimpleGrantedAuthority("client_credentials"),
new SimpleGrantedAuthority("authorization_code"),
+                                                       new SimpleGrantedAuthority("password"),
new SimpleGrantedAuthority("refresh_token")));
 
             OAuth2AuthenticationProcessingFilter filter = new OAuth2AuthenticationProcessingFilter();
             OAuth2AuthenticationManager oauth2AuthenticationManager = new OAuth2AuthenticationManager();
@@ -256,8 +256,7 @@ public class GoogleSheetsApiTestServer {
 
     private static class GzipServletFilter extends OncePerRequestFilter {
         @Override
-        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
-                                        FilterChain filterChain) throws ServletException,
IOException {
+        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
             HttpServletRequest filteredRequest = request;
             HttpServletResponse filteredResponse = response;
 
@@ -274,7 +273,7 @@ public class GoogleSheetsApiTestServer {
             filterChain.doFilter(filteredRequest, filteredResponse);
 
             if (filteredResponse instanceof GzipHttpServletResponseWrapper) {
-                ((GzipHttpServletResponseWrapper) filteredResponse).finish();
+                ((GzipHttpServletResponseWrapper)filteredResponse).finish();
             }
         }
     }
diff --git a/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/server/GoogleSheetsApiTestServerAssert.java
b/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/server/GoogleSheetsApiTestServerAssert.java
index a89edae..107e746 100644
--- a/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/server/GoogleSheetsApiTestServerAssert.java
+++ b/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/server/GoogleSheetsApiTestServerAssert.java
@@ -1,4 +1,4 @@
-/*
+/**
  * 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.
@@ -43,14 +43,11 @@ import org.assertj.core.api.AbstractAssert;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 
-public class GoogleSheetsApiTestServerAssert extends AbstractAssert<GoogleSheetsApiTestServerAssert,
GoogleSheetsApiTestServer> {
+public final class GoogleSheetsApiTestServerAssert extends AbstractAssert<GoogleSheetsApiTestServerAssert,
GoogleSheetsApiTestServer> {
 
-    private ObjectMapper mapper = new ObjectMapper()
-                .setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_EMPTY,
JsonInclude.Include.NON_EMPTY))
-                .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
-                .enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING)
-                .enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING)
-                .disable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
+    private ObjectMapper mapper = new ObjectMapper().setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_EMPTY,
JsonInclude.Include.NON_EMPTY))
+        .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING)
+        .enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING).disable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
 
     private GoogleSheetsApiTestServerAssert(GoogleSheetsApiTestServer server) {
         super(server, GoogleSheetsApiTestServerAssert.class);
@@ -58,6 +55,7 @@ public class GoogleSheetsApiTestServerAssert extends AbstractAssert<GoogleSheets
 
     /**
      * A fluent entry point to the assertion class.
+     * 
      * @param server the target server to perform assertions to.
      * @return
      */
@@ -87,8 +85,7 @@ public class GoogleSheetsApiTestServerAssert extends AbstractAssert<GoogleSheets
         } catch (InterruptedException | ExecutionException | TimeoutException e) {
             throw new IllegalStateException(e);
         } finally {
-            Optional.ofNullable(schedule)
-                .ifPresent(future -> future.cancel(true));
+            Optional.ofNullable(schedule).ifPresent(future -> future.cancel(true));
         }
     }
 
@@ -99,16 +96,9 @@ public class GoogleSheetsApiTestServerAssert extends AbstractAssert<GoogleSheets
 
         public void andReturnSpreadsheet(Spreadsheet spreadsheet) throws IOException {
             String spreadsheetJson = spreadsheet.toPrettyString();
-            actual.getRunner().async().actions(
-                actual.getRunner().http(action -> action.server(actual.getHttpServer())
-                    .receive()
-                    .get("/v4/spreadsheets/${spreadsheetId}")),
-                actual.getRunner().http(action -> action.server(actual.getHttpServer())
-                    .send()
-                    .response(HttpStatus.OK)
-                    .contentType(MediaType.APPLICATION_JSON_VALUE)
-                    .payload(spreadsheetJson))
-            );
+            actual.getRunner().async()
+                .actions(actual.getRunner().http(action -> action.server(actual.getHttpServer()).receive().get("/v4/spreadsheets/${spreadsheetId}")),
actual.getRunner()
+                    .http(action -> action.server(actual.getHttpServer()).send().response(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON_VALUE).payload(spreadsheetJson)));
         }
     }
 
@@ -123,19 +113,10 @@ public class GoogleSheetsApiTestServerAssert extends AbstractAssert<GoogleSheets
         }
 
         public void andReturnClearResponse(String clearedRange) throws IOException {
-            actual.getRunner().async().actions(
-                actual.getRunner().http(action -> action.server(actual.getHttpServer())
-                    .receive()
-                    .post("/v4/spreadsheets/${spreadsheetId}/values/${range}:clear")),
-                actual.getRunner().http(action -> action.server(actual.getHttpServer())
-                    .send()
-                    .response(HttpStatus.OK)
-                    .contentType(MediaType.APPLICATION_JSON_VALUE)
-                    .payload("{" +
-                            "\"spreadsheetId\": \"${spreadsheetId}\"," +
-                            "\"clearedRange\": \"" + clearedRange + "\"" +
-                        "}"))
-            );
+            actual.getRunner().async()
+                .actions(actual.getRunner().http(action -> action.server(actual.getHttpServer()).receive().post("/v4/spreadsheets/${spreadsheetId}/values/${range}:clear")),
+                         actual.getRunner().http(action -> action.server(actual.getHttpServer()).send().response(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON_VALUE)
+                             .payload("{" + "\"spreadsheetId\": \"${spreadsheetId}\"," +
"\"clearedRange\": \"" + clearedRange + "\"" + "}")));
         }
     }
 
@@ -155,23 +136,16 @@ public class GoogleSheetsApiTestServerAssert extends AbstractAssert<GoogleSheets
         public void andReturnUpdateResponse() throws IOException {
             String valuesJson = mapper.writer().writeValueAsString(data);
 
-            actual.getRunner().async().actions(
-                actual.getRunner().http(action -> action.server(actual.getHttpServer())
-                    .receive()
-                    .put("/v4/spreadsheets/${spreadsheetId}/values/${range}")
-                    .validate("$.values.toString()", valuesJson)),
-                actual.getRunner().http(action -> action.server(actual.getHttpServer())
-                    .send()
-                    .response(HttpStatus.OK)
-                    .contentType(MediaType.APPLICATION_JSON_VALUE)
-                    .payload("{" +
-                            "\"spreadsheetId\": \"${spreadsheetId}\"," +
-                            "\"updatedRange\": \"${range}\"," +
-                            "\"updatedRows\": " + data.size() + "," +
-                            "\"updatedColumns\": " + Optional.ofNullable(data.get(0)).map(Collection::size).orElse(0)
+ "," +
-                            "\"updatedCells\": " + data.size() * Optional.ofNullable(data.get(0)).map(Collection::size).orElse(0)
+
-                        "}"))
-            );
+            actual
+                .getRunner().async().actions(
+                                             actual.getRunner()
+                                                 .http(action -> action.server(actual.getHttpServer()).receive().put("/v4/spreadsheets/${spreadsheetId}/values/${range}")
+                                                     .validate("$.values.toString()", valuesJson)),
+                                             actual.getRunner()
+                                                 .http(action -> action.server(actual.getHttpServer()).send().response(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON_VALUE)
+                                                     .payload("{" + "\"spreadsheetId\": \"${spreadsheetId}\","
+ "\"updatedRange\": \"${range}\"," + "\"updatedRows\": "
+                                                              + data.size() + "," + "\"updatedColumns\":
" + Optional.ofNullable(data.get(0)).map(Collection::size).orElse(0) + ","
+                                                              + "\"updatedCells\": " + data.size()
* Optional.ofNullable(data.get(0)).map(Collection::size).orElse(0) + "}")));
         }
     }
 
@@ -191,27 +165,17 @@ public class GoogleSheetsApiTestServerAssert extends AbstractAssert<GoogleSheets
         public void andReturnAppendResponse(String updatedRange) throws IOException {
             String valuesJson = mapper.writer().writeValueAsString(data);
 
-            actual.getRunner().async().actions(
-                actual.getRunner().http(action -> action.server(actual.getHttpServer())
-                    .receive()
-                    .post("/v4/spreadsheets/${spreadsheetId}/values/${range}:append")
-                    .validate("$.values.toString()", valuesJson)),
-                actual.getRunner().http(action -> action.server(actual.getHttpServer())
-                    .send()
-                    .response(HttpStatus.OK)
-                    .contentType(MediaType.APPLICATION_JSON_VALUE)
-                    .payload("{" +
-                        "\"spreadsheetId\": \"${spreadsheetId}\"," +
-                        "\"updates\":" +
-                            "{" +
-                                "\"spreadsheetId\": \"${spreadsheetId}\"," +
-                                "\"updatedRange\": \"" + updatedRange + "\"," +
-                                "\"updatedRows\": " + data.size() + "," +
-                                "\"updatedColumns\": " + Optional.ofNullable(data.get(0)).map(Collection::size).orElse(0)
+ "," +
-                                "\"updatedCells\": " + data.size() * Optional.ofNullable(data.get(0)).map(Collection::size).orElse(0)
+
-                            "}" +
-                        "}"))
-            );
+            actual
+                .getRunner().async().actions(
+                                             actual.getRunner()
+                                                 .http(action -> action.server(actual.getHttpServer()).receive().post("/v4/spreadsheets/${spreadsheetId}/values/${range}:append")
+                                                     .validate("$.values.toString()", valuesJson)),
+                                             actual.getRunner()
+                                                 .http(action -> action.server(actual.getHttpServer()).send().response(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON_VALUE)
+                                                     .payload("{" + "\"spreadsheetId\": \"${spreadsheetId}\","
+ "\"updates\":" + "{" + "\"spreadsheetId\": \"${spreadsheetId}\","
+                                                              + "\"updatedRange\": \"" +
updatedRange + "\"," + "\"updatedRows\": " + data.size() + "," + "\"updatedColumns\": "
+                                                              + Optional.ofNullable(data.get(0)).map(Collection::size).orElse(0)
+ "," + "\"updatedCells\": "
+                                                              + data.size() * Optional.ofNullable(data.get(0)).map(Collection::size).orElse(0)
+ "}" + "}")));
         }
     }
 
@@ -227,43 +191,24 @@ public class GoogleSheetsApiTestServerAssert extends AbstractAssert<GoogleSheets
 
         public void andReturnValueRange(ValueRange valueRange) throws IOException {
             String valueJson = valueRange.toPrettyString();
-            actual.getRunner().async().actions(
-                actual.getRunner().http(action -> action.server(actual.getHttpServer())
-                    .receive()
-                    .get("/v4/spreadsheets/${spreadsheetId}/values/${range}")),
-                actual.getRunner().http(action -> action.server(actual.getHttpServer())
-                    .send()
-                    .response(HttpStatus.OK)
-                    .contentType(MediaType.APPLICATION_JSON_VALUE)
-                    .payload(valueJson))
-            );
+            actual.getRunner().async()
+                .actions(actual.getRunner().http(action -> action.server(actual.getHttpServer()).receive().get("/v4/spreadsheets/${spreadsheetId}/values/${range}")),
actual
+                    .getRunner()
+                    .http(action -> action.server(actual.getHttpServer()).send().response(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON_VALUE).payload(valueJson)));
         }
 
         public void andReturnValues(List<List<Object>> data) throws JsonProcessingException
{
             String valueRangeJson;
             if (ObjectHelper.isEmpty(data)) {
-                valueRangeJson = "{" +
-                        "\"range\": \"${range}\"," +
-                        "\"majorDimension\": \"ROWS\"" +
-                    "}";
+                valueRangeJson = "{" + "\"range\": \"${range}\"," + "\"majorDimension\":
\"ROWS\"" + "}";
             } else {
-                valueRangeJson = "{" +
-                        "\"range\": \"${range}\"," +
-                        "\"majorDimension\": \"ROWS\"," +
-                        "\"values\":" + mapper.writer().writeValueAsString(data) +
-                    "}";
+                valueRangeJson = "{" + "\"range\": \"${range}\"," + "\"majorDimension\":
\"ROWS\"," + "\"values\":" + mapper.writer().writeValueAsString(data) + "}";
             }
 
-            actual.getRunner().async().actions(
-                actual.getRunner().http(action -> action.server(actual.getHttpServer())
-                    .receive()
-                    .get("/v4/spreadsheets/${spreadsheetId}/values/${range}")),
-                actual.getRunner().http(action -> action.server(actual.getHttpServer())
-                    .send()
-                    .response(HttpStatus.OK)
-                    .contentType(MediaType.APPLICATION_JSON_VALUE)
-                    .payload(valueRangeJson))
-            );
+            actual.getRunner().async()
+                .actions(actual.getRunner().http(action -> action.server(actual.getHttpServer()).receive().get("/v4/spreadsheets/${spreadsheetId}/values/${range}")),
actual
+                    .getRunner()
+                    .http(action -> action.server(actual.getHttpServer()).send().response(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON_VALUE).payload(valueRangeJson)));
         }
     }
 
@@ -280,34 +225,17 @@ public class GoogleSheetsApiTestServerAssert extends AbstractAssert<GoogleSheets
         public void andReturnValues(List<List<Object>> data) throws JsonProcessingException
{
             String valueRangeJson;
             if (ObjectHelper.isEmpty(data)) {
-                valueRangeJson = "{\"spreadsheetId\": \"${spreadsheetId}\"," +
-                    "\"valueRanges\": [" +
-                        "{" +
-                            "\"range\": \"${range}\"," +
-                            "\"majorDimension\": \"ROWS\"" +
-                        "}" +
-                    "]}";
+                valueRangeJson = "{\"spreadsheetId\": \"${spreadsheetId}\"," + "\"valueRanges\":
[" + "{" + "\"range\": \"${range}\"," + "\"majorDimension\": \"ROWS\"" + "}"
+                                 + "]}";
             } else {
-                valueRangeJson = "{\"spreadsheetId\": \"${spreadsheetId}\"," +
-                    "\"valueRanges\": [" +
-                        "{" +
-                            "\"range\": \"${range}\"," +
-                            "\"majorDimension\": \"ROWS\"," +
-                            "\"values\":" + mapper.writer().writeValueAsString(data) +
-                        "}" +
-                    "]}";
+                valueRangeJson = "{\"spreadsheetId\": \"${spreadsheetId}\"," + "\"valueRanges\":
[" + "{" + "\"range\": \"${range}\"," + "\"majorDimension\": \"ROWS\","
+                                 + "\"values\":" + mapper.writer().writeValueAsString(data)
+ "}" + "]}";
             }
 
-            actual.getRunner().async().actions(
-                actual.getRunner().http(action -> action.server(actual.getHttpServer())
-                    .receive()
-                    .get("/v4/spreadsheets/${spreadsheetId}/values:batchGet")),
-                actual.getRunner().http(action -> action.server(actual.getHttpServer())
-                    .send()
-                    .response(HttpStatus.OK)
-                    .contentType(MediaType.APPLICATION_JSON_VALUE)
-                    .payload(valueRangeJson))
-            );
+            actual.getRunner().async()
+                .actions(actual.getRunner().http(action -> action.server(actual.getHttpServer()).receive().get("/v4/spreadsheets/${spreadsheetId}/values:batchGet")),
actual
+                    .getRunner()
+                    .http(action -> action.server(actual.getHttpServer()).send().response(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON_VALUE).payload(valueRangeJson)));
         }
     }
 
@@ -345,19 +273,10 @@ public class GoogleSheetsApiTestServerAssert extends AbstractAssert<GoogleSheets
                 spreadsheetJson = "{\"properties\":{\"title\":\"${title}\"}}";
             }
 
-            actual.getRunner().async().actions(
-                actual.getRunner().http(action -> action.server(actual.getHttpServer())
-                    .receive()
-                    .post("/v4/spreadsheets")
-                    .name("create.request")
-                    .messageType(MessageType.JSON)
-                    .payload(spreadsheetJson)),
-                actual.getRunner().http(action -> action.server(actual.getHttpServer())
-                    .send()
-                    .response(HttpStatus.OK)
-                    .contentType(MediaType.APPLICATION_JSON_VALUE)
-                    .payload("{\"spreadsheetId\":\"${spreadsheetId}\",\"properties\":{\"title\":\"citrus:jsonPath(citrus:message(create.request.payload()),
'$.properties.title')\"}}"))
-            );
+            actual.getRunner().async().actions(actual.getRunner().http(action -> action.server(actual.getHttpServer()).receive().post("/v4/spreadsheets").name("create.request")
+                .messageType(MessageType.JSON).payload(spreadsheetJson)), actual.getRunner()
+                    .http(action -> action.server(actual.getHttpServer()).send().response(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON_VALUE)
+                        .payload("{\"spreadsheetId\":\"${spreadsheetId}\",\"properties\":{\"title\":\"citrus:jsonPath(citrus:message(create.request.payload()),
'$.properties.title')\"}}")));
         }
     }
 
@@ -379,27 +298,14 @@ public class GoogleSheetsApiTestServerAssert extends AbstractAssert<GoogleSheets
         }
 
         public void andReturnUpdated() {
-            actual.getRunner().async().actions(
-                actual.getRunner().http(action -> action.server(actual.getHttpServer())
-                    .receive()
-                    .post("/v4/spreadsheets/${spreadsheetId}:batchUpdate")
-                    .messageType(MessageType.JSON)
-                    .payload("{" +
-                        "\"includeSpreadsheetInResponse\":true," +
-                        "\"requests\":[" +
-                                "{" +
-                                    "\"updateSpreadsheetProperties\": {" +
-                                    "\"fields\":\"" + String.join(",", fields) + "\"," +
-                                    "\"properties\":{" + fields.stream().map(field ->
String.format("\"%s\":\"${%s}\"", field, field)).collect(Collectors.joining(",")) + "}" +
-                                "}" +
-                            "}" +
-                        "]}")),
-                actual.getRunner().http(action -> action.server(actual.getHttpServer())
-                    .send()
-                    .response(HttpStatus.OK)
-                    .contentType(MediaType.APPLICATION_JSON_VALUE)
-                    .payload("{\"spreadsheetId\":\"${spreadsheetId}\",\"updatedSpreadsheet\":{\"properties\":{\"title\":\"${title}\"},\"spreadsheetId\":\"${spreadsheetId}\"}}"))
-            );
+            actual.getRunner().async()
+                .actions(actual.getRunner()
+                    .http(action -> action.server(actual.getHttpServer()).receive().post("/v4/spreadsheets/${spreadsheetId}:batchUpdate").messageType(MessageType.JSON)
+                        .payload("{" + "\"includeSpreadsheetInResponse\":true," + "\"requests\":["
+ "{" + "\"updateSpreadsheetProperties\": {" + "\"fields\":\""
+                                 + String.join(",", fields) + "\"," + "\"properties\":{"
+                                 + fields.stream().map(field -> String.format("\"%s\":\"${%s}\"",
field, field)).collect(Collectors.joining(",")) + "}" + "}" + "}" + "]}")),
+                         actual.getRunner().http(action -> action.server(actual.getHttpServer()).send().response(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON_VALUE)
+                             .payload("{\"spreadsheetId\":\"${spreadsheetId}\",\"updatedSpreadsheet\":{\"properties\":{\"title\":\"${title}\"},\"spreadsheetId\":\"${spreadsheetId}\"}}")));
         }
     }
 }
diff --git a/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/server/GoogleSheetsApiTestServerRule.java
b/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/server/GoogleSheetsApiTestServerRule.java
index 7ecdc53..75a21d4 100644
--- a/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/server/GoogleSheetsApiTestServerRule.java
+++ b/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/server/GoogleSheetsApiTestServerRule.java
@@ -1,4 +1,4 @@
-/*
+/**
  * 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.
@@ -43,20 +43,10 @@ public class GoogleSheetsApiTestServerRule implements TestRule {
         try {
             Map<String, Object> testOptions = getTestOptions(optionFile);
 
-            googleApiTestServer = new GoogleSheetsApiTestServer.Builder(CitrusEndpoints.http()
-                    .server()
-                    .port(serverPort)
-                    .timeout(15000)
-                    .defaultStatus(HttpStatus.REQUEST_TIMEOUT)
-                    .autoStart(true))
-                    .keyStorePath(new ClassPathResource(SERVER_KEYSTORE).getFile().toPath())
-                    .keyStorePassword(SERVER_KEYSTORE_PASSWORD)
-                    .securePort(serverPort)
-                    .clientId(testOptions.get("clientId").toString())
-                    .clientSecret(testOptions.get("clientSecret").toString())
-                    .accessToken(testOptions.get("accessToken").toString())
-                    .refreshToken(testOptions.get("refreshToken").toString())
-                    .build();
+            googleApiTestServer = new GoogleSheetsApiTestServer.Builder(CitrusEndpoints.http().server().port(serverPort).timeout(15000).defaultStatus(HttpStatus.REQUEST_TIMEOUT)
+                .autoStart(true)).keyStorePath(new ClassPathResource(SERVER_KEYSTORE).getFile().toPath()).keyStorePassword(SERVER_KEYSTORE_PASSWORD).securePort(serverPort)
+                    .clientId(testOptions.get("clientId").toString()).clientSecret(testOptions.get("clientSecret").toString())
+                    .accessToken(testOptions.get("accessToken").toString()).refreshToken(testOptions.get("refreshToken").toString()).build();
 
             assertThatGoogleApi(googleApiTestServer).isRunning();
         } catch (Exception e) {
@@ -71,6 +61,7 @@ public class GoogleSheetsApiTestServerRule implements TestRule {
 
     /**
      * Read component configuration from TEST_OPTIONS_PROPERTIES.
+     * 
      * @return Map of component options.
      */
     private Map<String, Object> getTestOptions(String optionFile) throws IOException
{
@@ -91,7 +82,7 @@ public class GoogleSheetsApiTestServerRule implements TestRule {
     private class GoogleSheetsApiTestServerStatement extends Statement {
         private final Statement base;
 
-        GoogleSheetsApiTestServerStatement( Statement base ) {
+        GoogleSheetsApiTestServerStatement(Statement base) {
             this.base = base;
         }
 


Mime
View raw message