diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryOptions.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryOptions.java index 465cc8305..89d92e422 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryOptions.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryOptions.java @@ -33,6 +33,7 @@ public class BigQueryOptions extends ServiceOptions { private static final String API_SHORT_NAME = "BigQuery"; private static final int DEFAULT_READ_API_TIME_OUT = 60000; private static final String BIGQUERY_SCOPE = "https://www.googleapis.com/auth/bigquery"; + // TODO(NOW) private static final Set SCOPES = ImmutableSet.of(BIGQUERY_SCOPE); private static final long serialVersionUID = -2437598817433266048L; private final String location; diff --git a/samples/snippets/src/main/java/com/example/bigquery/AuthDriveScope.java b/samples/snippets/src/main/java/com/example/bigquery/AuthDriveScope.java index c690ed4de..2ebf109ec 100644 --- a/samples/snippets/src/main/java/com/example/bigquery/AuthDriveScope.java +++ b/samples/snippets/src/main/java/com/example/bigquery/AuthDriveScope.java @@ -42,17 +42,29 @@ public static void setAuthDriveScope() throws IOException { "https://www.googleapis.com/auth/bigquery", "https://www.googleapis.com/auth/drive")); + // TODO(NOW) + // if (ServiceAccountCredentials.getApplicationDefault().equals(credentials)) { + // System.out.println("CHUONGPH: equal error: \n"); + // throw new IOException(); + // } else { + // System.out.println("CHUONGPH: not equal error: \n"); + // throw new IOException(); + // } + try { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. BigQuery bigquery = BigQueryOptions.newBuilder().setCredentials(credentials).build().getService(); + // System.out.println("CHUONGPH: Scopes \n" + BigQueryOptions.newBuilder().setCredentials(credentials).build().getScopes()); + // Use the client. System.out.println("Auth succeeded with multiple scopes. Datasets:"); for (Dataset dataset : bigquery.listDatasets().iterateAll()) { System.out.printf("Dataset: %s%n", dataset.getDatasetId().getDataset()); } + // throw new IOException(); } catch (BigQueryException e) { System.out.println("Auth failed due to error: \n" + e.toString()); } diff --git a/samples/snippets/src/main/java/com/example/bigquery/CreateTable.java b/samples/snippets/src/main/java/com/example/bigquery/CreateTable.java index df94a5ee7..ced6432d0 100644 --- a/samples/snippets/src/main/java/com/example/bigquery/CreateTable.java +++ b/samples/snippets/src/main/java/com/example/bigquery/CreateTable.java @@ -17,6 +17,8 @@ package com.example.bigquery; // [START bigquery_create_table] +import com.google.auth.oauth2.GoogleCredentials; +import com.google.auth.oauth2.ServiceAccountCredentials; import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.BigQueryException; import com.google.cloud.bigquery.BigQueryOptions; @@ -27,6 +29,10 @@ import com.google.cloud.bigquery.TableDefinition; import com.google.cloud.bigquery.TableId; import com.google.cloud.bigquery.TableInfo; +import com.google.cloud.bigquery.QueryJobConfiguration; +import com.google.cloud.bigquery.TableResult; +import com.google.common.collect.ImmutableSet; +import java.io.IOException; public class CreateTable { @@ -43,17 +49,50 @@ public static void main(String[] args) { public static void createTable(String datasetName, String tableName, Schema schema) { try { + // Create credentials with Drive & BigQuery API scopes. + // Both APIs must be enabled for your project before running this code. + GoogleCredentials credentials = + ServiceAccountCredentials.getApplicationDefault() + .createScoped( + ImmutableSet.of( + "https://www.googleapis.com/auth/bigquery", + "https://www.googleapis.com/auth/drive")); + // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. - BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService(); + BigQuery bigquery = + BigQueryOptions.newBuilder().setCredentials(credentials).build().getService(); + // // Initialize client that will be used to send requests. This client only needs to be created + // // once, and can be reused for multiple requests. + // BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService(); TableId tableId = TableId.of(datasetName, tableName); TableDefinition tableDefinition = StandardTableDefinition.of(schema); TableInfo tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build(); bigquery.create(tableInfo); - System.out.println("Table created successfully"); - } catch (BigQueryException e) { + + // TODO(NOW) + // String query = String.format("SELECT * FROM %s.INFORMATION_SCHEMA.SESSIONS_BY_USER", datasetName); + String query = "SELECT * FROM region-us.INFORMATION_SCHEMA.SESSIONS_BY_USER"; + // Create the query job. + QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query).build(); + + // Execute the query. + TableResult result = bigquery.query(queryConfig); + + // Print the results. + result + .iterateAll() + .forEach( + row -> { + System.out.print("creation_time:" + row.get("creation_time").getStringValue()); + System.out.print(", project_id:" + row.get("project_id").getStringValue()); + System.out.print(", session_id:" + row.get("session_id").getStringValue()); + System.out.print(", user_email:" + row.get("user_email").getStringValue()); + System.out.println(); + }); + } catch (BigQueryException | InterruptedException | IOException e) { System.out.println("Table was not created. \n" + e.toString()); } } diff --git a/samples/snippets/src/main/java/com/example/bigquery/QueryExternalSheetsPerm.java b/samples/snippets/src/main/java/com/example/bigquery/QueryExternalSheetsPerm.java index 97e660c97..be21aecbf 100644 --- a/samples/snippets/src/main/java/com/example/bigquery/QueryExternalSheetsPerm.java +++ b/samples/snippets/src/main/java/com/example/bigquery/QueryExternalSheetsPerm.java @@ -37,7 +37,7 @@ // Sample to queries an external data source using a permanent table public class QueryExternalSheetsPerm { - public static void main(String[] args) { + public static void main(String[] args) throws BigQueryException, InterruptedException, IOException { // TODO(developer): Replace these variables before running the sample. String datasetName = "MY_DATASET_NAME"; String tableName = "MY_TABLE_NAME"; @@ -53,8 +53,8 @@ public static void main(String[] args) { } public static void queryExternalSheetsPerm( - String datasetName, String tableName, String sourceUri, Schema schema, String query) { - try { + String datasetName, String tableName, String sourceUri, Schema schema, String query) throws BigQueryException, InterruptedException, IOException { + // try { // Create credentials with Drive & BigQuery API scopes. // Both APIs must be enabled for your project before running this code. @@ -91,9 +91,9 @@ public static void queryExternalSheetsPerm( .forEach(row -> row.forEach(val -> System.out.printf("%s,", val.toString()))); System.out.println("Query on external permanent table performed successfully."); - } catch (BigQueryException | InterruptedException | IOException e) { - System.out.println("Query not performed \n" + e.toString()); - } + // } catch (BigQueryException | InterruptedException | IOException e) { + // System.out.println("Query not performed \n" + e.toString()); + // // } } } // [END bigquery_query_external_sheets_perm] diff --git a/samples/snippets/src/test/java/com/example/bigquery/AddColumnLoadAppendIT.java b/samples/snippets/src/test/java/com/example/bigquery/AddColumnLoadAppendIT.java deleted file mode 100644 index 461c6dbe3..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/AddColumnLoadAppendIT.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.LegacySQLTypeName; -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class AddColumnLoadAppendIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private Schema schema; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - Assert.assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // create a test table. - tableName = "ADD_COLUMN_LOAD_APPEND_TEST_" + UUID.randomUUID().toString().substring(0, 8); - schema = - Schema.of( - Field.newBuilder("name", LegacySQLTypeName.STRING) - .setMode(Field.Mode.REQUIRED) - .build()); - - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testAddColumnLoadAppend() { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.csv"; - // Adding below additional column during the load job - Field newField = - Field.newBuilder("post_abbr", LegacySQLTypeName.STRING) - .setMode(Field.Mode.NULLABLE) - .build(); - List newFields = new ArrayList<>(schema.getFields()); - newFields.add(newField); - AddColumnLoadAppend.addColumnLoadAppend( - BIGQUERY_DATASET_NAME, tableName, sourceUri, Schema.of(newFields)); - assertThat(bout.toString()).contains("Column successfully added during load append job"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/AddEmptyColumnIT.java b/samples/snippets/src/test/java/com/example/bigquery/AddEmptyColumnIT.java deleted file mode 100644 index f5ce9add7..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/AddEmptyColumnIT.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.LegacySQLTypeName; -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class AddEmptyColumnIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - tableName = "AddEmptyColumnTestTable_" + UUID.randomUUID().toString().replace('-', '_'); - Schema schema = - Schema.of( - Field.of("booleanField", LegacySQLTypeName.BOOLEAN), - Field.of("numericField", LegacySQLTypeName.NUMERIC)); - - // Create table in dataset for testing - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); - } - - @After - public void tearDown() { - // clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void addEmptyColumn() { - String randomColumnName = "new_" + UUID.randomUUID().toString().replace('-', '_'); - AddEmptyColumn.addEmptyColumn(randomColumnName, BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()).contains("Empty column successfully added to table"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/AuthDriveScopeIT.java b/samples/snippets/src/test/java/com/example/bigquery/AuthDriveScopeIT.java index a846f7be8..93b1e1591 100644 --- a/samples/snippets/src/test/java/com/example/bigquery/AuthDriveScopeIT.java +++ b/samples/snippets/src/test/java/com/example/bigquery/AuthDriveScopeIT.java @@ -26,7 +26,9 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.Ignore; +@Ignore public class AuthDriveScopeIT { private final Logger log = Logger.getLogger(this.getClass().getName()); @@ -55,4 +57,4 @@ public void setAuthDriveScope() throws IOException { AuthDriveScope.setAuthDriveScope(); assertThat(bout.toString()).contains("Auth succeeded with multiple scopes."); } -} +} \ No newline at end of file diff --git a/samples/snippets/src/test/java/com/example/bigquery/AuthSnippetsIT.java b/samples/snippets/src/test/java/com/example/bigquery/AuthSnippetsIT.java deleted file mode 100644 index f365e4c5d..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/AuthSnippetsIT.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Tests for auth samples. */ -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class AuthSnippetsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testAuthSnippetsImplicit() throws Exception { - AuthSnippets.main(new String[] {"implicit"}); - String got = bout.toString(); - assertThat(got).contains("Datasets:"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/AuthorizeDatasetIT.java b/samples/snippets/src/test/java/com/example/bigquery/AuthorizeDatasetIT.java deleted file mode 100644 index c4facd5ef..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/AuthorizeDatasetIT.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2022 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.DatasetId; -import com.google.cloud.bigquery.testing.RemoteBigQueryHelper; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class AuthorizeDatasetIT { - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String userDatasetName; - private String srcDatasetName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private static final String GOOGLE_CLOUD_PROJECT = System.getenv("GOOGLE_CLOUD_PROJECT"); - private DatasetId sourceDatasetId; - private DatasetId userDatasetId; - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - userDatasetName = RemoteBigQueryHelper.generateDatasetName(); - srcDatasetName = RemoteBigQueryHelper.generateDatasetName(); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - CreateDataset.createDataset(userDatasetName); - CreateDataset.createDataset(srcDatasetName); - userDatasetId = DatasetId.of(GOOGLE_CLOUD_PROJECT, userDatasetName); - sourceDatasetId = DatasetId.of(GOOGLE_CLOUD_PROJECT, srcDatasetName); - } - - @After - public void tearDown() { - // Clean up - DeleteDataset.deleteDataset(GOOGLE_CLOUD_PROJECT, userDatasetName); - DeleteDataset.deleteDataset(GOOGLE_CLOUD_PROJECT, srcDatasetName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testCreateDataset() { - AuthorizeDataset.authorizeDataset(sourceDatasetId, userDatasetId); - assertThat(bout.toString()).contains(sourceDatasetId + " updated with the added authorization"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/AuthorizedViewTutorialIT.java b/samples/snippets/src/test/java/com/example/bigquery/AuthorizedViewTutorialIT.java deleted file mode 100644 index 89889e03f..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/AuthorizedViewTutorialIT.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class AuthorizedViewTutorialIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String sourceDatasetId; - private String sourceTableId; - private String sharedDatasetId; - private String sharedViewId; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - sourceDatasetId = "SOURCE_DATASET_TEST_" + UUID.randomUUID().toString().substring(0, 8); - sourceTableId = "SOURCE_TABLE_TEST_" + UUID.randomUUID().toString().substring(0, 8); - sharedDatasetId = "SHARED_DATASET_TEST_" + UUID.randomUUID().toString().substring(0, 8); - sharedViewId = "SHARED_VIEW_TEST_" + UUID.randomUUID().toString().substring(0, 8); - - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteDataset.deleteDataset(PROJECT_ID, sourceDatasetId); - DeleteDataset.deleteDataset(PROJECT_ID, sharedDatasetId); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testAuthorizedViewTutorial() { - AuthorizedViewTutorial.authorizedViewTutorial( - PROJECT_ID, sourceDatasetId, sourceTableId, sharedDatasetId, sharedViewId); - assertThat(bout.toString()).contains("Authorized view tutorial successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/BrowseTableIT.java b/samples/snippets/src/test/java/com/example/bigquery/BrowseTableIT.java deleted file mode 100644 index ad4853363..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/BrowseTableIT.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class BrowseTableIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - tableName = "MY_TABLE_NAME_" + UUID.randomUUID().toString().replace("-", "_"); - Schema schema = - Schema.of( - Field.of("stringField", StandardSQLTypeName.STRING), - Field.of("booleanField", StandardSQLTypeName.BOOL)); - - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testBrowseTable() { - BrowseTable.browseTable(BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()).contains("Query ran successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CancelJobIT.java b/samples/snippets/src/test/java/com/example/bigquery/CancelJobIT.java deleted file mode 100644 index 49d9be275..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CancelJobIT.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class CancelJobIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testCreateJob() { - String query = "SELECT country_name from `bigquery-public-data.utility_us.country_code_iso`"; - - CancelJob.cancelJob(query); - assertThat(bout.toString()).contains("Job canceled successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CopyMultipleTablesIT.java b/samples/snippets/src/test/java/com/example/bigquery/CopyMultipleTablesIT.java deleted file mode 100644 index e0d175c86..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CopyMultipleTablesIT.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CopyMultipleTablesIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String datasetName; - private String tableName; - private String sourceTable1Name; - private String sourceTable2Name; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws Exception { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Create a new destination table for each test since existing table cannot be overwritten - datasetName = "MY_DATASET_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - tableName = "COPY_MULTIPLE_TABLE_TEST" + UUID.randomUUID().toString().substring(0, 8); - sourceTable1Name = - "COPY_MULTIPLE_TABLE_SOURCE1_TEST" + UUID.randomUUID().toString().substring(0, 8); - sourceTable2Name = - "COPY_MULTIPLE_TABLE_SOURCE2_TEST" + UUID.randomUUID().toString().substring(0, 8); - CreateDataset.createDataset(datasetName); - - Schema schema = - Schema.of( - Field.of("timestampField", StandardSQLTypeName.TIMESTAMP), - Field.of("stringField", StandardSQLTypeName.STRING), - Field.of("booleanField", StandardSQLTypeName.BOOL)); - CreateTable.createTable(datasetName, tableName, schema); - CreateTable.createTable(datasetName, sourceTable1Name, schema); - CreateTable.createTable(datasetName, sourceTable2Name, schema); - } - - @After - public void tearDown() { - // Clean up - DeleteDataset.deleteDataset(PROJECT_ID, datasetName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testCopyMultipleTables() { - CopyMultipleTables.copyMultipleTables( - datasetName, tableName, sourceTable1Name, sourceTable2Name); - assertThat(bout.toString()).contains("Table copied successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CopyTableCmekIT.java b/samples/snippets/src/test/java/com/example/bigquery/CopyTableCmekIT.java deleted file mode 100644 index 7a601cf95..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CopyTableCmekIT.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.EncryptionConfiguration; -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class CopyTableCmekIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String sourceTableName; - private String destinationTableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - private static final String BIGQUERY_KMS_KEY_NAME = requireEnvVar("BIGQUERY_KMS_KEY_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - requireEnvVar("BIGQUERY_KMS_KEY_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - sourceTableName = "MY_SOURCE_TABLE_CMEK_TEST" + UUID.randomUUID().toString().substring(0, 8); - destinationTableName = - "MY_DESTINATION_TABLE_CMEK_TEST" + UUID.randomUUID().toString().substring(0, 8); - Schema schema = - Schema.of( - Field.of("stringField", StandardSQLTypeName.STRING), - Field.of("booleanField", StandardSQLTypeName.BOOL)); - EncryptionConfiguration configuration = - EncryptionConfiguration.newBuilder().setKmsKeyName(BIGQUERY_KMS_KEY_NAME).build(); - CreateTableCmek.createTableCmek(BIGQUERY_DATASET_NAME, sourceTableName, schema, configuration); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, sourceTableName); - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, destinationTableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testCopyTableCmek() { - EncryptionConfiguration configuration = - EncryptionConfiguration.newBuilder().setKmsKeyName(BIGQUERY_KMS_KEY_NAME).build(); - CopyTableCmek.copyTableCmek( - BIGQUERY_DATASET_NAME, - sourceTableName, - BIGQUERY_DATASET_NAME, - destinationTableName, - configuration); - assertThat(bout.toString()).contains("Table cmek copied successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CopyTableIT.java b/samples/snippets/src/test/java/com/example/bigquery/CopyTableIT.java deleted file mode 100644 index ccf150740..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CopyTableIT.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CopyTableIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String sourceTable; - private String destinationTable; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() throws Exception { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // Create a new destination and source table for each test since existing table cannot be - // overwritten - sourceTable = "SOURCE_TABLE_TEST" + UUID.randomUUID().toString().substring(0, 8); - destinationTable = "DESTINATION_TABLE_TEST" + UUID.randomUUID().toString().substring(0, 8); - // Adding an arbitrary table schema so we aren't copying nothing. - Schema schema = - Schema.of( - Field.of("stringField", StandardSQLTypeName.STRING), - Field.of("booleanField", StandardSQLTypeName.BOOL)); - - CreateTable.createTable(BIGQUERY_DATASET_NAME, destinationTable, schema); - CreateTable.createTable(BIGQUERY_DATASET_NAME, sourceTable, schema); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, destinationTable); - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, sourceTable); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testCopyTable() { - CopyTable.copyTable( - BIGQUERY_DATASET_NAME, sourceTable, BIGQUERY_DATASET_NAME, destinationTable); - assertThat(bout.toString()).contains("Table copied successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateAndQueryRepeatedRecordFieldIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateAndQueryRepeatedRecordFieldIT.java deleted file mode 100644 index 56ad47a5d..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateAndQueryRepeatedRecordFieldIT.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreateAndQueryRepeatedRecordFieldIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - tableName = "MY_TABLE_NAME_" + UUID.randomUUID().toString().replace("-", "_"); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testCreateAndQueryRepeatedRecordField() { - CreateAndQueryRepeatedRecordField.createAndQueryRepeatedRecordField( - BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()) - .contains("Query with Array of struct parameters performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateClusteredTableIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateClusteredTableIT.java deleted file mode 100644 index 2ea6cc536..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateClusteredTableIT.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import com.google.common.collect.ImmutableList; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreateClusteredTableIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - tableName = "MY_CLUSTERED_TABLE_TEST" + UUID.randomUUID().toString().substring(0, 8); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void createClusteredTable() { - Schema schema = - Schema.of( - Field.of("name", StandardSQLTypeName.STRING), - Field.of("post_abbr", StandardSQLTypeName.STRING), - Field.of("date", StandardSQLTypeName.DATE)); - - CreateClusteredTable.createClusteredTable( - BIGQUERY_DATASET_NAME, tableName, schema, ImmutableList.of("name", "post_abbr")); - - assertThat(bout.toString()).contains("Clustered table created successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateDatasetAwsIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateDatasetAwsIT.java deleted file mode 100644 index 6f59f0c49..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateDatasetAwsIT.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class CreateDatasetAwsIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "aws-us-east-1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String datasetName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String OMNI_PROJECT_ID = requireEnvVar("OMNI_PROJECT_ID"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("OMNI_PROJECT_ID"); - } - - @Before - public void setUp() { - datasetName = "CREATE_DATASET_AWS_TEST_" + ID; - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteDataset.deleteDataset(OMNI_PROJECT_ID, datasetName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testCreateDatasetAws() { - CreateDatasetAws.createDatasetAws(OMNI_PROJECT_ID, datasetName, LOCATION); - assertThat(bout.toString()).contains("Aws dataset created successfully :"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateDatasetIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateDatasetIT.java deleted file mode 100644 index 1fbf4f546..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateDatasetIT.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.testing.RemoteBigQueryHelper; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreateDatasetIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String datasetName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String GOOGLE_CLOUD_PROJECT = System.getenv("GOOGLE_CLOUD_PROJECT"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - datasetName = RemoteBigQueryHelper.generateDatasetName(); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteDataset.deleteDataset(GOOGLE_CLOUD_PROJECT, datasetName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testCreateDataset() { - CreateDataset.createDataset(datasetName); - assertThat(bout.toString()).contains(datasetName + " created successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateDatasetWithRegionalEndpointIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateDatasetWithRegionalEndpointIT.java deleted file mode 100644 index da6f4afd7..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateDatasetWithRegionalEndpointIT.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class CreateDatasetWithRegionalEndpointIT { - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testCreateDatasetWithRegionalEndpoint() { - CreateDatasetWithRegionalEndpoint.createDatasetWithRegionalEndpoint(); - assertThat(bout.toString().contains("Region of dataset: us-east4")); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateExternalTableAwsIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateExternalTableAwsIT.java deleted file mode 100644 index 80be0bb26..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateExternalTableAwsIT.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.CsvOptions; -import com.google.cloud.bigquery.ExternalTableDefinition; -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class CreateExternalTableAwsIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String OMNI_PROJECT_ID = requireEnvVar("OMNI_PROJECT_ID"); - private static final String OMNI_DATASET_NAME = requireEnvVar("OMNI_DATASET_NAME"); - private static final String AWS_READ_CONNECTION_ID = requireEnvVar("AWS_READ_CONNECTION_ID"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("OMNI_PROJECT_ID"); - requireEnvVar("OMNI_DATASET_NAME"); - requireEnvVar("AWS_READ_CONNECTION_ID"); - } - - @Before - public void setUp() { - tableName = "CREATE_EXTERNAL_TABLE_AWS_TEST_" + ID; - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testCreateExternalTableAws() { - String sourceUri = "s3://omni-samples-test-bucket/us-states.csv"; - Schema schema = - Schema.of( - Field.of("name", StandardSQLTypeName.STRING), - Field.of("post_abbr", StandardSQLTypeName.STRING)); - CsvOptions options = CsvOptions.newBuilder().setSkipLeadingRows(1).build(); - ExternalTableDefinition externalTableDefinition = - ExternalTableDefinition.newBuilder(sourceUri, options) - .setConnectionId(AWS_READ_CONNECTION_ID) - .setSchema(schema) - .build(); - CreateExternalTableAws.createExternalTableAws( - OMNI_PROJECT_ID, OMNI_DATASET_NAME, tableName, externalTableDefinition); - assertThat(bout.toString()).contains("Aws external table created successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateIamPolicyIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateIamPolicyIT.java deleted file mode 100644 index 420d81e40..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateIamPolicyIT.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreateIamPolicyIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // create a temporary table - tableName = "CREATE_POLICY_TABLE_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, Schema.of()); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testCreateIamPolicy() { - CreateIamPolicy.createIamPolicy(BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()).contains("Iam policy created successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateJobIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateJobIT.java deleted file mode 100644 index 91242e922..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateJobIT.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class CreateJobIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testCreateJob() { - String query = "SELECT country_name from `bigquery-public-data.utility_us.country_code_iso`"; - - CreateJob.createJob(query); - assertThat(bout.toString()).contains("Job created successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateMaterializedViewIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateMaterializedViewIT.java deleted file mode 100644 index 7d4ec84b2..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateMaterializedViewIT.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreateMaterializedViewIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private String materializedViewName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - tableName = "MY_TABLE_NAME_TEST_" + ID; - materializedViewName = "MY_MATERIALIZED_VIEW_NAME_TEST_" + ID; - - Schema schema = - Schema.of( - Field.of("timestampField", StandardSQLTypeName.TIMESTAMP), - Field.of("stringField", StandardSQLTypeName.STRING), - Field.of("booleanField", StandardSQLTypeName.BOOL)); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, materializedViewName); - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testCreateMaterializedView() { - String query = - String.format( - "SELECT MAX(TimestampField) AS TimestampField, StringField, " - + "MAX(BooleanField) AS BooleanField " - + "FROM %s.%s GROUP BY StringField", - BIGQUERY_DATASET_NAME, tableName); - CreateMaterializedView.createMaterializedView( - BIGQUERY_DATASET_NAME, materializedViewName, query); - assertThat(bout.toString()).contains("Materialized view created successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateModelIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateModelIT.java deleted file mode 100644 index dd18a02f1..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateModelIT.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreateModelIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String modelName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - modelName = "MY_MODEL_NAME_TEST_" + UUID.randomUUID().toString().replace('-', '_'); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteModel.deleteModel(BIGQUERY_DATASET_NAME, modelName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testCreateModel() { - String sql = - "CREATE MODEL `" - + BIGQUERY_DATASET_NAME - + "." - + modelName - + "`" - + "OPTIONS ( " - + "model_type='linear_reg', " - + "max_iterations=1, " - + "learn_rate=0.4, " - + "learn_rate_strategy='constant' " - + ") AS ( " - + "SELECT 'a' AS f1, 2.0 AS label " - + "UNION ALL " - + "SELECT 'b' AS f1, 3.8 AS label " - + ")"; - CreateModel.createModel(sql); - assertThat(bout.toString()).contains("Model created successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreatePartitionedTableIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreatePartitionedTableIT.java deleted file mode 100644 index 7a73c783d..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreatePartitionedTableIT.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreatePartitionedTableIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - tableName = "MY_PARTITIONED_TABLE_TEST_" + UUID.randomUUID().toString().substring(0, 8); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testCreatePartitionedTable() { - Schema schema = - Schema.of( - Field.of("name", StandardSQLTypeName.STRING), - Field.of("post_abbr", StandardSQLTypeName.STRING), - Field.of("date", StandardSQLTypeName.DATE)); - CreatePartitionedTable.createPartitionedTable(BIGQUERY_DATASET_NAME, tableName, schema); - assertThat(bout.toString()).contains("Partitioned table created successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateRangePartitionedTableIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateRangePartitionedTableIT.java deleted file mode 100644 index 37a2a3bcf..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateRangePartitionedTableIT.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreateRangePartitionedTableIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - tableName = "RANGE_PARTITIONED_TABLE_TEST" + UUID.randomUUID().toString().replace('-', '_'); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testCreateRangePartitionedTable() { - Schema schema = - Schema.of( - Field.of("integerField", StandardSQLTypeName.INT64), - Field.of("stringField", StandardSQLTypeName.STRING), - Field.of("booleanField", StandardSQLTypeName.BOOL), - Field.of("dateField", StandardSQLTypeName.DATE)); - - CreateRangePartitionedTable.createRangePartitionedTable( - BIGQUERY_DATASET_NAME, tableName, schema); - - assertThat(bout.toString()).contains("Range partitioned table created successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateRoutineDdlIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateRoutineDdlIT.java deleted file mode 100644 index ae362f90f..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateRoutineDdlIT.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreateRoutineDdlIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String routineName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - routineName = "MY_ROUTINE_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteRoutine.deleteRoutine(BIGQUERY_DATASET_NAME, routineName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testCreateRoutineDdl() { - String sql = - "CREATE FUNCTION " - + "`" - + PROJECT_ID - + "." - + BIGQUERY_DATASET_NAME - + "." - + routineName - + "`" - + "( arr ARRAY>) AS " - + "( (SELECT SUM(IF(elem.name = \"foo\",elem.val,null)) FROM UNNEST(arr) AS elem))"; - CreateRoutineDdl.createRoutineDdl(sql); - assertThat(bout.toString()).contains("Routine created successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateRoutineIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateRoutineIT.java deleted file mode 100644 index 6568c3324..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateRoutineIT.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreateRoutineIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String routineName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - routineName = "MY_ROUTINE_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteRoutine.deleteRoutine(BIGQUERY_DATASET_NAME, routineName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testCreateRoutine() { - CreateRoutine.createRoutine(BIGQUERY_DATASET_NAME, routineName); - assertThat(bout.toString()).contains("Routine created successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateTableCmekIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateTableCmekIT.java deleted file mode 100644 index 7169a8fce..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateTableCmekIT.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.EncryptionConfiguration; -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class CreateTableCmekIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - private static final String BIGQUERY_KMS_KEY_NAME = requireEnvVar("BIGQUERY_KMS_KEY_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - requireEnvVar("BIGQUERY_KMS_KEY_NAME"); - } - - @Before - public void setUp() { - tableName = "MY_TABLE_CMEK_TEST" + UUID.randomUUID().toString().substring(0, 8); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testCreateTableCmek() { - Schema schema = - Schema.of( - Field.of("stringField", StandardSQLTypeName.STRING), - Field.of("booleanField", StandardSQLTypeName.BOOL)); - EncryptionConfiguration configuration = - EncryptionConfiguration.newBuilder().setKmsKeyName(BIGQUERY_KMS_KEY_NAME).build(); - CreateTableCmek.createTableCmek(BIGQUERY_DATASET_NAME, tableName, schema, configuration); - assertThat(bout.toString()).contains("Table cmek created successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateTableExternalHivePartitionedIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateTableExternalHivePartitionedIT.java deleted file mode 100644 index b460dec9b..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateTableExternalHivePartitionedIT.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreateTableExternalHivePartitionedIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - // Create a test table - tableName = "SET_HIVEPARTITIONINGOPTIONS_FROM_GCS_TEST_" + ID; - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testCreateTableExternalHivePartitioned() { - String sourceUri = "gs://cloud-samples-data/bigquery/hive-partitioning-samples/customlayout/*"; - String sourceUriPrefix = - "gs://cloud-samples-data/bigquery/hive-partitioning-samples/customlayout/{pkey:STRING}/"; - CreateTableExternalHivePartitioned.createTableExternalHivePartitioned( - BIGQUERY_DATASET_NAME, tableName, sourceUriPrefix, sourceUri); - assertThat(bout.toString()).contains("External table created using hivepartitioningoptions"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateTableIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateTableIT.java index af5104c1c..b919e305c 100644 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateTableIT.java +++ b/samples/snippets/src/test/java/com/example/bigquery/CreateTableIT.java @@ -31,7 +31,9 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.Ignore; +@Ignore public class CreateTableIT { private final Logger log = Logger.getLogger(this.getClass().getName()); @@ -81,4 +83,4 @@ public void testCreateTable() { CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); assertThat(bout.toString()).contains("Table created successfully"); } -} +} \ No newline at end of file diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateTableWithoutSchemaIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateTableWithoutSchemaIT.java deleted file mode 100644 index dd686d179..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateTableWithoutSchemaIT.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreateTableWithoutSchemaIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - tableName = "MY_TABLE_TEST" + UUID.randomUUID().toString().replace('-', '_'); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testCreateTableWithoutSchema() { - CreateTableWithoutSchema.createTableWithoutSchema(BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()).contains("Table created successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateTablesWithPrimaryAndForeignKeysIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateTablesWithPrimaryAndForeignKeysIT.java deleted file mode 100644 index 00ba8fa44..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateTablesWithPrimaryAndForeignKeysIT.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreateTablesWithPrimaryAndForeignKeysIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableNamePk; - private String tableNameFk; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - tableNamePk = "MY_TABLE_NAME_" + UUID.randomUUID().toString().replace("-", "_"); - tableNameFk = "MY_TABLE_NAME_" + UUID.randomUUID().toString().replace("-", "_"); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableNamePk); - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableNameFk); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testCreateAndQueryRepeatedRecordField() { - CreateTablesWithPrimaryAndForeignKeys.createTablesWithPrimaryAndForeignKeys( - BIGQUERY_DATASET_NAME, tableNamePk, tableNameFk); - assertThat(bout.toString()) - .contains("Tables with primary and foreign keys created successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateViewIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateViewIT.java deleted file mode 100644 index 6b4c7e38a..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/CreateViewIT.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreateViewIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private String viewName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - tableName = "MY_TABLE_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - viewName = "MY_VIEW_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - - Schema schema = - Schema.of( - Field.of("timestampField", StandardSQLTypeName.TIMESTAMP), - Field.of("stringField", StandardSQLTypeName.STRING), - Field.of("booleanField", StandardSQLTypeName.BOOL)); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, viewName); - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testCreateView() { - String query = - String.format( - "SELECT timestampField, stringField, booleanField FROM %s.%s", - BIGQUERY_DATASET_NAME, tableName); - CreateView.createView(BIGQUERY_DATASET_NAME, viewName, query); - assertThat(bout.toString()).contains("View created successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/DatasetExistsIT.java b/samples/snippets/src/test/java/com/example/bigquery/DatasetExistsIT.java deleted file mode 100644 index 45b6b6b17..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/DatasetExistsIT.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class DatasetExistsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String datasetName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // create a temporary dataset - datasetName = "MY_DATASET_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateDataset.createDataset(datasetName); - } - - @After - public void tearDown() { - // delete a temporary dataset - DeleteDataset.deleteDataset(PROJECT_ID, datasetName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testDatasetExists() { - DatasetExists.datasetExists(datasetName); - assertThat(bout.toString()).contains("Dataset already exist"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/DdlCreateViewIT.java b/samples/snippets/src/test/java/com/example/bigquery/DdlCreateViewIT.java deleted file mode 100644 index 146e5670d..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/DdlCreateViewIT.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class DdlCreateViewIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String viewName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - viewName = "MY_VIEW_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, viewName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testDdlCreateView() { - String sql = - "CREATE VIEW " - + "`" - + PROJECT_ID - + "." - + BIGQUERY_DATASET_NAME - + "." - + viewName - + "`" - + " OPTIONS(" - + " expiration_timestamp=TIMESTAMP_ADD(" - + " CURRENT_TIMESTAMP(), INTERVAL 48 HOUR)," - + " friendly_name=\"new_view\"," - + " description=\"a view that expires in 2 days\"," - + " labels=[(\"org_unit\", \"development\")]" - + " )" - + " AS SELECT name, state, year, number" - + " FROM `bigquery-public-data.usa_names.usa_1910_current`" - + " WHERE state LIKE 'W%'"; - DdlCreateView.ddlCreateView(sql); - assertThat(bout.toString()).contains("View created successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/DeleteDatasetAndContentsIT.java b/samples/snippets/src/test/java/com/example/bigquery/DeleteDatasetAndContentsIT.java deleted file mode 100644 index 6151e309b..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/DeleteDatasetAndContentsIT.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class DeleteDatasetAndContentsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String datasetName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // create a temporary dataset - datasetName = "MY_DATASET_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateDataset.createDataset(datasetName); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testDeleteDatasetAndContents() { - DeleteDatasetAndContents.deleteDatasetAndContents(PROJECT_ID, datasetName); - assertThat(bout.toString()).contains("Dataset deleted with contents successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/DeleteDatasetIT.java b/samples/snippets/src/test/java/com/example/bigquery/DeleteDatasetIT.java deleted file mode 100644 index 27ab2e58d..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/DeleteDatasetIT.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import com.google.cloud.bigquery.BigQuery; -import com.google.cloud.bigquery.BigQueryOptions; -import com.google.cloud.bigquery.DatasetId; -import com.google.cloud.bigquery.DatasetInfo; -import com.google.cloud.bigquery.testing.RemoteBigQueryHelper; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class DeleteDatasetIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void deleteDataset() { - BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService(); - - // create the dataset to be deleted - String generatedDatasetName = RemoteBigQueryHelper.generateDatasetName(); - DatasetInfo datasetInfo = DatasetInfo.newBuilder(generatedDatasetName).build(); - bigquery.create(datasetInfo); - - // delete the dataset that was just created - DatasetId datasetId = DatasetId.of(bigquery.getOptions().getProjectId(), generatedDatasetName); - DeleteDataset.deleteDataset(datasetId.getProject(), generatedDatasetName); - - assertThat(bout.toString()).contains("Dataset deleted successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/DeleteLabelDatasetIT.java b/samples/snippets/src/test/java/com/example/bigquery/DeleteLabelDatasetIT.java deleted file mode 100644 index 1136e18f2..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/DeleteLabelDatasetIT.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class DeleteLabelDatasetIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String datasetName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // create a temporary dataset - datasetName = "MY_DATASET_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateDataset.createDataset(datasetName); - // add a label on dataset - LabelDataset.labelDataset(datasetName); - } - - @After - public void tearDown() { - // delete a temporary dataset - DeleteDataset.deleteDataset(PROJECT_ID, datasetName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testDeleteLabelDataset() { - DeleteLabelDataset.deleteLabelDataset(datasetName); - assertThat(bout.toString()).contains("Dataset label deleted successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/DeleteLabelTableIT.java b/samples/snippets/src/test/java/com/example/bigquery/DeleteLabelTableIT.java deleted file mode 100644 index f1ad6be63..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/DeleteLabelTableIT.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertNotNull; - -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class DeleteLabelTableIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // create a temporary table - tableName = "MY_TABLE_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, Schema.of()); - // add label on a table - LabelTable.labelTable(BIGQUERY_DATASET_NAME, tableName); - } - - @After - public void tearDown() { - // delete a temporary table - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testDeleteLabelTable() { - DeleteLabelTable.deleteLabelTable(BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()).contains("Table label deleted successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/DeleteMaterializedViewIT.java b/samples/snippets/src/test/java/com/example/bigquery/DeleteMaterializedViewIT.java deleted file mode 100644 index bd5be8fe9..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/DeleteMaterializedViewIT.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class DeleteMaterializedViewIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private String materializedViewName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - tableName = "MY_TABLE_NAME_TEST_" + ID; - materializedViewName = "MY_ALTER_MATERIALIZED_VIEW_NAME_TEST_" + ID; - - Schema schema = - Schema.of( - Field.of("timestampField", StandardSQLTypeName.TIMESTAMP), - Field.of("stringField", StandardSQLTypeName.STRING), - Field.of("booleanField", StandardSQLTypeName.BOOL)); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); - String query = - String.format( - "SELECT MAX(TimestampField) AS TimestampField, StringField, " - + "MAX(BooleanField) AS BooleanField " - + "FROM %s.%s GROUP BY StringField", - BIGQUERY_DATASET_NAME, tableName); - CreateMaterializedView.createMaterializedView( - BIGQUERY_DATASET_NAME, materializedViewName, query); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testDeleteMaterializedView() { - DeleteMaterializedView.deleteMaterializedView(BIGQUERY_DATASET_NAME, materializedViewName); - assertThat(bout.toString()).contains("Materialized view deleted successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/DeleteModelIT.java b/samples/snippets/src/test/java/com/example/bigquery/DeleteModelIT.java deleted file mode 100644 index 9df25a658..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/DeleteModelIT.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class DeleteModelIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String modelName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Create a new model to be deleted - modelName = "MY_MODEL_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - String sql = - "CREATE MODEL `" - + BIGQUERY_DATASET_NAME - + "." - + modelName - + "`" - + "OPTIONS ( " - + "model_type='linear_reg', " - + "max_iterations=1, " - + "learn_rate=0.4, " - + "learn_rate_strategy='constant' " - + ") AS ( " - + "SELECT 'a' AS f1, 2.0 AS label " - + "UNION ALL " - + "SELECT 'b' AS f1, 3.8 AS label " - + ")"; - CreateModel.createModel(sql); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testDeleteModel() { - // Delete the model that was just created - DeleteModel.deleteModel(BIGQUERY_DATASET_NAME, modelName); - assertThat(bout.toString()).contains("Model deleted successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/DeleteRoutineIT.java b/samples/snippets/src/test/java/com/example/bigquery/DeleteRoutineIT.java deleted file mode 100644 index 395979241..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/DeleteRoutineIT.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class DeleteRoutineIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String routineName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // create a temporary routine - routineName = "MY_ROUTINE_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateRoutine.createRoutine(BIGQUERY_DATASET_NAME, routineName); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testDeleteRoutine() { - DeleteRoutine.deleteRoutine(BIGQUERY_DATASET_NAME, routineName); - assertThat(bout.toString()).contains("Routine deleted successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/DeleteTableIT.java b/samples/snippets/src/test/java/com/example/bigquery/DeleteTableIT.java deleted file mode 100644 index 95d0afa17..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/DeleteTableIT.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class DeleteTableIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // Create a new table to be deleted - tableName = "GCLOUD_TEST_TABLE_TEMP_" + UUID.randomUUID().toString().substring(0, 8); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, null); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testDeleteTable() { - // Delete the table that was just created - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()).contains("Table deleted successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/ExportQueryResultsToS3IT.java b/samples/snippets/src/test/java/com/example/bigquery/ExportQueryResultsToS3IT.java deleted file mode 100644 index b014bde60..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/ExportQueryResultsToS3IT.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class ExportQueryResultsToS3IT { - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String OMNI_PROJECT_ID = requireEnvVar("OMNI_PROJECT_ID"); - private static final String OMNI_DATASET_NAME = requireEnvVar("OMNI_DATASET_NAME"); - private static final String OMNI_EXTERNAL_TABLE_NAME = requireEnvVar("OMNI_EXTERNAL_TABLE_NAME"); - private static final String AWS_WRITE_CONNECTION_ID = requireEnvVar("AWS_WRITE_CONNECTION_ID"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("OMNI_PROJECT_ID"); - requireEnvVar("OMNI_DATASET_NAME"); - requireEnvVar("OMNI_EXTERNAL_TABLE_NAME"); - requireEnvVar("AWS_WRITE_CONNECTION_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testQueryExternalTableAws() throws InterruptedException { - String destinationUri = "s3://omni-samples-test-bucket/client-lib-test*"; - String format = "CSV"; - String query = - String.format( - "EXPORT DATA WITH CONNECTION `%s` OPTIONS(uri='%s', format='%s') " - + "AS SELECT * FROM %s.%s.%s WHERE name LIKE 'W%%'", - AWS_WRITE_CONNECTION_ID, - destinationUri, - format, - OMNI_PROJECT_ID, - OMNI_DATASET_NAME, - OMNI_EXTERNAL_TABLE_NAME); - ExportQueryResultsToS3.exportQueryResultsToS3(query); - assertThat(bout.toString()).contains("Query results exported to Amazon S3 successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/ExtractModelIT.java b/samples/snippets/src/test/java/com/example/bigquery/ExtractModelIT.java deleted file mode 100644 index ac0d13111..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/ExtractModelIT.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class ExtractModelIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String GCS_BUCKET = System.getenv("GCS_BUCKET"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GCS_BUCKET"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testExtractModel() throws InterruptedException { - String projectId = "bigquery-public-data"; - String datasetName = "samples"; - String modelName = "model"; - String destinationUri = "gs://" + GCS_BUCKET + "/extractModel"; - // Extract model content to GCS - ExtractModel.extractModel(projectId, datasetName, modelName, destinationUri); - assertThat(bout.toString()).contains("Model extract successful"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/ExtractTableCompressedIT.java b/samples/snippets/src/test/java/com/example/bigquery/ExtractTableCompressedIT.java deleted file mode 100644 index 4e551ed81..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/ExtractTableCompressedIT.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class ExtractTableCompressedIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String GCS_BUCKET = System.getenv("GCS_BUCKET"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GCS_BUCKET"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testExtractTableCompressed() { - String projectId = "bigquery-public-data"; - String datasetName = "samples"; - String tableName = "shakespeare"; - String destinationUri = "gs://" + GCS_BUCKET + "/extractTest.csv"; - String dataFormat = "CSV"; - String compressed = "gzip"; - - // Extract table content to GCS in CSV format and gzip compressed - ExtractTableCompressed.extractTableCompressed( - projectId, datasetName, tableName, destinationUri, dataFormat, compressed); - assertThat(bout.toString()).contains("Table extract compressed successful"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/ExtractTableToCsvIT.java b/samples/snippets/src/test/java/com/example/bigquery/ExtractTableToCsvIT.java deleted file mode 100644 index 838a989b6..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/ExtractTableToCsvIT.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class ExtractTableToCsvIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String GCS_BUCKET = System.getenv("GCS_BUCKET"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GCS_BUCKET"); - } - - @Before - public void setUp() throws Exception { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testExtractTableToJson() { - String projectId = "bigquery-public-data"; - String datasetName = "samples"; - String tableName = "shakespeare"; - String destinationUri = "gs://" + GCS_BUCKET + "/extractTest.csv"; - String dataFormat = "CSV"; - - // Extract table content to GCS in CSV format - ExtractTableToCsv.extractTableToCsv( - projectId, datasetName, tableName, destinationUri, dataFormat); - assertThat(bout.toString()) - .contains("Table export successful. Check in GCS bucket for the " + dataFormat + " file."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/ExtractTableToJsonIT.java b/samples/snippets/src/test/java/com/example/bigquery/ExtractTableToJsonIT.java deleted file mode 100644 index 393188c7e..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/ExtractTableToJsonIT.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.FormatOptions; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class ExtractTableToJsonIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String GCS_BUCKET = System.getenv("GCS_BUCKET"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GCS_BUCKET"); - } - - @Before - public void setUp() throws Exception { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testExtractTableToJson() { - String projectId = "bigquery-public-data"; - String datasetName = "samples"; - String tableName = "shakespeare"; - String destinationUri = "gs://" + GCS_BUCKET + "/extractTest.json"; - // FormatOptions.json() is not "JSON" but "NEWLINE_DELIMITED_JSON" - String dataFormat = FormatOptions.json().getType(); - - // Extract table content to GCS in JSON format - ExtractTableToJson.extractTableToJson( - projectId, datasetName, tableName, destinationUri, dataFormat); - assertThat(bout.toString()) - .contains("Table export successful. Check in GCS bucket for the " + dataFormat + " file."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/GetDatasetInfoIT.java b/samples/snippets/src/test/java/com/example/bigquery/GetDatasetInfoIT.java deleted file mode 100644 index ab5019ad4..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/GetDatasetInfoIT.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class GetDatasetInfoIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String GOOGLE_CLOUD_PROJECT = System.getenv("BIGQUERY_PROJECT_ID"); - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void getDatasetInfo() { - GetDatasetInfo.getDatasetInfo(GOOGLE_CLOUD_PROJECT, BIGQUERY_DATASET_NAME); - assertThat(bout.toString()).contains("Dataset info retrieved successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/GetDatasetLabelsIT.java b/samples/snippets/src/test/java/com/example/bigquery/GetDatasetLabelsIT.java deleted file mode 100644 index 443f3698f..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/GetDatasetLabelsIT.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class GetDatasetLabelsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String datasetName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // create a temporary dataset - datasetName = "MY_DATASET_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateDataset.createDataset(datasetName); - // add a label on dataset - LabelDataset.labelDataset(datasetName); - } - - @After - public void tearDown() { - // delete a temporary dataset - DeleteDataset.deleteDataset(PROJECT_ID, datasetName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testGetDatasetLabels() { - GetDatasetLabels.getDatasetLabels(datasetName); - assertThat(bout.toString()).contains("Retrieved labels successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/GetJobIT.java b/samples/snippets/src/test/java/com/example/bigquery/GetJobIT.java deleted file mode 100644 index 8d99fd89a..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/GetJobIT.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class GetJobIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String jobName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - String query = "SELECT country_name from `bigquery-public-data.utility_us.country_code_iso`"; - CreateJob.createJob(query); - String result = bout.toString(); - jobName = result.substring(result.lastIndexOf(".") + 1); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testGetJob() { - GetJob.getJob(jobName); - assertThat(bout.toString()).contains("Job retrieved successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/GetModelIT.java b/samples/snippets/src/test/java/com/example/bigquery/GetModelIT.java deleted file mode 100644 index 7a1c931ee..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/GetModelIT.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class GetModelIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String modelName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Create a new model to be deleted - modelName = "MY_MODEL_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - String sql = - "CREATE MODEL `" - + BIGQUERY_DATASET_NAME - + "." - + modelName - + "`" - + "OPTIONS ( " - + "model_type='linear_reg', " - + "max_iterations=1, " - + "learn_rate=0.4, " - + "learn_rate_strategy='constant' " - + ") AS ( " - + "SELECT 'a' AS f1, 2.0 AS label " - + "UNION ALL " - + "SELECT 'b' AS f1, 3.8 AS label " - + ")"; - CreateModel.createModel(sql); - } - - @After - public void tearDown() { - // Clean up - DeleteModel.deleteModel(BIGQUERY_DATASET_NAME, modelName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testGetModel() { - GetModel.getModel(BIGQUERY_DATASET_NAME, modelName); - assertThat(bout.toString()).contains("Successfully retrieved model"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/GetRoutineIT.java b/samples/snippets/src/test/java/com/example/bigquery/GetRoutineIT.java deleted file mode 100644 index a88364254..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/GetRoutineIT.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class GetRoutineIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String routineName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // create a temporary routine - routineName = "MY_ROUTINE_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateRoutine.createRoutine(BIGQUERY_DATASET_NAME, routineName); - } - - @After - public void tearDown() { - // Clean up - DeleteRoutine.deleteRoutine(BIGQUERY_DATASET_NAME, routineName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testGetRoutine() { - GetRoutine.getRoutine(BIGQUERY_DATASET_NAME, routineName); - assertThat(bout.toString()).contains("Routine retrieved successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/GetTableIT.java b/samples/snippets/src/test/java/com/example/bigquery/GetTableIT.java deleted file mode 100644 index e16db3e9d..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/GetTableIT.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class GetTableIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() throws Exception { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testGetTable() { - // Get shakespeare table from bigquery-public-data:samples dataset - GetTable.getTable("bigquery-public-data", "samples", "shakespeare"); - assertThat(bout.toString()).contains("Table info:"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/GetTableLabelsIT.java b/samples/snippets/src/test/java/com/example/bigquery/GetTableLabelsIT.java deleted file mode 100644 index a5e9bc453..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/GetTableLabelsIT.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertNotNull; - -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class GetTableLabelsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // create a temporary table - tableName = "MY_TABLE_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, Schema.of()); - // add label on a table - LabelTable.labelTable(BIGQUERY_DATASET_NAME, tableName); - } - - @After - public void tearDown() { - // delete a temporary table - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testGetTableLabels() { - GetTableLabels.getTableLabels(BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()).contains("Retrieved labels successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/GetViewIT.java b/samples/snippets/src/test/java/com/example/bigquery/GetViewIT.java deleted file mode 100644 index 06539416b..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/GetViewIT.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class GetViewIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private String viewName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Create a new table to be deleted - tableName = "MY_TABLE_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - viewName = "MY_VIEW_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - - Schema schema = - Schema.of( - Field.of("timestampField", StandardSQLTypeName.TIMESTAMP), - Field.of("stringField", StandardSQLTypeName.STRING), - Field.of("booleanField", StandardSQLTypeName.BOOL)); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); - - // Create a new view to be deleted - String query = - String.format( - "SELECT timestampField, stringField, booleanField FROM %s.%s", - BIGQUERY_DATASET_NAME, tableName); - CreateView.createView(BIGQUERY_DATASET_NAME, viewName, query); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, viewName); - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testGetView() { - GetView.getView(BIGQUERY_DATASET_NAME, viewName); - assertThat(bout.toString()).contains("View retrieved successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/GrantViewAccessIT.java b/samples/snippets/src/test/java/com/example/bigquery/GrantViewAccessIT.java deleted file mode 100644 index 11b1215ff..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/GrantViewAccessIT.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class GrantViewAccessIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String datasetName; - private String viewDatasetName; - private String tableName; - private String viewName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // create a temporary dataset, table and view to be deleted. - datasetName = "MY_DATASET_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - viewDatasetName = "MY_VIEW_DATASET_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - tableName = "MY_TABLE_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - viewName = "MY_VIEW_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - - CreateDataset.createDataset(datasetName); - CreateDataset.createDataset(viewDatasetName); - - Schema schema = - Schema.of( - Field.of("timestampField", StandardSQLTypeName.TIMESTAMP), - Field.of("stringField", StandardSQLTypeName.STRING), - Field.of("booleanField", StandardSQLTypeName.BOOL)); - CreateTable.createTable(viewDatasetName, tableName, schema); - - String query = - String.format( - "SELECT timestampField, stringField, booleanField FROM %s.%s", - viewDatasetName, tableName); - CreateView.createView(viewDatasetName, viewName, query); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(viewDatasetName, viewName); - DeleteTable.deleteTable(viewDatasetName, tableName); - DeleteDataset.deleteDataset(PROJECT_ID, datasetName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testGrantViewAccess() { - GrantViewAccess.grantViewAccess(datasetName, viewDatasetName, viewName); - assertThat(bout.toString()).contains("Grant view access successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/InsertingDataTypesIT.java b/samples/snippets/src/test/java/com/example/bigquery/InsertingDataTypesIT.java deleted file mode 100644 index 0ec786fa0..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/InsertingDataTypesIT.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class InsertingDataTypesIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - tableName = "MY_TABLE_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testInsertingDataTypes() { - InsertingDataTypes.insertingDataTypes(BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()).contains("Rows successfully inserted into table"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LabelDatasetIT.java b/samples/snippets/src/test/java/com/example/bigquery/LabelDatasetIT.java deleted file mode 100644 index 214996caa..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LabelDatasetIT.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class LabelDatasetIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String datasetName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // create a temporary dataset - datasetName = "MY_DATASET_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateDataset.createDataset(datasetName); - } - - @After - public void tearDown() { - // delete a temporary dataset - DeleteDataset.deleteDataset(PROJECT_ID, datasetName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testLabelDataset() { - LabelDataset.labelDataset(datasetName); - assertThat(bout.toString()).contains("Label added successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LabelTableIT.java b/samples/snippets/src/test/java/com/example/bigquery/LabelTableIT.java deleted file mode 100644 index bf6f9160d..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LabelTableIT.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertNotNull; - -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class LabelTableIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // create a temporary table - tableName = "MY_TABLE_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, Schema.of()); - } - - @After - public void tearDown() { - // delete a temporary table - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testLabelTable() { - LabelTable.labelTable(BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()).contains("Label added successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/ListDatasetsByLabelIT.java b/samples/snippets/src/test/java/com/example/bigquery/ListDatasetsByLabelIT.java deleted file mode 100644 index 8cf273b32..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/ListDatasetsByLabelIT.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class ListDatasetsByLabelIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String datasetName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // create a temporary dataset - datasetName = "MY_DATASET_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateDataset.createDataset(datasetName); - // add a label on dataset - LabelDataset.labelDataset(datasetName); - } - - @After - public void tearDown() { - // delete a temporary dataset - DeleteDataset.deleteDataset(PROJECT_ID, datasetName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testListDatasetsByLabel() { - String filter = "labels.color:green"; - ListDatasetsByLabel.listDatasetsByLabel(PROJECT_ID, filter); - assertThat(bout.toString()).contains("Success! Dataset ID"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/ListDatasetsIT.java b/samples/snippets/src/test/java/com/example/bigquery/ListDatasetsIT.java deleted file mode 100644 index 607e336bb..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/ListDatasetsIT.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class ListDatasetsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() throws Exception { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testListDatasets() { - // List datasets in bigquery-public-data project - ListDatasets.listDatasets("bigquery-public-data"); - assertThat(bout.toString()).contains("Success! Dataset ID"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/ListJobsIT.java b/samples/snippets/src/test/java/com/example/bigquery/ListJobsIT.java deleted file mode 100644 index 806dde7e9..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/ListJobsIT.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class ListJobsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Create a new job - String query = - "SELECT name" - + " FROM `bigquery-public-data.usa_names.usa_1910_2013`" - + " WHERE state = 'TX'" - + " LIMIT 100;"; - CreateJob.createJob(query); - } - - @After - public void tearDown() { - // Clean up - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testListJobs() { - ListJobs.listJobs(); - assertThat(bout.toString()).contains("Success! Job ID"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/ListModelsIT.java b/samples/snippets/src/test/java/com/example/bigquery/ListModelsIT.java deleted file mode 100644 index 4ddac63bc..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/ListModelsIT.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static junit.framework.TestCase.assertNotNull; - -import com.google.common.truth.Truth; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class ListModelsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String modelName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Create a new model to be deleted - modelName = "MY_MODEL_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - String sql = - "CREATE MODEL `" - + BIGQUERY_DATASET_NAME - + "." - + modelName - + "`" - + "OPTIONS ( " - + "model_type='linear_reg', " - + "max_iterations=1, " - + "learn_rate=0.4, " - + "learn_rate_strategy='constant' " - + ") AS ( " - + "SELECT 'a' AS f1, 2.0 AS label " - + "UNION ALL " - + "SELECT 'b' AS f1, 3.8 AS label " - + ")"; - CreateModel.createModel(sql); - } - - @After - public void tearDown() { - // Clean up - DeleteModel.deleteModel(BIGQUERY_DATASET_NAME, modelName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testListModels() { - ListModels.listModels(BIGQUERY_DATASET_NAME); - Truth.assertThat(bout.toString()).contains("Success! Model ID"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/ListRoutinesIT.java b/samples/snippets/src/test/java/com/example/bigquery/ListRoutinesIT.java deleted file mode 100644 index 3b0f0de38..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/ListRoutinesIT.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class ListRoutinesIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String routineName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Create a new routine to be deleted - routineName = "MY_ROUTINE_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateRoutine.createRoutine(BIGQUERY_DATASET_NAME, routineName); - } - - @After - public void tearDown() { - // Clean up - DeleteRoutine.deleteRoutine(BIGQUERY_DATASET_NAME, routineName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testListRoutines() { - ListRoutines.listRoutines(BIGQUERY_DATASET_NAME); - assertThat(bout.toString()).contains("Success! Routine ID"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/ListTablesIT.java b/samples/snippets/src/test/java/com/example/bigquery/ListTablesIT.java deleted file mode 100644 index 674f7e7ca..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/ListTablesIT.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class ListTablesIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() throws Exception { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testListTables() { - // List tables in bigquery-public-data:samples dataset - ListTables.listTables("bigquery-public-data", "samples"); - assertThat(bout.toString()).contains("Tables listed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LoadAvroFromGcsIT.java b/samples/snippets/src/test/java/com/example/bigquery/LoadAvroFromGcsIT.java deleted file mode 100644 index a8f44463b..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LoadAvroFromGcsIT.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class LoadAvroFromGcsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Create a test table - tableName = "MY_LOAD_AVRO_TABLE_FROM_GCS_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, Schema.of()); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void loadLoadAvroFromGcs() { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.avro"; - LoadAvroFromGcs.loadAvroFromGcs(BIGQUERY_DATASET_NAME, tableName, sourceUri); - assertThat(bout.toString()).contains("Avro from GCS successfully loaded in a table"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LoadAvroFromGcsTruncateIT.java b/samples/snippets/src/test/java/com/example/bigquery/LoadAvroFromGcsTruncateIT.java deleted file mode 100644 index e088fc066..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LoadAvroFromGcsTruncateIT.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class LoadAvroFromGcsTruncateIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Create a test table - tableName = "MY_LOAD_AVRO_TABLE_FROM_GCS_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, Schema.of()); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void loadLoadAvroFromGcsTruncate() { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.avro"; - LoadAvroFromGcsTruncate.loadAvroFromGcsTruncate(BIGQUERY_DATASET_NAME, tableName, sourceUri); - assertThat(bout.toString()) - .contains("Table is successfully overwritten by AVRO file loaded from GCS"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LoadCsvFromGcsAutodetectIT.java b/samples/snippets/src/test/java/com/example/bigquery/LoadCsvFromGcsAutodetectIT.java deleted file mode 100644 index 4a005c5a5..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LoadCsvFromGcsAutodetectIT.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class LoadCsvFromGcsAutodetectIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Create a test table - tableName = - "LOAD_CSV_TABLE_AUTODETECT_FROM_GCS_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, Schema.of()); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testLoadCsvFromGcsAutodetect() { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.csv"; - LoadCsvFromGcsAutodetect.loadCsvFromGcsAutodetect(BIGQUERY_DATASET_NAME, tableName, sourceUri); - assertThat(bout.toString()).contains("CSV Autodetect from GCS successfully loaded in a table"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LoadCsvFromGcsIT.java b/samples/snippets/src/test/java/com/example/bigquery/LoadCsvFromGcsIT.java deleted file mode 100644 index b44cf8b21..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LoadCsvFromGcsIT.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class LoadCsvFromGcsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - // Create a test table - tableName = "LOAD_CSV_TABLE_FROM_GCS_TEST_" + UUID.randomUUID().toString().substring(0, 8); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void loadCsvFromGcs() { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.csv"; - Schema schema = - Schema.of( - Field.of("name", StandardSQLTypeName.STRING), - Field.of("post_abbr", StandardSQLTypeName.STRING)); - LoadCsvFromGcs.loadCsvFromGcs(BIGQUERY_DATASET_NAME, tableName, sourceUri, schema); - assertThat(bout.toString()).contains("CSV from GCS successfully added during load append job"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LoadCsvFromGcsTruncateTest.java b/samples/snippets/src/test/java/com/example/bigquery/LoadCsvFromGcsTruncateTest.java deleted file mode 100644 index 620367649..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LoadCsvFromGcsTruncateTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.LegacySQLTypeName; -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class LoadCsvFromGcsTruncateTest { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Create a test table - tableName = "loadCsvFromGcsTruncate_TEST_" + UUID.randomUUID().toString().replace('-', '_'); - - Schema schema = - Schema.of( - Field.of("name", LegacySQLTypeName.STRING), - Field.of("post_abbr", LegacySQLTypeName.STRING)); - - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void loadCsvFromGcsTruncate() throws Exception { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.csv"; - LoadCsvFromGcsTruncate.loadCsvFromGcsTruncate(BIGQUERY_DATASET_NAME, tableName, sourceUri); - assertThat(bout.toString()) - .contains("Table is successfully overwritten by CSV file loaded from GCS"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LoadJsonFromGcsAutodetectIT.java b/samples/snippets/src/test/java/com/example/bigquery/LoadJsonFromGcsAutodetectIT.java deleted file mode 100644 index 1c8b85a3f..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LoadJsonFromGcsAutodetectIT.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class LoadJsonFromGcsAutodetectIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Create a test table - tableName = - "MY_LOAD_JSON_TABLE_AUTODETECT_FROM_GCS_TEST_" - + UUID.randomUUID().toString().substring(0, 8); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, Schema.of()); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void loadLoadJsonFromGcsAutodetect() { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.json"; - LoadJsonFromGcsAutodetect.loadJsonFromGcsAutodetect( - BIGQUERY_DATASET_NAME, tableName, sourceUri); - assertThat(bout.toString()).contains("Json Autodetect from GCS successfully loaded in a table"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LoadJsonFromGcsCmekIT.java b/samples/snippets/src/test/java/com/example/bigquery/LoadJsonFromGcsCmekIT.java deleted file mode 100644 index c4507f11d..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LoadJsonFromGcsCmekIT.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.EncryptionConfiguration; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class LoadJsonFromGcsCmekIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - private static final String BIGQUERY_KMS_KEY_NAME = requireEnvVar("BIGQUERY_KMS_KEY_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - requireEnvVar("BIGQUERY_KMS_KEY_NAME"); - } - - @Before - public void setUp() { - tableName = - "MY_LOAD_JSON_TABLE_CMEK_FROM_GCS_TEST_" + UUID.randomUUID().toString().substring(0, 8); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testLoadJsonFromGcsCmek() { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.json"; - EncryptionConfiguration configuration = - EncryptionConfiguration.newBuilder().setKmsKeyName(BIGQUERY_KMS_KEY_NAME).build(); - LoadJsonFromGcsCmek.loadJsonFromGcsCmek( - BIGQUERY_DATASET_NAME, tableName, sourceUri, configuration); - assertThat(bout.toString()) - .contains("Table loaded succesfully from GCS with configuration key"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LoadJsonFromGcsIT.java b/samples/snippets/src/test/java/com/example/bigquery/LoadJsonFromGcsIT.java deleted file mode 100644 index 4171028d4..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LoadJsonFromGcsIT.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class LoadJsonFromGcsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Create a test table - tableName = "MY_LOAD_JSON_TABLE_FROM_GCS_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, Schema.of()); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void loadLoadJsonFromGcs() { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.json"; - Schema schema = - Schema.of( - Field.of("name", StandardSQLTypeName.STRING), - Field.of("post_abbr", StandardSQLTypeName.STRING)); - LoadJsonFromGcs.loadJsonFromGcs(BIGQUERY_DATASET_NAME, tableName, sourceUri, schema); - assertThat(bout.toString()).contains("Json from GCS successfully loaded in a table"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LoadJsonFromGcsTruncateIT.java b/samples/snippets/src/test/java/com/example/bigquery/LoadJsonFromGcsTruncateIT.java deleted file mode 100644 index a5ffdea9e..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LoadJsonFromGcsTruncateIT.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class LoadJsonFromGcsTruncateIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - tableName = "MY_LOAD_JSON_TABLE_FROM_GCS_TEST_" + UUID.randomUUID().toString().substring(0, 8); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void loadLoadJsonFromGcsTruncate() { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.json"; - Schema schema = - Schema.of( - Field.of("name", StandardSQLTypeName.STRING), - Field.of("post_abbr", StandardSQLTypeName.STRING)); - LoadJsonFromGcsTruncate.loadJsonFromGcsTruncate( - BIGQUERY_DATASET_NAME, tableName, sourceUri, schema); - assertThat(bout.toString()) - .contains("Table is successfully overwritten by JSON file loaded from GCS"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LoadLocalFileIT.java b/samples/snippets/src/test/java/com/example/bigquery/LoadLocalFileIT.java deleted file mode 100644 index 31a20b70b..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LoadLocalFileIT.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.FormatOptions; -import com.google.cloud.bigquery.LegacySQLTypeName; -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.nio.file.FileSystems; -import java.nio.file.Path; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class LoadLocalFileIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - tableName = "LOADLOCALFILETESTTABLE_" + UUID.randomUUID().toString().substring(0, 8); - Schema schema = - Schema.of( - Field.of("Name", LegacySQLTypeName.STRING), - Field.of("Age", LegacySQLTypeName.NUMERIC), - Field.of("Weight", LegacySQLTypeName.NUMERIC), - Field.of("IsMagic", LegacySQLTypeName.BOOLEAN)); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void loadLocalFile() throws IOException, InterruptedException { - Path csvPath = FileSystems.getDefault().getPath("src/test/resources", "bigquery_noheader.csv"); - LoadLocalFile.loadLocalFile(BIGQUERY_DATASET_NAME, tableName, csvPath, FormatOptions.csv()); - assertThat(bout.toString()).contains("Successfully loaded"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LoadLocalFileInSessionIT.java b/samples/snippets/src/test/java/com/example/bigquery/LoadLocalFileInSessionIT.java deleted file mode 100644 index 1bf612878..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LoadLocalFileInSessionIT.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertFalse; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.FormatOptions; -import com.google.cloud.bigquery.LegacySQLTypeName; -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.nio.file.FileSystems; -import java.nio.file.Path; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class LoadLocalFileInSessionIT { - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - tableName = "LOADLOCALFILETESTTABLE_" + UUID.randomUUID().toString().substring(0, 8); - Schema schema = - Schema.of( - Field.of("Name", LegacySQLTypeName.STRING), - Field.of("Age", LegacySQLTypeName.NUMERIC), - Field.of("Weight", LegacySQLTypeName.NUMERIC), - Field.of("IsMagic", LegacySQLTypeName.BOOLEAN)); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void loadLocalFileInSession() throws IOException, InterruptedException { - Path csvPath = FileSystems.getDefault().getPath("src/test/resources", "bigquery_noheader.csv"); - String sessionId = - LoadLocalFileInSession.createSessionForLoading( - BIGQUERY_DATASET_NAME, tableName, csvPath, FormatOptions.csv()); - assertFalse(sessionId.isEmpty()); - LoadLocalFileInSession.loadLocalFileInSession( - BIGQUERY_DATASET_NAME, tableName, csvPath, FormatOptions.csv(), sessionId); - assertThat(bout.toString()).contains("Successfully loaded to Session"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LoadOrcFromGcsIT.java b/samples/snippets/src/test/java/com/example/bigquery/LoadOrcFromGcsIT.java deleted file mode 100644 index 01a68a590..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LoadOrcFromGcsIT.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class LoadOrcFromGcsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - // Create a test table - tableName = "LOAD_ORC_TABLE_FROM_GCS_TEST_" + UUID.randomUUID().toString().substring(0, 8); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testLoadOrcFromGcs() { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.orc"; - Schema schema = - Schema.of( - Field.of("name", StandardSQLTypeName.STRING), - Field.of("post_abbr", StandardSQLTypeName.STRING)); - LoadOrcFromGcs.loadOrcFromGcs(BIGQUERY_DATASET_NAME, tableName, sourceUri, schema); - assertThat(bout.toString()).contains("ORC from GCS successfully added during load append job"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LoadOrcFromGcsTruncateIT.java b/samples/snippets/src/test/java/com/example/bigquery/LoadOrcFromGcsTruncateIT.java deleted file mode 100644 index cc5862801..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LoadOrcFromGcsTruncateIT.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class LoadOrcFromGcsTruncateIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Create a test table - tableName = "MY_LOAD_ORC_TABLE_FROM_GCS_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, Schema.of()); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testLoadOrcFromGcsTruncate() { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.orc"; - LoadOrcFromGcsTruncate.loadOrcFromGcsTruncate(BIGQUERY_DATASET_NAME, tableName, sourceUri); - assertThat(bout.toString()) - .contains("Table is successfully overwritten by ORC file loaded from GCS"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LoadParquetIT.java b/samples/snippets/src/test/java/com/example/bigquery/LoadParquetIT.java deleted file mode 100644 index e50c32b8a..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LoadParquetIT.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class LoadParquetIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void loadParquet() { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.parquet"; - String tableName = "us_states"; - LoadParquet.loadParquet(BIGQUERY_DATASET_NAME, tableName, sourceUri); - assertThat(bout.toString()).contains("GCS parquet loaded successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LoadParquetReplaceTableIT.java b/samples/snippets/src/test/java/com/example/bigquery/LoadParquetReplaceTableIT.java deleted file mode 100644 index 7846f7677..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LoadParquetReplaceTableIT.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class LoadParquetReplaceTableIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testLoadParquetReplaceTable() { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.parquet"; - String tableName = "us_states"; - LoadParquetReplaceTable.loadParquetReplaceTable(BIGQUERY_DATASET_NAME, tableName, sourceUri); - assertThat(bout.toString()).contains("GCS parquet overwrote existing table successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LoadPartitionedTableIT.java b/samples/snippets/src/test/java/com/example/bigquery/LoadPartitionedTableIT.java deleted file mode 100644 index 3f9d9f5ff..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LoadPartitionedTableIT.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class LoadPartitionedTableIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - tableName = "LOAD_PARTITIONED_TABLE_TEST_" + UUID.randomUUID().toString().substring(0, 8); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void loadPartitionedTable() throws Exception { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states-by-date-no-header.csv"; - LoadPartitionedTable.loadPartitionedTable(BIGQUERY_DATASET_NAME, tableName, sourceUri); - assertThat(bout.toString()) - .contains("Data successfully loaded into time partitioned table during load job"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/LoadTableClusteredIT.java b/samples/snippets/src/test/java/com/example/bigquery/LoadTableClusteredIT.java deleted file mode 100644 index e7f9df5d9..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/LoadTableClusteredIT.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import com.google.common.collect.ImmutableList; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class LoadTableClusteredIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - tableName = "LOAD_CLUSTERED_TABLE_TEST_" + UUID.randomUUID().toString().substring(0, 8); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testLoadTableClustered() { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states-by-date-no-header.csv"; - Schema schema = - Schema.of( - Field.of("name", StandardSQLTypeName.STRING), - Field.of("post_abbr", StandardSQLTypeName.STRING), - Field.of("date", StandardSQLTypeName.DATE)); - - LoadTableClustered.loadTableClustered( - BIGQUERY_DATASET_NAME, tableName, sourceUri, schema, ImmutableList.of("name", "post_abbr")); - assertThat(bout.toString()) - .contains("Data successfully loaded into clustered table during load job"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/NestedRepeatedSchemaIT.java b/samples/snippets/src/test/java/com/example/bigquery/NestedRepeatedSchemaIT.java deleted file mode 100644 index afa23ac7d..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/NestedRepeatedSchemaIT.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class NestedRepeatedSchemaIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - tableName = "NESTED_REPEATED_" + UUID.randomUUID().toString().replace("-", "_"); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void createTableWithNestedRepeatedSchema() { - NestedRepeatedSchema.createTableWithNestedRepeatedSchema(BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()) - .contains("Table with nested and repeated schema created successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryBatchIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryBatchIT.java deleted file mode 100644 index b379583c9..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryBatchIT.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class QueryBatchIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryBatch() { - String query = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus"; - - QueryBatch.queryBatch(query); - assertThat(bout.toString()).contains("Query batch performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryClusteredTableIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryClusteredTableIT.java deleted file mode 100644 index abdaed05f..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryClusteredTableIT.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class QueryClusteredTableIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void queryClusteredTable() { - String projectId = "java-docs-samples-testing"; - String datasetName = "bigquery_test_dataset"; - String tableName = "clustered_shakespeare"; - - QueryClusteredTable.queryClusteredTable(projectId, datasetName, tableName); - assertThat(bout.toString()).contains("Query clustered table performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryDestinationTableCmekIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryDestinationTableCmekIT.java deleted file mode 100644 index e4f21760d..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryDestinationTableCmekIT.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.EncryptionConfiguration; -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class QueryDestinationTableCmekIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private EncryptionConfiguration encryption; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - private static final String BIGQUERY_KMS_KEY_NAME = requireEnvVar("BIGQUERY_KMS_KEY_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - requireEnvVar("BIGQUERY_KMS_KEY_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // create a test table with encryption key - tableName = "MY_TABLE_CMEK_TEST" + UUID.randomUUID().toString().substring(0, 8); - Schema schema = - Schema.of( - Field.of("stringField", StandardSQLTypeName.STRING), - Field.of("booleanField", StandardSQLTypeName.BOOL)); - encryption = EncryptionConfiguration.newBuilder().setKmsKeyName(BIGQUERY_KMS_KEY_NAME).build(); - CreateTableCmek.createTableCmek(BIGQUERY_DATASET_NAME, tableName, schema, encryption); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryDestinationTableCmek() { - String query = - String.format( - "SELECT stringField, booleanField FROM %s.%s", BIGQUERY_DATASET_NAME, tableName); - QueryDestinationTableCmek.queryDestinationTableCmek(query, encryption); - assertThat(bout.toString()).contains("Query performed successfully with encryption key."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryDisableCacheIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryDisableCacheIT.java deleted file mode 100644 index 93ac76a62..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryDisableCacheIT.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class QueryDisableCacheIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryDisableCache() { - String query = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;"; - QueryDisableCache.queryDisableCache(query); - assertThat(bout.toString()).contains("Query disable cache performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryDryRunIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryDryRunIT.java deleted file mode 100644 index f19641be5..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryDryRunIT.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class QueryDryRunIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryDryRun() { - String query = - "SELECT name, COUNT(*) as name_count " - + "FROM `bigquery-public-data.usa_names.usa_1910_2013` " - + "WHERE state = 'WA' " - + "GROUP BY name"; - - QueryDryRun.queryDryRun(query); - assertThat(bout.toString()).contains("Query dry run performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryExternalBigtablePermIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryExternalBigtablePermIT.java deleted file mode 100644 index 7f14a2871..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryExternalBigtablePermIT.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient; -import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest; -import com.google.cloud.bigtable.data.v2.BigtableDataClient; -import com.google.cloud.bigtable.data.v2.models.BulkMutation; -import com.google.cloud.bigtable.data.v2.models.Mutation; -import com.google.protobuf.ByteString; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class QueryExternalBigtablePermIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String TABLE_ID = "bigquery-samples-test" + ID; - private static final String COLUMN_FAMILY_NAME = "stats_summary"; - private static final long TIMESTAMP = System.currentTimeMillis() * 1000; - private static final String CONNECTED_CELL = "connected_cell"; - private static final String CONNECTED_WIFI = "connected_wifi"; - private static final String OS_BUILD = "os_build"; - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String INSTANCE = requireEnvVar("BIGTABLE_TESTING_INSTANCE"); - private static final String PROJECT = requireEnvVar("SAMPLES_TESTING_PROJECT"); - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - requireEnvVar("BIGTABLE_TESTING_INSTANCE"); - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() throws IOException { - // Create a test table - tableName = "EXTERNAL_TABLE_FROM_BIGTABLE_TEST_" + ID; - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // create a temporary bigtable table. - try (BigtableTableAdminClient client = BigtableTableAdminClient.create(PROJECT, INSTANCE)) { - CreateTableRequest createTableRequest = - CreateTableRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY_NAME); - client.createTable(createTableRequest); - } - // inserting temporary rows. - try (BigtableDataClient client = BigtableDataClient.create(PROJECT, INSTANCE)) { - BulkMutation bulkMutation = - BulkMutation.create(TABLE_ID) - .add( - "phone#4c410523#20190501", - Mutation.create() - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_CELL.getBytes()), - TIMESTAMP, - 1) - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_WIFI.getBytes()), - TIMESTAMP, - 1) - .setCell(COLUMN_FAMILY_NAME, OS_BUILD, TIMESTAMP, "PQ2A.190405.003")) - .add( - "phone#4c410523#20190502", - Mutation.create() - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_CELL.getBytes()), - TIMESTAMP, - 1) - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_WIFI.getBytes()), - TIMESTAMP, - 1) - .setCell(COLUMN_FAMILY_NAME, OS_BUILD, TIMESTAMP, "PQ2A.190405.004")) - .add( - "phone#4c410523#20190505", - Mutation.create() - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_CELL.getBytes()), - TIMESTAMP, - 0) - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_WIFI.getBytes()), - TIMESTAMP, - 1) - .setCell(COLUMN_FAMILY_NAME, OS_BUILD, TIMESTAMP, "PQ2A.190406.000")) - .add( - "phone#5c10102#20190501", - Mutation.create() - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_CELL.getBytes()), - TIMESTAMP, - 1) - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_WIFI.getBytes()), - TIMESTAMP, - 1) - .setCell(COLUMN_FAMILY_NAME, OS_BUILD, TIMESTAMP, "PQ2A.190401.002")) - .add( - "phone#5c10102#20190502", - Mutation.create() - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_CELL.getBytes()), - TIMESTAMP, - 1) - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_WIFI.getBytes()), - TIMESTAMP, - 0) - .setCell(COLUMN_FAMILY_NAME, OS_BUILD, TIMESTAMP, "PQ2A.190406.000")); - - client.bulkMutateRows(bulkMutation); - } - } - - @After - public void tearDown() throws IOException { - // Clean up - try (BigtableTableAdminClient client = BigtableTableAdminClient.create(PROJECT, INSTANCE)) { - client.deleteTable(TABLE_ID); - } - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testQueryExternalBigtablePerm() { - String query = String.format("SELECT * FROM %s.%s ", BIGQUERY_DATASET_NAME, tableName); - String sourceUri = - String.format( - "https://googleapis.com/bigtable/projects/%s/instances/%s/tables/%s", - PROJECT, INSTANCE, TABLE_ID); - QueryExternalBigtablePerm.queryExternalBigtablePerm( - BIGQUERY_DATASET_NAME, tableName, sourceUri, query); - assertThat(bout.toString()) - .contains("Query on external permanent table performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryExternalBigtableTempIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryExternalBigtableTempIT.java deleted file mode 100644 index dce81d637..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryExternalBigtableTempIT.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient; -import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest; -import com.google.cloud.bigtable.data.v2.BigtableDataClient; -import com.google.cloud.bigtable.data.v2.models.BulkMutation; -import com.google.cloud.bigtable.data.v2.models.Mutation; -import com.google.protobuf.ByteString; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class QueryExternalBigtableTempIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String TABLE_ID = "bigquery-samples-test" + ID; - private static final String COLUMN_FAMILY_NAME = "stats_summary"; - private static final long TIMESTAMP = System.currentTimeMillis() * 1000; - private static final String CONNECTED_CELL = "connected_cell"; - private static final String CONNECTED_WIFI = "connected_wifi"; - private static final String OS_BUILD = "os_build"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String INSTANCE = requireEnvVar("BIGTABLE_TESTING_INSTANCE"); - private static final String PROJECT = requireEnvVar("SAMPLES_TESTING_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - requireEnvVar("BIGTABLE_TESTING_INSTANCE"); - } - - @Before - public void setUp() throws IOException { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // create a temporary bigtable table. - try (BigtableTableAdminClient client = BigtableTableAdminClient.create(PROJECT, INSTANCE)) { - CreateTableRequest createTableRequest = - CreateTableRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY_NAME); - client.createTable(createTableRequest); - } - // inserting temporary rows. - try (BigtableDataClient client = BigtableDataClient.create(PROJECT, INSTANCE)) { - BulkMutation bulkMutation = - BulkMutation.create(TABLE_ID) - .add( - "phone#4c410523#20190501", - Mutation.create() - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_CELL.getBytes()), - TIMESTAMP, - 1) - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_WIFI.getBytes()), - TIMESTAMP, - 1) - .setCell(COLUMN_FAMILY_NAME, OS_BUILD, TIMESTAMP, "PQ2A.190405.003")) - .add( - "phone#4c410523#20190502", - Mutation.create() - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_CELL.getBytes()), - TIMESTAMP, - 1) - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_WIFI.getBytes()), - TIMESTAMP, - 1) - .setCell(COLUMN_FAMILY_NAME, OS_BUILD, TIMESTAMP, "PQ2A.190405.004")) - .add( - "phone#4c410523#20190505", - Mutation.create() - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_CELL.getBytes()), - TIMESTAMP, - 0) - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_WIFI.getBytes()), - TIMESTAMP, - 1) - .setCell(COLUMN_FAMILY_NAME, OS_BUILD, TIMESTAMP, "PQ2A.190406.000")) - .add( - "phone#5c10102#20190501", - Mutation.create() - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_CELL.getBytes()), - TIMESTAMP, - 1) - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_WIFI.getBytes()), - TIMESTAMP, - 1) - .setCell(COLUMN_FAMILY_NAME, OS_BUILD, TIMESTAMP, "PQ2A.190401.002")) - .add( - "phone#5c10102#20190502", - Mutation.create() - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_CELL.getBytes()), - TIMESTAMP, - 1) - .setCell( - COLUMN_FAMILY_NAME, - ByteString.copyFrom(CONNECTED_WIFI.getBytes()), - TIMESTAMP, - 0) - .setCell(COLUMN_FAMILY_NAME, OS_BUILD, TIMESTAMP, "PQ2A.190406.000")); - - client.bulkMutateRows(bulkMutation); - } - } - - @After - public void tearDown() throws IOException { - // Clean up - try (BigtableTableAdminClient client = BigtableTableAdminClient.create(PROJECT, INSTANCE)) { - client.deleteTable(TABLE_ID); - } - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testQueryExternalBigtableTemp() { - String tableName = "EXTERNAL_TEMP_TABLE_FROM_BIGTABLE_TEST_" + ID; - String query = String.format("SELECT * FROM %s ", tableName); - String sourceUri = - String.format( - "https://googleapis.com/bigtable/projects/%s/instances/%s/tables/%s", - PROJECT, INSTANCE, TABLE_ID); - QueryExternalBigtableTemp.queryExternalBigtableTemp(tableName, sourceUri, query); - assertThat(bout.toString()) - .contains("Query on external temporary table performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryExternalGcsPermIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryExternalGcsPermIT.java deleted file mode 100644 index ed4e8d40b..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryExternalGcsPermIT.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class QueryExternalGcsPermIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - // Create a test table - tableName = "EXTERNAL_CSV_TABLE_FROM_GCS_TEST_" + UUID.randomUUID().toString().substring(0, 8); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryExternalGcsPerm() { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.csv"; - Schema schema = - Schema.of( - Field.of("name", StandardSQLTypeName.STRING), - Field.of("post_abbr", StandardSQLTypeName.STRING)); - String query = - String.format( - "SELECT * FROM %s.%s WHERE name LIKE 'W%%'", BIGQUERY_DATASET_NAME, tableName); - QueryExternalGcsPerm.queryExternalGcsPerm( - BIGQUERY_DATASET_NAME, tableName, sourceUri, schema, query); - assertThat(bout.toString()) - .contains("Query on external permanent table performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryExternalGcsTempIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryExternalGcsTempIT.java deleted file mode 100644 index a64117810..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryExternalGcsTempIT.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class QueryExternalGcsTempIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryExternalGcsTemp() { - String tableName = - "EXTERNAL_CSV_TEMP_TABLE_FROM_GCS_TEST_" + UUID.randomUUID().toString().substring(0, 8); - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.csv"; - Schema schema = - Schema.of( - Field.of("name", StandardSQLTypeName.STRING), - Field.of("post_abbr", StandardSQLTypeName.STRING)); - String query = String.format("SELECT * FROM %s WHERE name LIKE 'W%%'", tableName); - QueryExternalGcsTemp.queryExternalGcsTemp(tableName, sourceUri, schema, query); - assertThat(bout.toString()) - .contains("Query on external temporary table performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryExternalSheetsPermIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryExternalSheetsPermIT.java index fc16a4f8e..15c8a3eca 100644 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryExternalSheetsPermIT.java +++ b/samples/snippets/src/test/java/com/example/bigquery/QueryExternalSheetsPermIT.java @@ -33,7 +33,9 @@ import org.junit.Ignore; import org.junit.Test; -@Ignore +import com.google.cloud.bigquery.BigQueryException; +import java.io.IOException; + public class QueryExternalSheetsPermIT { private final Logger log = Logger.getLogger(this.getClass().getName()); @@ -43,6 +45,7 @@ public class QueryExternalSheetsPermIT { private PrintStream originalPrintStream; private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); + private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); private static String requireEnvVar(String varName) { String value = System.getenv(varName); @@ -79,7 +82,7 @@ public void tearDown() { } @Test - public void testQueryExternalSheetsPerm() { + public void testQueryExternalSheetsPerm() throws BigQueryException, InterruptedException, IOException { String sourceUri = "https://docs.google.com/spreadsheets/d/1i_QCL-7HcSyUZmIbP9E6lO_T5u3HnpLe7dnpHaijg_E/edit?usp=sharing"; Schema schema = diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryExternalSheetsTempIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryExternalSheetsTempIT.java deleted file mode 100644 index 2098cce6e..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryExternalSheetsTempIT.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class QueryExternalSheetsTempIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryExternalSheetsTemp() { - String tableName = - "EXTERNAL_SHEET_TEMP_TABLE_FROM_GCS_TEST_" + UUID.randomUUID().toString().substring(0, 8); - String sourceUri = - "https://docs.google.com/spreadsheets/d/1i_QCL-7HcSyUZmIbP9E6lO_T5u3HnpLe7dnpHaijg_E/edit?usp=sharing"; - Schema schema = - Schema.of( - Field.of("name", StandardSQLTypeName.STRING), - Field.of("post_abbr", StandardSQLTypeName.STRING)); - String query = String.format("SELECT * FROM %s WHERE name LIKE 'W%%'", tableName); - QueryExternalSheetsTemp.queryExternalSheetsTemp(tableName, sourceUri, schema, query); - assertThat(bout.toString()) - .contains("Query on external temporary table performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryExternalTableAwsIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryExternalTableAwsIT.java deleted file mode 100644 index 504a72f45..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryExternalTableAwsIT.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class QueryExternalTableAwsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String OMNI_PROJECT_ID = requireEnvVar("OMNI_PROJECT_ID"); - private static final String OMNI_DATASET_NAME = requireEnvVar("OMNI_DATASET_NAME"); - private static final String OMNI_EXTERNAL_TABLE_NAME = requireEnvVar("OMNI_EXTERNAL_TABLE_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("OMNI_PROJECT_ID"); - requireEnvVar("OMNI_DATASET_NAME"); - requireEnvVar("OMNI_EXTERNAL_TABLE_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testQueryExternalTableAws() throws InterruptedException { - String query = - String.format( - "SELECT * FROM %s.%s.%s WHERE name LIKE 'W%%'", - OMNI_PROJECT_ID, OMNI_DATASET_NAME, OMNI_EXTERNAL_TABLE_NAME); - QueryExternalTableAws.queryExternalTableAws(query); - assertThat(bout.toString()) - .contains("Query on aws external permanent table performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryLargeResultsIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryLargeResultsIT.java deleted file mode 100644 index 11efa613b..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryLargeResultsIT.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class QueryLargeResultsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - tableName = "QUERY_LARGE_RESULT_TABLE_TEST" + UUID.randomUUID().toString().substring(0, 8); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryLargeResults() { - String query = "SELECT corpus FROM [bigquery-public-data:samples.shakespeare] GROUP BY corpus;"; - QueryLargeResults.queryLargeResults(BIGQUERY_DATASET_NAME, tableName, query); - assertThat(bout.toString()).contains("Query large results performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryMaterializedViewIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryMaterializedViewIT.java deleted file mode 100644 index 7e84daf28..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryMaterializedViewIT.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class QueryMaterializedViewIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private String materializedViewName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - tableName = "MY_TABLE_NAME_TEST_" + ID; - materializedViewName = "MY_QUERY_MATERIALIZED_VIEW_NAME_TEST_" + ID; - - Schema schema = - Schema.of( - Field.of("timestampField", StandardSQLTypeName.TIMESTAMP), - Field.of("stringField", StandardSQLTypeName.STRING), - Field.of("booleanField", StandardSQLTypeName.BOOL)); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); - String query = - String.format( - "SELECT MAX(TimestampField) AS TimestampField, StringField, " - + "MAX(BooleanField) AS BooleanField " - + "FROM %s.%s GROUP BY StringField", - BIGQUERY_DATASET_NAME, tableName); - CreateMaterializedView.createMaterializedView( - BIGQUERY_DATASET_NAME, materializedViewName, query); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, materializedViewName); - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testQueryMaterializedView() throws InterruptedException { - String query = - String.format("SELECT * FROM %s.%s", BIGQUERY_DATASET_NAME, materializedViewName); - QueryMaterializedView.queryMaterializedView(query); - assertThat(bout.toString()).contains("Query performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryPaginationIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryPaginationIT.java deleted file mode 100644 index 415bed7b6..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryPaginationIT.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class QueryPaginationIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - tableName = - "QUERY_PAGINATION_TABLE_FROM_GCS_TEST_" + UUID.randomUUID().toString().substring(0, 8); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryPagination() { - String query = - "SELECT name, SUM(number) as total_people" - + " FROM `bigquery-public-data.usa_names.usa_1910_2013`" - + " GROUP BY name" - + " ORDER BY total_people DESC" - + " LIMIT 100"; - QueryPagination.queryPagination(BIGQUERY_DATASET_NAME, tableName, query); - assertThat(bout.toString()).contains("Query pagination performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryPartitionedTableIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryPartitionedTableIT.java deleted file mode 100644 index 777c9482b..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryPartitionedTableIT.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class QueryPartitionedTableIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() throws Exception { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Create a test table - tableName = "LOAD_PARTITIONED_TABLE_TEST_" + UUID.randomUUID().toString().substring(0, 8); - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states-by-date-no-header.csv"; - LoadPartitionedTable.loadPartitionedTable(BIGQUERY_DATASET_NAME, tableName, sourceUri); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryPartitionedTable() { - String query = - String.format( - "SELECT * FROM `%s.%s` WHERE date BETWEEN @start_date AND @end_date", - BIGQUERY_DATASET_NAME, tableName); - QueryPartitionedTable.queryPartitionedTable(query); - assertThat(bout.toString()).contains("Query partitioned table performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryScriptIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryScriptIT.java deleted file mode 100644 index ee172f786..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryScriptIT.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class QueryScriptIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryScript() { - String script = - "-- Declare a variable to hold names as an array.\n" - + "DECLARE top_names ARRAY;\n" - + "-- Build an array of the top 100 names from the year 2017.\n" - + "SET top_names = (\n" - + " SELECT ARRAY_AGG(name ORDER BY number DESC LIMIT 100)\n" - + " FROM `bigquery-public-data`.usa_names.usa_1910_current\n" - + " WHERE year = 2017\n" - + ");\n" - + "-- Which names appear as words in Shakespeare's plays?\n" - + "SELECT\n" - + " name AS shakespeare_name\n" - + "FROM UNNEST(top_names) AS name\n" - + "WHERE name IN (\n" - + " SELECT word\n" - + " FROM `bigquery-public-data`.samples.shakespeare\n" - + ");"; - - QueryScript.queryScript(script); - assertThat(bout.toString()).contains("Query script performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryShortModeIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryShortModeIT.java deleted file mode 100644 index 6500de782..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryShortModeIT.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class QueryShortModeIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryBatch() { - String query = - "SELECT name, gender, SUM(number) AS total FROM " - + "bigquery-public-data.usa_names.usa_1910_2013 GROUP BY " - + "name, gender ORDER BY total DESC LIMIT 10"; - - QueryShortMode.queryShortMode(query); - assertThat(bout.toString()).contains("Query was run"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryTotalRowsIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryTotalRowsIT.java deleted file mode 100644 index 8e48bc110..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryTotalRowsIT.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class QueryTotalRowsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryTotalRows() { - String query = - "SELECT name FROM `bigquery-public-data.usa_names.usa_1910_2013`" - + " WHERE state = \"TX\"" - + " LIMIT 100"; - QueryTotalRows.queryTotalRows(query); - assertThat(bout.toString()).contains("Query total rows performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryWithArrayOfStructsNamedParametersIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryWithArrayOfStructsNamedParametersIT.java deleted file mode 100644 index f0b524dda..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryWithArrayOfStructsNamedParametersIT.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class QueryWithArrayOfStructsNamedParametersIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryWithNamedParameters() { - QueryWithArrayOfStructsNamedParameters.queryWithArrayOfStructsNamedParameters(); - assertThat(bout.toString()) - .contains("Query with Array of struct parameters performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryWithArrayParametersIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryWithArrayParametersIT.java deleted file mode 100644 index c52d6167d..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryWithArrayParametersIT.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class QueryWithArrayParametersIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryWithArrayParameters() { - String gender = "M"; - String[] states = {"WA", "WI", "WV", "WY"}; - String query = - "SELECT name, sum(number) as count\n" - + "FROM `bigquery-public-data.usa_names.usa_1910_2013`\n" - + "WHERE gender = @gender\n" - + "AND state IN UNNEST(@states)\n" - + "GROUP BY name\n" - + "ORDER BY count DESC\n" - + "LIMIT 10;"; - QueryWithArrayParameters.queryWithArrayParameters(query, gender, states); - assertThat(bout.toString()).contains("Query with arrays parameters performed successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryWithNamedParametersIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryWithNamedParametersIT.java deleted file mode 100644 index be57b9d32..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryWithNamedParametersIT.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class QueryWithNamedParametersIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryWithNamedParameters() { - QueryWithNamedParameters.queryWithNamedParameters(); - assertThat(bout.toString()).contains("Query with named parameters performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryWithNamedTypesParametersIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryWithNamedTypesParametersIT.java deleted file mode 100644 index 359379e36..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryWithNamedTypesParametersIT.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class QueryWithNamedTypesParametersIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryWithNamedTypesParameters() { - String[] words = {"and", "is", "the", "moon"}; - String corpus = "romeoandjuliet"; - Integer wordsCount = 250; - String query = - "SELECT word, word_count" - + " FROM `bigquery-public-data.samples.shakespeare`" - + " WHERE word IN UNNEST(@wordList)" - + " AND corpus = @corpus" - + " AND word_count >= @minWordCount" - + " ORDER BY word_count DESC"; - QueryWithNamedTypesParameters.queryWithNamedTypesParameters(query, words, corpus, wordsCount); - assertThat(bout.toString()) - .contains("Query with named types parameters performed successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryWithPositionalParametersIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryWithPositionalParametersIT.java deleted file mode 100644 index 38afddffa..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryWithPositionalParametersIT.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class QueryWithPositionalParametersIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryWithPositionalParameters() { - QueryWithPositionalParameters.queryWithPositionalParameters(); - assertThat(bout.toString()) - .contains("Query with positional parameters performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryWithPositionalTypesParametersIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryWithPositionalTypesParametersIT.java deleted file mode 100644 index 1abe37299..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryWithPositionalTypesParametersIT.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class QueryWithPositionalTypesParametersIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryWithPositionalTypesParameters() { - String[] words = {"and", "is", "the", "moon"}; - String corpus = "romeoandjuliet"; - Integer wordsCount = 250; - String query = - "SELECT word, word_count" - + " FROM `bigquery-public-data.samples.shakespeare`" - + " WHERE word IN UNNEST(?)" - + " AND corpus = ?" - + " AND word_count >= ?" - + " ORDER BY word_count DESC"; - QueryWithPositionalTypesParameters.queryWithPositionalTypesParameters( - query, words, corpus, wordsCount); - assertThat(bout.toString()) - .contains("Query with positional types parameters performed successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryWithStructsParametersIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryWithStructsParametersIT.java deleted file mode 100644 index 3a67da6da..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryWithStructsParametersIT.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class QueryWithStructsParametersIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryWithNamedParameters() { - QueryWithStructsParameters.queryWithStructsParameters(); - assertThat(bout.toString()).contains("Query with struct parameter performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryWithTimestampParametersIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryWithTimestampParametersIT.java deleted file mode 100644 index eb6f79cb7..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryWithTimestampParametersIT.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class QueryWithTimestampParametersIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQueryWithTimestampParameters() { - QueryWithTimestampParameters.queryWithTimestampParameters(); - assertThat(bout.toString()).contains("Query with timestamp parameter performed successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/QuickstartSampleIT.java b/samples/snippets/src/test/java/com/example/bigquery/QuickstartSampleIT.java deleted file mode 100644 index f819db552..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/QuickstartSampleIT.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import com.google.cloud.bigquery.BigQuery; -import com.google.cloud.bigquery.BigQuery.DatasetDeleteOption; -import com.google.cloud.bigquery.BigQueryOptions; -import com.google.cloud.bigquery.DatasetId; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Tests for quickstart sample. */ -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class QuickstartSampleIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final void deleteMyNewDataset() { - BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService(); - String datasetName = "my_new_dataset"; - DatasetId datasetId = DatasetId.of(datasetName); - DatasetDeleteOption deleteContents = DatasetDeleteOption.deleteContents(); - bigquery.delete(datasetId, deleteContents); - } - - @Before - public void setUp() { - deleteMyNewDataset(); - - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - deleteMyNewDataset(); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQuickstart() throws Exception { - QuickstartSample.main(); - String got = bout.toString(); - assertThat(got).contains("Dataset my_new_dataset created."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/RelaxColumnLoadAppendIT.java b/samples/snippets/src/test/java/com/example/bigquery/RelaxColumnLoadAppendIT.java deleted file mode 100644 index 96ad8fc45..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/RelaxColumnLoadAppendIT.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class RelaxColumnLoadAppendIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Create a test table - tableName = "RELAX_COLUMN_LOAD_APPEND_TEST_" + UUID.randomUUID().toString().substring(0, 8); - Field id = - Field.newBuilder("id", StandardSQLTypeName.INT64).setMode(Field.Mode.REQUIRED).build(); - Field name = - Field.newBuilder("name", StandardSQLTypeName.STRING).setMode(Field.Mode.REQUIRED).build(); - Field postAbbr = - Field.newBuilder("post_abbr", StandardSQLTypeName.STRING) - .setMode(Field.Mode.REQUIRED) - .build(); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, Schema.of(id, name, postAbbr)); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testRelaxColumnLoadAppend() { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.csv"; - RelaxColumnLoadAppend.relaxColumnLoadAppend(BIGQUERY_DATASET_NAME, tableName, sourceUri); - assertThat(bout.toString()).contains("Relax column append successfully loaded in a table"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/RelaxColumnModeIT.java b/samples/snippets/src/test/java/com/example/bigquery/RelaxColumnModeIT.java deleted file mode 100644 index 8e7860947..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/RelaxColumnModeIT.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Field.Mode; -import com.google.cloud.bigquery.LegacySQLTypeName; -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class RelaxColumnModeIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() throws Exception { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // Create a new table with REQUIRED columns for each test to relax its column mode since this is - // a one-way operation - tableName = "GCLOUD_TEST_TABLE_TEMP_" + UUID.randomUUID().toString().substring(0, 8); - Schema originalSchema = - Schema.of( - Field.newBuilder("word", LegacySQLTypeName.STRING).setMode(Mode.REQUIRED).build(), - Field.newBuilder("word_count", LegacySQLTypeName.STRING) - .setMode(Field.Mode.REQUIRED) - .build(), - Field.newBuilder("corpus", LegacySQLTypeName.STRING) - .setMode(Field.Mode.REQUIRED) - .build(), - Field.newBuilder("corpus_date", LegacySQLTypeName.STRING) - .setMode(Field.Mode.REQUIRED) - .build()); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, originalSchema); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testRelaxColumnMode() { - // Relax table column mode - RelaxColumnMode.relaxColumnMode(BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()).contains("Table schema successfully relaxed."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/RelaxTableQueryIT.java b/samples/snippets/src/test/java/com/example/bigquery/RelaxTableQueryIT.java deleted file mode 100644 index ac123a74f..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/RelaxTableQueryIT.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.LegacySQLTypeName; -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class RelaxTableQueryIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_PROJECT_ID = System.getenv("BIGQUERY_PROJECT_ID"); - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_PROJECT_ID"); - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() throws Exception { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - tableName = "RELAX_TABLE_QUERY_TEST" + UUID.randomUUID().toString().substring(0, 8); - Schema originalSchema = - Schema.of( - Field.newBuilder("word", LegacySQLTypeName.STRING).setMode(Field.Mode.REQUIRED).build(), - Field.newBuilder("word_count", LegacySQLTypeName.STRING) - .setMode(Field.Mode.REQUIRED) - .build(), - Field.newBuilder("corpus", LegacySQLTypeName.STRING) - .setMode(Field.Mode.REQUIRED) - .build(), - Field.newBuilder("corpus_date", LegacySQLTypeName.STRING) - .setMode(Field.Mode.REQUIRED) - .build()); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, originalSchema); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testRelaxTableQuery() throws Exception { - RelaxTableQuery.relaxTableQuery(BIGQUERY_PROJECT_ID, BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()) - .contains("Successfully relaxed all columns in destination table during query job"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/RunLegacyQueryIT.java b/samples/snippets/src/test/java/com/example/bigquery/RunLegacyQueryIT.java deleted file mode 100644 index aeff57335..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/RunLegacyQueryIT.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class RunLegacyQueryIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testRunLegacyQuery() { - RunLegacyQuery.runLegacyQuery(); - assertThat(bout.toString()).contains("Legacy query ran successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/SaveQueryToTableIT.java b/samples/snippets/src/test/java/com/example/bigquery/SaveQueryToTableIT.java deleted file mode 100644 index a1bb54f96..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/SaveQueryToTableIT.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class SaveQueryToTableIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - tableName = "MY_TABLE_NAME_" + UUID.randomUUID().toString().substring(0, 8); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testSaveQueryToTable() { - String query = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;"; - SaveQueryToTable.saveQueryToTable(BIGQUERY_DATASET_NAME, tableName, query); - assertThat(bout.toString()).contains("Saved query ran successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/SetUserAgentTest.java b/samples/snippets/src/test/java/com/example/bigquery/SetUserAgentTest.java deleted file mode 100644 index 6c5c9cf6d..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/SetUserAgentTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2022 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class SetUserAgentTest { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String customUserAgentValue; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - customUserAgentValue = "CUSTOM_USER_AGENT_" + UUID.randomUUID().toString().substring(0, 8); - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // Clean up - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void setUserAgentTest() throws IOException { - SetUserAgent.setUserAgent(PROJECT_ID, customUserAgentValue); - assertThat(bout.toString()).contains("CUSTOM_USER_AGENT_"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/SimpleAppIT.java b/samples/snippets/src/test/java/com/example/bigquery/SimpleAppIT.java deleted file mode 100644 index 4c4030c7d..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/SimpleAppIT.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Tests for simple app sample. */ -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class SimpleAppIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testQuickstart() throws Exception { - SimpleApp.simpleApp(PROJECT_ID); - String got = bout.toString(); - assertThat(got).contains("https://stackoverflow.com/questions/"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/SimpleQueryConnectionReadApiIT.java b/samples/snippets/src/test/java/com/example/bigquery/SimpleQueryConnectionReadApiIT.java deleted file mode 100644 index b7cb109c7..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/SimpleQueryConnectionReadApiIT.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class SimpleQueryConnectionReadApiIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testSimpleQueryConnectionReadApi() { - String query = - "SELECT corpus, count(*) as corpus_count " - + "FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;"; - - SimpleQueryConnectionReadApi.simpleQueryConnectionReadApi(query); - assertThat(bout.toString()).contains("Query ran successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/SimpleQueryIT.java b/samples/snippets/src/test/java/com/example/bigquery/SimpleQueryIT.java deleted file mode 100644 index 5441ffcca..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/SimpleQueryIT.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class SimpleQueryIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testSimpleQuery() { - String query = - "SELECT corpus, count(*) as corpus_count " - + "FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;"; - - SimpleQuery.simpleQuery(query); - assertThat(bout.toString()).contains("Query ran successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/TableExistsIT.java b/samples/snippets/src/test/java/com/example/bigquery/TableExistsIT.java deleted file mode 100644 index 4573648a6..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/TableExistsIT.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class TableExistsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // create a temporary table - tableName = "MY_TABLE_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - } - - @After - public void tearDown() { - // delete a temporary table - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testTableExists() { - TableExists.tableExists(BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()).contains("Table not found"); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, Schema.of()); - TableExists.tableExists(BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()).contains("Table already exist"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/TableInsertRowsIT.java b/samples/snippets/src/test/java/com/example/bigquery/TableInsertRowsIT.java deleted file mode 100644 index d47953012..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/TableInsertRowsIT.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.LegacySQLTypeName; -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class TableInsertRowsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - tableName = "INSERT_ROW_INTO_TABLE_TEST" + UUID.randomUUID().toString().substring(0, 8); - Schema schema = - Schema.of( - Field.of("booleanField", LegacySQLTypeName.BOOLEAN), - Field.of("numericField", LegacySQLTypeName.NUMERIC)); - - // Create table in dataset for testing - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testTableInsertRows() { - // Create a row to insert - Map rowContent = new HashMap<>(); - rowContent.put("booleanField", true); - rowContent.put("numericField", "3.14"); - String rowId = "ROW_ID"; - // Testing - TableInsertRows.tableInsertRows(BIGQUERY_DATASET_NAME, tableName, rowId, rowContent); - assertThat(bout.toString()).contains("Rows successfully inserted into table"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/TableInsertRowsWithoutRowIdsIT.java b/samples/snippets/src/test/java/com/example/bigquery/TableInsertRowsWithoutRowIdsIT.java deleted file mode 100644 index ae00c10f8..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/TableInsertRowsWithoutRowIdsIT.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.LegacySQLTypeName; -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class TableInsertRowsWithoutRowIdsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - tableName = "INSERT_ROW_WITHOUT_ROW_ID_TEST" + UUID.randomUUID().toString().substring(0, 8); - Schema schema = - Schema.of( - Field.of("stringField", LegacySQLTypeName.STRING), - Field.of("numericField", LegacySQLTypeName.NUMERIC)); - - // Create table in dataset for testing - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testTableInsertRowsWithoutRowIds() { - TableInsertRowsWithoutRowIds.tableInsertRowsWithoutRowIds(BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()).contains("Rows successfully inserted into table without row ids"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/UndeleteTableIT.java b/samples/snippets/src/test/java/com/example/bigquery/UndeleteTableIT.java deleted file mode 100644 index f53b0e41f..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/UndeleteTableIT.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class UndeleteTableIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private String recoverTableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - tableName = "UNDELETE_TABLE_TEST_" + UUID.randomUUID().toString().substring(0, 8); - recoverTableName = "RECOVER_DELETE_TABLE_TEST_" + UUID.randomUUID().toString().substring(0, 8); - // Create table in dataset for testing - Schema schema = - Schema.of( - Field.of("stringField", StandardSQLTypeName.STRING), - Field.of("booleanField", StandardSQLTypeName.BOOL)); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, recoverTableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testUndeleteTable() { - UndeleteTable.undeleteTable(BIGQUERY_DATASET_NAME, tableName, recoverTableName); - assertThat(bout.toString()).contains("Undelete table recovered successfully."); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/UpdateDatasetAccessIT.java b/samples/snippets/src/test/java/com/example/bigquery/UpdateDatasetAccessIT.java deleted file mode 100644 index 2a1ed26f9..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/UpdateDatasetAccessIT.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Acl; -import com.google.cloud.bigquery.Acl.Role; -import com.google.cloud.bigquery.Acl.User; -import com.google.cloud.bigquery.testing.RemoteBigQueryHelper; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class UpdateDatasetAccessIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String GOOGLE_CLOUD_PROJECT = System.getenv("GOOGLE_CLOUD_PROJECT"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws Exception { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - tableName = RemoteBigQueryHelper.generateDatasetName(); - // Create a dataset in order to modify its ACL - CreateDataset.createDataset(tableName); - } - - @After - public void tearDown() { - // Clean up - DeleteDataset.deleteDataset(GOOGLE_CLOUD_PROJECT, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void updateDatasetAccess() { - Acl newEntry = Acl.of(new User("sample.bigquery.dev@gmail.com"), Role.READER); - // Modify dataset's ACL - UpdateDatasetAccess.updateDatasetAccess(tableName, newEntry); - assertThat(bout.toString()).contains("Dataset Access Control updated successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/UpdateDatasetDescriptionIT.java b/samples/snippets/src/test/java/com/example/bigquery/UpdateDatasetDescriptionIT.java deleted file mode 100644 index c74e91d1f..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/UpdateDatasetDescriptionIT.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.testing.RemoteBigQueryHelper; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class UpdateDatasetDescriptionIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String GOOGLE_CLOUD_PROJECT = System.getenv("GOOGLE_CLOUD_PROJECT"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws Exception { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - tableName = RemoteBigQueryHelper.generateDatasetName(); - // Create a dataset in order to modify its description - CreateDataset.createDataset(tableName); - } - - @After - public void tearDown() { - // Clean up - DeleteDataset.deleteDataset(GOOGLE_CLOUD_PROJECT, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void updateDatasetDescription() { - String newDescription = "new description!"; - // Modify dataset's description - UpdateDatasetDescription.updateDatasetDescription(tableName, newDescription); - assertThat(bout.toString()) - .contains("Dataset description updated successfully to " + newDescription); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/UpdateDatasetExpirationIT.java b/samples/snippets/src/test/java/com/example/bigquery/UpdateDatasetExpirationIT.java deleted file mode 100644 index 201b74600..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/UpdateDatasetExpirationIT.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.testing.RemoteBigQueryHelper; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class UpdateDatasetExpirationIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String GOOGLE_CLOUD_PROJECT = System.getenv("GOOGLE_CLOUD_PROJECT"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws Exception { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - tableName = RemoteBigQueryHelper.generateDatasetName(); - // Create a dataset in order to modify its expiration - CreateDataset.createDataset(tableName); - } - - @After - public void tearDown() { - // Clean up - DeleteDataset.deleteDataset(GOOGLE_CLOUD_PROJECT, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void updateDatasetExpiration() { - Long newExpiration = TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS); - // Modify dataset's expiration - UpdateDatasetExpiration.updateDatasetExpiration(tableName, newExpiration); - assertThat(bout.toString()).contains("Dataset description updated successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/UpdateDatasetPartitionExpirationIT.java b/samples/snippets/src/test/java/com/example/bigquery/UpdateDatasetPartitionExpirationIT.java deleted file mode 100644 index 0ef2a4726..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/UpdateDatasetPartitionExpirationIT.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.testing.RemoteBigQueryHelper; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class UpdateDatasetPartitionExpirationIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String datasetName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String GOOGLE_CLOUD_PROJECT = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - datasetName = RemoteBigQueryHelper.generateDatasetName(); - // Create a dataset in order to modify its partition expiration - CreateDataset.createDataset(datasetName); - } - - @After - public void tearDown() { - // Clean up - DeleteDataset.deleteDataset(GOOGLE_CLOUD_PROJECT, datasetName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testUpdateDatasetPartitionExpiration() { - Long newExpiration = TimeUnit.MILLISECONDS.convert(90, TimeUnit.DAYS); - UpdateDatasetPartitionExpiration.updateDatasetPartitionExpiration(datasetName, newExpiration); - assertThat(bout.toString()) - .contains("Dataset default partition expiration updated successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/UpdateIamPolicyIT.java b/samples/snippets/src/test/java/com/example/bigquery/UpdateIamPolicyIT.java deleted file mode 100644 index 196fcd4ef..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/UpdateIamPolicyIT.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class UpdateIamPolicyIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // create a temporary table - tableName = "UPDATE_POLICY_TABLE_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, Schema.of()); - CreateIamPolicy.createIamPolicy(BIGQUERY_DATASET_NAME, tableName); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testUpdateIamPolicy() { - UpdateIamPolicy.updateIamPolicy(BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()).contains("Iam policy updated successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/UpdateMaterializedViewIT.java b/samples/snippets/src/test/java/com/example/bigquery/UpdateMaterializedViewIT.java deleted file mode 100644 index 54ed2194a..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/UpdateMaterializedViewIT.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class UpdateMaterializedViewIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private String materializedViewName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - tableName = "MY_TABLE_NAME_TEST_" + ID; - materializedViewName = "MY_UPDATE_MATERIALIZED_VIEW_NAME_TEST_" + ID; - - Schema schema = - Schema.of( - Field.of("timestampField", StandardSQLTypeName.TIMESTAMP), - Field.of("stringField", StandardSQLTypeName.STRING), - Field.of("booleanField", StandardSQLTypeName.BOOL)); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); - String query = - String.format( - "SELECT MAX(TimestampField) AS TimestampField, StringField, " - + "MAX(BooleanField) AS BooleanField " - + "FROM %s.%s GROUP BY StringField", - BIGQUERY_DATASET_NAME, tableName); - CreateMaterializedView.createMaterializedView( - BIGQUERY_DATASET_NAME, materializedViewName, query); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, materializedViewName); - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testUpdateMaterializedView() { - UpdateMaterializedView.updateMaterializedView(BIGQUERY_DATASET_NAME, materializedViewName); - assertThat(bout.toString()).contains("Materialized view updated successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/UpdateModelDescriptionIT.java b/samples/snippets/src/test/java/com/example/bigquery/UpdateModelDescriptionIT.java deleted file mode 100644 index 478cfec97..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/UpdateModelDescriptionIT.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class UpdateModelDescriptionIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String modelName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // create a test model - modelName = "MY_MODEL_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - String sql = - "CREATE MODEL `" - + BIGQUERY_DATASET_NAME - + "." - + modelName - + "`" - + "OPTIONS ( " - + "model_type='linear_reg', " - + "max_iterations=1, " - + "learn_rate=0.4, " - + "learn_rate_strategy='constant' " - + ") AS ( " - + "SELECT 'a' AS f1, 2.0 AS label " - + "UNION ALL " - + "SELECT 'b' AS f1, 3.8 AS label " - + ")"; - CreateModel.createModel(sql); - } - - @After - public void tearDown() { - // Clean up - DeleteModel.deleteModel(BIGQUERY_DATASET_NAME, modelName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testUpdateModelDescription() { - String newDescription = "A really great model."; - UpdateModelDescription.updateModelDescription(BIGQUERY_DATASET_NAME, modelName, newDescription); - assertThat(bout.toString()).contains("Model description updated successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/UpdateRoutineIT.java b/samples/snippets/src/test/java/com/example/bigquery/UpdateRoutineIT.java deleted file mode 100644 index 2abfe4cf7..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/UpdateRoutineIT.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class UpdateRoutineIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String routineName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // create a temporary routine - routineName = "MY_ROUTINE_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - CreateRoutine.createRoutine(BIGQUERY_DATASET_NAME, routineName); - } - - @After - public void tearDown() { - // Clean up - DeleteRoutine.deleteRoutine(BIGQUERY_DATASET_NAME, routineName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testUpdateRoutine() { - UpdateRoutine.updateRoutine(BIGQUERY_DATASET_NAME, routineName); - assertThat(bout.toString()).contains("Routine updated successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/UpdateTableCmekIT.java b/samples/snippets/src/test/java/com/example/bigquery/UpdateTableCmekIT.java deleted file mode 100644 index ddeb7a022..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/UpdateTableCmekIT.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.EncryptionConfiguration; -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class UpdateTableCmekIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - private static final String BIGQUERY_KMS_KEY_NAME = requireEnvVar("BIGQUERY_KMS_KEY_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - requireEnvVar("BIGQUERY_KMS_KEY_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // create a test table. - tableName = "MY_UPDATE_TABLE_CMEK_TEST" + UUID.randomUUID().toString().substring(0, 8); - Schema schema = - Schema.of( - Field.of("stringField", StandardSQLTypeName.STRING), - Field.of("booleanField", StandardSQLTypeName.BOOL)); - EncryptionConfiguration encryption = - EncryptionConfiguration.newBuilder().setKmsKeyName(BIGQUERY_KMS_KEY_NAME).build(); - CreateTableCmek.createTableCmek(BIGQUERY_DATASET_NAME, tableName, schema, encryption); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testUpdateTableCmek() { - EncryptionConfiguration encryption = - EncryptionConfiguration.newBuilder().setKmsKeyName(BIGQUERY_KMS_KEY_NAME).build(); - UpdateTableCmek.updateTableCmek(BIGQUERY_DATASET_NAME, tableName, encryption); - assertThat(bout.toString()).contains("Table cmek updated successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/UpdateTableDescriptionIT.java b/samples/snippets/src/test/java/com/example/bigquery/UpdateTableDescriptionIT.java deleted file mode 100644 index d26a79da5..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/UpdateTableDescriptionIT.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class UpdateTableDescriptionIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // Create a table in order to modify its description - tableName = "MY_TABLE_NAME_" + UUID.randomUUID().toString().replace("-", "_"); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, null); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testUpdateTableDescription() { - String newDescription = "new description!"; - // Modify table's description - UpdateTableDescription.updateTableDescription(BIGQUERY_DATASET_NAME, tableName, newDescription); - assertThat(bout.toString()) - .contains("Table description updated successfully to " + newDescription); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/UpdateTableDmlIT.java b/samples/snippets/src/test/java/com/example/bigquery/UpdateTableDmlIT.java deleted file mode 100644 index 53ba0d1ab..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/UpdateTableDmlIT.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.LegacySQLTypeName; -import com.google.cloud.bigquery.Schema; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class UpdateTableDmlIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Create a test table - tableName = "UserSessions_TEST_" + UUID.randomUUID().toString().replace('-', '_'); - Schema schema = - Schema.of( - Field.of("id", LegacySQLTypeName.STRING), - Field.of("user_id", LegacySQLTypeName.STRING), - Field.of("login_time", LegacySQLTypeName.STRING), - Field.of("logout_time", LegacySQLTypeName.STRING), - Field.of("ip_address", LegacySQLTypeName.STRING)); - - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testUpdateTableDml() throws IOException, InterruptedException { - UpdateTableDml.updateTableDml(BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()).contains("Table updated successfully using DML"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/UpdateTableExpirationIT.java b/samples/snippets/src/test/java/com/example/bigquery/UpdateTableExpirationIT.java deleted file mode 100644 index 1e3b8980f..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/UpdateTableExpirationIT.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.time.Instant; -import java.time.temporal.ChronoUnit; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class UpdateTableExpirationIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); - - private static void requireEnvVar(String varName) { - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - String suffix = UUID.randomUUID().toString().replace('-', '_'); - tableName = "update_expiration_table_" + suffix; - Schema schema = - Schema.of( - Field.of("stringField", StandardSQLTypeName.STRING), - Field.of("booleanField", StandardSQLTypeName.BOOL)); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testUpdateTableExpiration() { - // Set new expiration to a week from Now - Long newExpiration = Instant.now().plus(7, ChronoUnit.DAYS).toEpochMilli(); - UpdateTableExpiration.updateTableExpiration(BIGQUERY_DATASET_NAME, tableName, newExpiration); - assertThat(bout.toString()).contains("Table expiration updated successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/UpdateTableRequirePartitionFilterIT.java b/samples/snippets/src/test/java/com/example/bigquery/UpdateTableRequirePartitionFilterIT.java deleted file mode 100644 index c6c9233ee..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/UpdateTableRequirePartitionFilterIT.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class UpdateTableRequirePartitionFilterIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - tableName = - "UPDATE_TABLE_REQUIRE_PARTITION_FILTER_TEST_" - + UUID.randomUUID().toString().substring(0, 8); - // Create a table in order to modify its partition filter. - Schema schema = - Schema.of( - Field.of("name", StandardSQLTypeName.STRING), - Field.of("post_abbr", StandardSQLTypeName.STRING), - Field.of("date", StandardSQLTypeName.DATE)); - CreatePartitionedTable.createPartitionedTable(BIGQUERY_DATASET_NAME, tableName, schema); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testUpdateTableRequirePartitionFilter() { - UpdateTableRequirePartitionFilter.updateTableRequirePartitionFilter( - BIGQUERY_DATASET_NAME, tableName); - assertThat(bout.toString()).contains("Table require partition filter updated successfully"); - } -} diff --git a/samples/snippets/src/test/java/com/example/bigquery/UpdateViewQueryIT.java b/samples/snippets/src/test/java/com/example/bigquery/UpdateViewQueryIT.java deleted file mode 100644 index 2b14e6655..000000000 --- a/samples/snippets/src/test/java/com/example/bigquery/UpdateViewQueryIT.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed 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 com.example.bigquery; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class UpdateViewQueryIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tableName; - private String viewName; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String BIGQUERY_DATASET_NAME = requireEnvVar("BIGQUERY_DATASET_NAME"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("BIGQUERY_DATASET_NAME"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - tableName = "MY_TABLE_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - viewName = "MY_VIEW_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8); - - // create a test table. - Schema schema = - Schema.of( - Field.of("timestampField", StandardSQLTypeName.TIMESTAMP), - Field.of("stringField", StandardSQLTypeName.STRING), - Field.of("booleanField", StandardSQLTypeName.BOOL)); - CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema); - - // create a test view - String query = - String.format( - "SELECT timestampField, stringField, booleanField FROM %s.%s", - BIGQUERY_DATASET_NAME, tableName); - CreateView.createView(BIGQUERY_DATASET_NAME, viewName, query); - } - - @After - public void tearDown() { - // Clean up - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, viewName); - DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, "\n" + bout.toString()); - } - - @Test - public void testUpdateViewQuery() { - String updateQuery = - String.format( - "SELECT TimestampField, StringField FROM %s.%s", BIGQUERY_DATASET_NAME, tableName); - UpdateViewQuery.updateViewQuery(BIGQUERY_DATASET_NAME, viewName, updateQuery); - assertThat(bout.toString()).contains("View query updated successfully"); - } -}