@@ -0,0 +1,3311 @@
+/*%0A * Copyright 2021 Google LLC%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.example.bigquerystorage;%0A%0Aimport static com.google.common.truth.Truth.assertThat;%0Aimport static junit.framework.TestCase.assertNotNull;%0A%0Aimport com.google.cloud.bigquery.BigQuery;%0Aimport com.google.cloud.bigquery.BigQuery.DatasetDeleteOption;%0Aimport com.google.cloud.bigquery.BigQueryOptions;%0Aimport com.google.cloud.bigquery.DatasetId;%0Aimport com.google.cloud.bigquery.DatasetInfo;%0Aimport com.google.cloud.bigquery.Field;%0Aimport com.google.cloud.bigquery.Schema;%0Aimport com.google.cloud.bigquery.StandardSQLTypeName;%0Aimport com.google.cloud.bigquery.StandardTableDefinition;%0Aimport com.google.cloud.bigquery.TableId;%0Aimport com.google.cloud.bigquery.TableInfo;%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.PrintStream;%0Aimport java.util.UUID;%0Aimport org.junit.After;%0Aimport org.junit.Before;%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.junit.runners.JUnit4;%0A%0A@RunWith(JUnit4.class)%0Apublic class WriteToDefaultStreamIT %7B%0A%0A  private static final String GOOGLE_CLOUD_PROJECT = System.getenv(%22GOOGLE_CLOUD_PROJECT%22);%0A%0A  private ByteArrayOutputStream bout;%0A  private PrintStream out;%0A  private BigQuery bigquery;%0A  private String datasetName;%0A  private String tableName;%0A%0A  private static void requireEnvVar(String varName) %7B%0A    assertNotNull(%0A        %22Environment variable %22 + varName + %22 is required to perform these tests.%22,%0A        System.getenv(varName));%0A  %7D%0A%0A  @BeforeClass%0A  public static void checkRequirements() %7B%0A    requireEnvVar(%22GOOGLE_CLOUD_PROJECT%22);%0A  %7D%0A%0A  @Before%0A  public void setUp() %7B%0A    bout = new ByteArrayOutputStream();%0A    out = new PrintStream(bout);%0A    System.setOut(out);%0A%0A    bigquery = BigQueryOptions.getDefaultInstance().getService();%0A%0A    // Create a new dataset and table for each test.%0A    datasetName = %22WRITE_STREAM_TEST%22 + UUID.randomUUID().toString().substring(0, 8);%0A    tableName = %22DEFAULT_STREAM_TEST%22 + UUID.randomUUID().toString().substring(0, 8);%0A    Schema schema = Schema.of(Field.of(%22col1%22, StandardSQLTypeName.STRING));%0A    bigquery.create(DatasetInfo.newBuilder(datasetName).build());%0A    TableInfo tableInfo =%0A        TableInfo.newBuilder(TableId.of(datasetName, tableName), StandardTableDefinition.of(schema))%0A            .build();%0A    bigquery.create(tableInfo);%0A  %7D%0A%0A  @After%0A  public void tearDown() %7B%0A    bigquery.delete(%0A        DatasetId.of(GOOGLE_CLOUD_PROJECT, datasetName), DatasetDeleteOption.deleteContents());%0A    System.setOut(null);%0A  %7D%0A%0A  @Test%0A  public void testWriteToDefaultStream() throws Exception %7B%0A    WriteToDefaultStream.writeToDefaultStream(GOOGLE_CLOUD_PROJECT, datasetName, tableName);%0A    assertThat(bout.toString()).contains(%22Appended records successfully.%22);%0A  %7D%0A%7D%0A

add IT for WriteToDefaultStream (#1158)