1818
1919import static com .google .common .truth .Truth .assertThat ;
2020
21+ import com .google .cloud .ServiceOptions ;
22+ import com .google .cloud .bigquery .BigQuery ;
23+ import com .google .cloud .bigquery .BigQuery .DatasetDeleteOption ;
24+ import com .google .cloud .bigquery .BigQueryOptions ;
25+ import com .google .cloud .bigquery .Dataset ;
26+ import com .google .cloud .bigquery .DatasetId ;
27+ import com .google .cloud .bigquery .DatasetInfo ;
28+ import com .google .cloud .bigquery .testing .RemoteBigQueryHelper ;
2129import com .google .cloud .storage .BlobInfo ;
2230import com .google .cloud .storage .Bucket ;
2331import com .google .cloud .storage .BucketInfo ;
3846@ SuppressWarnings ("checkstyle:abbreviationaswordinname" )
3947public class QuickStartIT {
4048 private static final String bucketName = UUID .randomUUID ().toString ();
49+ private static final String datasetName = RemoteBigQueryHelper .generateDatasetName ();
4150 private ByteArrayOutputStream bout ;
4251 private PrintStream out ;
52+ private BigQuery bigquery ;
4353
4454 private static final void deleteBucket (String bucketName ) {
4555 Storage storage = StorageOptions .getDefaultInstance ().getService ();
@@ -62,6 +72,10 @@ private static final void createBucket(String bucketName) {
6272 @ Before
6373 public void setUp () {
6474 createBucket (bucketName );
75+ bigquery = BigQueryOptions .getDefaultInstance ().getService ();
76+ if (bigquery .getDataset (datasetName ) == null ) {
77+ Dataset dataset = bigquery .create (DatasetInfo .newBuilder (datasetName ).build ());
78+ }
6579 bout = new ByteArrayOutputStream ();
6680 out = new PrintStream (bout );
6781 System .setOut (out );
@@ -72,6 +86,8 @@ public void tearDown() {
7286 String consoleOutput = bout .toString ();
7387 System .setOut (null );
7488 deleteBucket (bucketName );
89+ DatasetId datasetId = DatasetId .of (bigquery .getOptions ().getProjectId (), datasetName );
90+ bigquery .delete (datasetId , DatasetDeleteOption .deleteContents ());
7591 }
7692
7793 @ Test
@@ -82,8 +98,20 @@ public void testExportAssetExample() throws Exception {
8298 assertThat (got ).contains (String .format ("uri: \" %s\" " , assetDumpPath ));
8399 }
84100
101+ @ Test
102+ public void testExportAssetBigqueryExample () throws Exception {
103+ String dataset =
104+ String .format ("projects/%s/datasets/%s" , ServiceOptions .getDefaultProjectId (), datasetName );
105+ String table = "java_test" ;
106+ ExportAssetsBigqueryExample .exportBigQuery (dataset , table );
107+ String got = bout .toString ();
108+ assertThat (got ).contains (String .format ("dataset: \" %s\" " , dataset ));
109+ }
110+
85111 @ Test
86112 public void testBatchGetAssetsHistory () throws Exception {
113+ // Wait 10 seconds to let bucket creation event go to CAI
114+ Thread .sleep (10000 );
87115 String bucketAssetName = String .format ("//storage.googleapis.com/%s" , bucketName );
88116 BatchGetAssetsHistoryExample .main (bucketAssetName );
89117 String got = bout .toString ();
0 commit comments