|
| 1 | +/* |
| 2 | + Copyright 2016, Google, Inc. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package com.example.bigquery; |
| 18 | + |
| 19 | +import static com.google.common.truth.Truth.assertThat; |
| 20 | + |
| 21 | +import com.google.cloud.bigquery.BigQuery; |
| 22 | +import com.google.cloud.bigquery.BigQuery.DatasetDeleteOption; |
| 23 | +import com.google.cloud.bigquery.BigQueryOptions; |
| 24 | +import com.google.cloud.bigquery.DatasetId; |
| 25 | +import org.junit.After; |
| 26 | +import org.junit.Before; |
| 27 | +import org.junit.Test; |
| 28 | +import org.junit.runner.RunWith; |
| 29 | +import org.junit.runners.JUnit4; |
| 30 | + |
| 31 | +import java.io.ByteArrayOutputStream; |
| 32 | +import java.io.PrintStream; |
| 33 | + |
| 34 | +/** |
| 35 | + * Tests for quickstart sample. |
| 36 | + */ |
| 37 | +@RunWith(JUnit4.class) |
| 38 | +@SuppressWarnings("checkstyle:abbreviationaswordinname") |
| 39 | +public class QuickstartSampleIT { |
| 40 | + private ByteArrayOutputStream bout; |
| 41 | + private PrintStream out; |
| 42 | + |
| 43 | + private static final void deleteMyNewDataset() { |
| 44 | + BigQuery bigquery = BigQueryOptions.defaultInstance().service(); |
| 45 | + String datasetName = "my_new_dataset"; |
| 46 | + DatasetId datasetId = DatasetId.of(datasetName); |
| 47 | + DatasetDeleteOption deleteContents = DatasetDeleteOption.deleteContents(); |
| 48 | + bigquery.delete(datasetId, deleteContents); |
| 49 | + } |
| 50 | + |
| 51 | + @Before |
| 52 | + public void setUp() { |
| 53 | + deleteMyNewDataset(); |
| 54 | + |
| 55 | + bout = new ByteArrayOutputStream(); |
| 56 | + out = new PrintStream(bout); |
| 57 | + System.setOut(out); |
| 58 | + } |
| 59 | + |
| 60 | + @After |
| 61 | + public void tearDown() { |
| 62 | + System.setOut(null); |
| 63 | + deleteMyNewDataset(); |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + public void testQuickstart() throws Exception { |
| 68 | + QuickstartSample.main(); |
| 69 | + String got = bout.toString(); |
| 70 | + assertThat(got).contains("Dataset my_new_dataset created."); |
| 71 | + } |
| 72 | +} |
0 commit comments