@@ -69,8 +69,8 @@ public void beforeTest() throws IOException {
69
69
System .setOut (new PrintStream (bout ));
70
70
71
71
String datasetId = "dataset-" + UUID .randomUUID ().toString ().replaceAll ("-" , "_" );
72
- datasetName =
73
- String .format ("projects/ %s/locations/%s/ datasets/%s" , PROJECT_ID , REGION_ID , datasetId );
72
+ String parentName = String . format ( "projects/%s/locations/%s" , PROJECT_ID , REGION_ID );
73
+ datasetName = String .format ("%s/datasets/%s" , parentName , datasetId );
74
74
75
75
DatasetCreate .datasetCreate (PROJECT_ID , REGION_ID , datasetId );
76
76
@@ -79,30 +79,41 @@ public void beforeTest() throws IOException {
79
79
}
80
80
81
81
@ After
82
- public void tearDown () {
82
+ public void tearDown () throws IOException {
83
83
System .setOut (originalOut );
84
+ try {
85
+ DatasetDelete .datasetDelete (datasetName );
86
+ } catch (GoogleJsonResponseException ex ) {
87
+ // Dataset already deleted, continue.
88
+ }
84
89
bout .reset ();
85
90
}
86
91
87
92
@ Test
88
- public void test_DatasetCreate () throws IOException {
89
- String newDatasetName =
90
- String .format ("projects/%s/locations/%s/datasets/new-dataset" , PROJECT_ID , REGION_ID );
93
+ public void test_DatasetCreateDelete () throws IOException {
94
+ String newName = "new-dataset" ;
95
+ String newFullName =
96
+ String .format ("projects/%s/locations/%s/datasets/%s" , PROJECT_ID , REGION_ID , newName );
91
97
try {
92
- DatasetDelete .datasetDelete (newDatasetName );
98
+ DatasetDelete .datasetDelete (newFullName );
93
99
} catch (GoogleJsonResponseException gjre ) {
94
100
// Expected if new-dataset does not exist.
95
101
}
96
- DatasetCreate .datasetCreate (PROJECT_ID , REGION_ID , "new-dataset" );
102
+ DatasetCreate .datasetCreate (PROJECT_ID , REGION_ID , newName );
97
103
98
104
String output = bout .toString (StandardCharsets .UTF_8 );
99
105
assertThat (output , containsString ("Dataset created." ));
106
+ bout .reset ();
107
+
108
+ DatasetDelete .datasetDelete (newFullName );
109
+
110
+ output = bout .toString ();
111
+ assertThat (output , containsString ("Dataset deleted." ));
100
112
}
101
113
102
114
@ Test
103
115
public void test_DatasetGet () throws IOException {
104
116
DatasetGet .datasetGet (datasetName );
105
-
106
117
String output = bout .toString ();
107
118
assertThat (output , containsString ("Dataset retrieved:" ));
108
119
}
@@ -146,12 +157,4 @@ public void test_DatasetSetIamPolicy() throws IOException {
146
157
String output = bout .toString ();
147
158
assertThat (output , containsString ("Dataset policy has been updated: " ));
148
159
}
149
-
150
- @ Test
151
- public void test_DatasetDelete () throws IOException {
152
- DatasetDelete .datasetDelete (datasetName );
153
-
154
- String output = bout .toString ();
155
- assertThat (output , containsString ("Dataset deleted." ));
156
- }
157
160
}
0 commit comments