Skip to content

Commit 7b4389b

Browse files
committed
Add integration tests to BigQuery quickstart sample.
1 parent 8a1d549 commit 7b4389b

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

bigquery/cloud-client/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ You can then run a given `ClassName` via:
2222
-DpropertyName=propertyValue \
2323
-Dexec.args="any arguments to the app"
2424

25+
### Creating a new dataset (using the quickstart sample)
26+
27+
mvn exec:java -Dexec.mainClass=com.example.bigquery.QuickstartSample
28+
2529
### Running a synchronous query
2630

2731
mvn exec:java -Dexec.mainClass=com.example.bigquery.SyncQuerySample \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
}

bigquery/cloud-client/src/test/java/com/example/bigquery/SyncQuerySampleTest.java renamed to bigquery/cloud-client/src/test/java/com/example/bigquery/SyncQuerySampleIT.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
* Tests for synchronous query sample.
3232
*/
3333
@RunWith(JUnit4.class)
34-
public class SyncQuerySampleTest {
34+
@SuppressWarnings("checkstyle:abbreviationaswordinname")
35+
public class SyncQuerySampleIT {
3536
private ByteArrayOutputStream bout;
3637
private PrintStream out;
3738

0 commit comments

Comments
 (0)