Skip to content

Commit 3c44fa7

Browse files
committed
chore(bigquery-jdbc): refactor tests to remove hardcoded base uri
1 parent 7b5efb5 commit 3c44fa7

11 files changed

Lines changed: 129 additions & 339 deletions

java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITAuthTests.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.cloud.bigquery.jdbc.it;
1818

19+
1920
import static org.junit.jupiter.api.Assertions.assertEquals;
2021
import static org.junit.jupiter.api.Assertions.assertFalse;
2122
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -90,7 +91,7 @@ public void testValidServiceAccountAuthentication() throws SQLException, IOExcep
9091
Files.write(tempFile.toPath(), authJson.toString().getBytes());
9192

9293
String connection_uri =
93-
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;"
94+
getBaseConnectionUrl() + ""
9495
+ "ProjectId="
9596
+ authJson.get("project_id").getAsString()
9697
+ ";OAuthType=0;"
@@ -105,7 +106,7 @@ public void testValidServiceAccountAuthentication() throws SQLException, IOExcep
105106
@Test
106107
public void testServiceAccountAuthenticationMissingOAuthPvtKeyPath() throws SQLException {
107108
String connection_uri =
108-
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;"
109+
getBaseConnectionUrl() + ""
109110
+ "ProjectId="
110111
+ PROJECT_ID
111112
+ ";OAuthType=0;";
@@ -127,7 +128,7 @@ public void testValidServiceAccountAuthenticationOAuthPvtKeyAsPath()
127128
Files.write(tempFile.toPath(), authJson.toString().getBytes());
128129

129130
String connection_uri =
130-
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;"
131+
getBaseConnectionUrl() + ""
131132
+ "ProjectId="
132133
+ authJson.get("project_id").getAsString()
133134
+ ";OAuthType=0;"
@@ -144,7 +145,7 @@ public void testValidServiceAccountAuthenticationViaEmailAndPkcs8Key()
144145
final JsonObject authJson = getAuthJson();
145146

146147
String connection_uri =
147-
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;"
148+
getBaseConnectionUrl() + ""
148149
+ "ProjectId="
149150
+ authJson.get("project_id").getAsString()
150151
+ ";OAuthType=0;"
@@ -162,7 +163,7 @@ public void testValidServiceAccountAuthenticationOAuthPvtKeyAsJson()
162163
final JsonObject authJson = getAuthJson();
163164

164165
String connection_uri =
165-
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;"
166+
getBaseConnectionUrl() + ""
166167
+ "ProjectId="
167168
+ authJson.get("project_id").getAsString()
168169
+ ";OAuthType=0;"
@@ -192,7 +193,7 @@ public void testValidServiceAccountAuthenticationP12() throws SQLException, IOEx
192193
@Disabled
193194
public void testValidGoogleUserAccountAuthentication() throws SQLException {
194195
String connection_uri =
195-
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID="
196+
getBaseConnectionUrl() + "PROJECTID="
196197
+ PROJECT_ID
197198
+ ";OAuthType=1;OAuthClientId=client_id;OAuthClientSecret=client_secret;";
198199

@@ -213,7 +214,7 @@ public void testValidGoogleUserAccountAuthentication() throws SQLException {
213214
@Disabled
214215
public void testValidExternalAccountAuthentication() throws SQLException {
215216
String connection_uri =
216-
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID="
217+
getBaseConnectionUrl() + "PROJECTID="
217218
+ PROJECT_ID
218219
+ ";OAUTHTYPE=4;"
219220
+ "BYOID_AudienceUri=//iam.googleapis.com/projects/<project>/locations/<location>/workloadIdentityPools/<pool>/providers/<provider>;"
@@ -237,7 +238,7 @@ public void testValidExternalAccountAuthentication() throws SQLException {
237238
@Disabled
238239
public void testValidExternalAccountAuthenticationFromFile() throws SQLException {
239240
String connection_uri =
240-
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID="
241+
getBaseConnectionUrl() + "PROJECTID="
241242
+ PROJECT_ID
242243
+ ";OAUTHTYPE=4;"
243244
+ "OAuthPvtKeyPath=/path/to/file;";
@@ -259,7 +260,7 @@ public void testValidExternalAccountAuthenticationFromFile() throws SQLException
259260
@Disabled
260261
public void testValidExternalAccountAuthenticationRawJson() throws SQLException {
261262
String connection_uri =
262-
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID="
263+
getBaseConnectionUrl() + "PROJECTID="
263264
+ PROJECT_ID
264265
+ ";OAUTHTYPE=4;OAuthPvtKey={\n"
265266
+ " \"universe_domain\": \"googleapis.com\",\n"
@@ -303,7 +304,7 @@ public void testValidPreGeneratedAccessTokenAuthentication(String scope, boolean
303304
String accessToken = credentials.getAccessToken().getTokenValue();
304305

305306
String connectionUri =
306-
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId="
307+
getBaseConnectionUrl() + "ProjectId="
307308
+ authJson.get("project_id").getAsString()
308309
+ ";OAuthType=2"
309310
+ ";OAuthAccessToken="
@@ -319,7 +320,7 @@ public void testValidPreGeneratedAccessTokenAuthentication(String scope, boolean
319320
@Disabled
320321
public void testValidRefreshTokenAuthentication() throws SQLException {
321322
String connection_uri =
322-
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID="
323+
getBaseConnectionUrl() + "PROJECTID="
323324
+ PROJECT_ID
324325
+ ";OAUTHTYPE=2;OAuthRefreshToken=refresh_token;"
325326
+ ";OAuthClientId=client;OAuthClientSecret=secret;";

java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud.bigquery.jdbc.it;
1818

1919
import static org.junit.jupiter.api.Assertions.assertNotNull;
20+
import com.google.cloud.bigquery.jdbc.utils.TestUtilities;
2021

2122
import com.google.cloud.ServiceOptions;
2223
import com.google.cloud.bigquery.BigQuery;
@@ -177,10 +178,15 @@ private static void registerShutdownHook(final String dataset) {
177178
}
178179

179180
public static final String DEFAULT_CATALOG = ServiceOptions.getDefaultProjectId();
180-
public static String connectionUrl =
181-
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId="
182-
+ DEFAULT_CATALOG
183-
+ ";OAuthType=3;Timeout=3600;";
181+
182+
public static String getBaseConnectionUrl() {
183+
return TestUtilities.getBaseConnectionUrl();
184+
}
185+
186+
public static String connectionUrl = getBaseConnectionUrl()
187+
+ "ProjectId="
188+
+ DEFAULT_CATALOG
189+
+ ";OAuthType=3;Timeout=3600;";
184190

185191
public static final String createDatasetQuery =
186192
"CREATE SCHEMA IF NOT EXISTS `%s.%s` OPTIONS(default_table_expiration_days = 5)";

0 commit comments

Comments
 (0)