18
18
19
19
import static com .google .common .truth .Truth .assertThat ;
20
20
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 ;
21
29
import com .google .cloud .storage .BlobInfo ;
22
30
import com .google .cloud .storage .Bucket ;
23
31
import com .google .cloud .storage .BucketInfo ;
38
46
@ SuppressWarnings ("checkstyle:abbreviationaswordinname" )
39
47
public class QuickStartIT {
40
48
private static final String bucketName = UUID .randomUUID ().toString ();
49
+ private static final String datasetName = RemoteBigQueryHelper .generateDatasetName ();
41
50
private ByteArrayOutputStream bout ;
42
51
private PrintStream out ;
52
+ private BigQuery bigquery ;
43
53
44
54
private static final void deleteBucket (String bucketName ) {
45
55
Storage storage = StorageOptions .getDefaultInstance ().getService ();
@@ -62,6 +72,10 @@ private static final void createBucket(String bucketName) {
62
72
@ Before
63
73
public void setUp () {
64
74
createBucket (bucketName );
75
+ bigquery = BigQueryOptions .getDefaultInstance ().getService ();
76
+ if (bigquery .getDataset (datasetName ) == null ) {
77
+ Dataset dataset = bigquery .create (DatasetInfo .newBuilder (datasetName ).build ());
78
+ }
65
79
bout = new ByteArrayOutputStream ();
66
80
out = new PrintStream (bout );
67
81
System .setOut (out );
@@ -72,6 +86,8 @@ public void tearDown() {
72
86
String consoleOutput = bout .toString ();
73
87
System .setOut (null );
74
88
deleteBucket (bucketName );
89
+ DatasetId datasetId = DatasetId .of (bigquery .getOptions ().getProjectId (), datasetName );
90
+ bigquery .delete (datasetId , DatasetDeleteOption .deleteContents ());
75
91
}
76
92
77
93
@ Test
@@ -82,8 +98,20 @@ public void testExportAssetExample() throws Exception {
82
98
assertThat (got ).contains (String .format ("uri: \" %s\" " , assetDumpPath ));
83
99
}
84
100
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
+
85
111
@ Test
86
112
public void testBatchGetAssetsHistory () throws Exception {
113
+ // Wait 10 seconds to let bucket creation event go to CAI
114
+ Thread .sleep (10000 );
87
115
String bucketAssetName = String .format ("//storage.googleapis.com/%s" , bucketName );
88
116
BatchGetAssetsHistoryExample .main (bucketAssetName );
89
117
String got = bout .toString ();
0 commit comments