This is an automated email from the ASF dual-hosted git repository.

bamaer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git


The following commit(s) were added to refs/heads/main by this push:
     new 41c517942f Google Sheets Output: Resolve variables in proxy host and 
port (#9583)
41c517942f is described below

commit 41c517942fccd64bac31013404cf5cd15a71ded3
Author: Joel Giovinazzo <[email protected]>
AuthorDate: Thu Nov 19 18:01:34 2026 +1100

    Google Sheets Output: Resolve variables in proxy host and port (#9583)
---
 .../googlesheets/GoogleSheetsOutput.java           | 17 ++--
 .../googlesheets/GoogleSheetsOutputTest.java       | 94 ++++++++++++++++++++++
 2 files changed, 106 insertions(+), 5 deletions(-)

diff --git 
a/plugins/tech/google/src/main/java/org/apache/hop/pipeline/transforms/googlesheets/GoogleSheetsOutput.java
 
b/plugins/tech/google/src/main/java/org/apache/hop/pipeline/transforms/googlesheets/GoogleSheetsOutput.java
index 4164ef0017..79f085a8eb 100644
--- 
a/plugins/tech/google/src/main/java/org/apache/hop/pipeline/transforms/googlesheets/GoogleSheetsOutput.java
+++ 
b/plugins/tech/google/src/main/java/org/apache/hop/pipeline/transforms/googlesheets/GoogleSheetsOutput.java
@@ -42,6 +42,7 @@ import 
com.google.api.services.sheets.v4.model.SpreadsheetProperties;
 import com.google.api.services.sheets.v4.model.UpdateSheetPropertiesRequest;
 import com.google.api.services.sheets.v4.model.ValueRange;
 import java.io.IOException;
+import java.security.GeneralSecurityException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -79,6 +80,15 @@ public class GoogleSheetsOutput
     super(transformMeta, meta, data, copyNr, pipelineMeta, pipeline);
   }
 
+  /**
+   * Creates the HTTP transport for the Google APIs, with variables resolved 
in the proxy host and
+   * port.
+   */
+  private NetHttpTransport newHttpTransport() throws GeneralSecurityException, 
IOException {
+    return GoogleSheetsConnectionFactory.newTransport(
+        resolve(meta.getProxyHost()), resolve(meta.getProxyPort()));
+  }
+
   /** Initialize and do work where other transforms need to wait for... */
   @Override
   public boolean init() {
@@ -91,9 +101,7 @@ public class GoogleSheetsOutput
 
       // Check if file exists
       try {
-        httpTransport =
-            GoogleSheetsConnectionFactory.newTransport(
-                resolve(meta.getProxyHost()), resolve(meta.getProxyPort()));
+        httpTransport = newHttpTransport();
         jsonFactory = JacksonFactory.getDefaultInstance();
         scope = "https://www.googleapis.com/auth/drive";;
 
@@ -536,8 +544,7 @@ public class GoogleSheetsOutput
                 "Clearing range" + range + " in Spreadsheet :" + 
resolve(meta.getSpreadsheetKey()));
           }
           // Creating service
-          httpTransport =
-              GoogleSheetsConnectionFactory.newTransport(meta.getProxyHost(), 
meta.getProxyPort());
+          httpTransport = newHttpTransport();
           JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
           String scope = SheetsScopes.SPREADSHEETS;
           HttpRequestInitializer credential =
diff --git 
a/plugins/tech/google/src/test/java/org/apache/hop/pipeline/transforms/googlesheets/GoogleSheetsOutputTest.java
 
b/plugins/tech/google/src/test/java/org/apache/hop/pipeline/transforms/googlesheets/GoogleSheetsOutputTest.java
new file mode 100644
index 0000000000..44a8418bd1
--- /dev/null
+++ 
b/plugins/tech/google/src/test/java/org/apache/hop/pipeline/transforms/googlesheets/GoogleSheetsOutputTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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.hop.pipeline.transforms.googlesheets;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import org.apache.hop.core.exception.HopException;
+import org.apache.hop.core.logging.ILoggingObject;
+import org.apache.hop.pipeline.transforms.mock.TransformMockHelper;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+
+class GoogleSheetsOutputTest {
+
+  private TransformMockHelper<GoogleSheetsOutputMeta, GoogleSheetsOutputData> 
mockHelper;
+
+  @BeforeEach
+  void setUp() {
+    mockHelper =
+        new TransformMockHelper<>(
+            "GoogleSheetsOutput", GoogleSheetsOutputMeta.class, 
GoogleSheetsOutputData.class);
+    when(mockHelper.logChannelFactory.create(any(), any(ILoggingObject.class)))
+        .thenReturn(mockHelper.iLogChannel);
+    when(mockHelper.pipeline.isRunning()).thenReturn(true);
+  }
+
+  @AfterEach
+  void cleanUp() {
+    mockHelper.cleanUp();
+  }
+
+  /**
+   * After the last input row, processRow() opens a new connection to write 
the buffered rows. That
+   * connection must use the proxy host and port with variables resolved, as 
init() does.
+   */
+  @Test
+  void processRowResolvesVariablesInProxySettings() throws Exception {
+    GoogleSheetsOutputMeta meta = new GoogleSheetsOutputMeta();
+    meta.setProxyHost("${PROXY_HOST}");
+    meta.setProxyPort("${PROXY_PORT}");
+    GoogleSheetsOutputData data = new GoogleSheetsOutputData();
+    // Rows were already buffered: this call sees the end of the input.
+    data.currentRow = 1;
+
+    GoogleSheetsOutput transform =
+        spy(
+            new GoogleSheetsOutput(
+                mockHelper.transformMeta,
+                meta,
+                data,
+                0,
+                mockHelper.pipelineMeta,
+                mockHelper.pipeline));
+    transform.setVariable("PROXY_HOST", "proxy.example.com");
+    transform.setVariable("PROXY_PORT", "3128");
+    transform.first = false;
+    doReturn(null).when(transform).getRow();
+
+    try (MockedStatic<GoogleSheetsConnectionFactory> factory =
+        mockStatic(GoogleSheetsConnectionFactory.class)) {
+      // Stop right after the transport is requested; the Google APIs are not 
under test.
+      factory
+          .when(() -> GoogleSheetsConnectionFactory.newTransport(anyString(), 
anyString()))
+          .thenThrow(new IllegalStateException("stop after transport"));
+
+      assertThrows(HopException.class, transform::processRow);
+
+      factory.verify(() -> 
GoogleSheetsConnectionFactory.newTransport("proxy.example.com", "3128"));
+    }
+  }
+}

Reply via email to