1
1
/*
2
- * Copyright 2018 Google Inc.
2
+ * Copyright 2018 Google LLC
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
import static junit .framework .Assert .fail ;
21
21
import static junit .framework .TestCase .assertEquals ;
22
22
23
+ import com .google .api .gax .rpc .NotFoundException ;
23
24
import com .google .cloud .devtools .containeranalysis .v1beta1 .GrafeasV1Beta1Client ;
24
25
import com .google .cloud .pubsub .v1 .Subscriber ;
25
26
import com .google .cloud .pubsub .v1 .SubscriptionAdminClient ;
@@ -74,6 +75,7 @@ public static void tearDownClass() {
74
75
subscriptionAdminClient .shutdownNow ();
75
76
} catch (Exception e ) {
76
77
// these exceptions aren't relevant to the tests
78
+ System .out .println ("TearDownClass Error: " + e .toString ());
77
79
}
78
80
}
79
81
@@ -92,30 +94,28 @@ public void tearDown() {
92
94
Samples .deleteNote (client , noteId , PROJECT_ID );
93
95
} catch (Exception e ) {
94
96
// these exceptions aren't relevant to the tests
97
+ System .out .println ("TearDown Error: " + e .toString ());
95
98
}
96
99
}
97
100
98
101
@ Test
99
102
public void testCreateNote () throws Exception {
100
-
101
103
// note should have been created as part of set up. verify that it succeeded
102
104
Note n = Samples .getNote (client , noteId , PROJECT_ID );
103
105
104
106
assertEquals (n .getName (), noteObj .getName ());
105
-
106
107
}
107
108
108
109
@ Test
109
110
public void testDeleteNote () throws Exception {
110
111
Samples .deleteNote (client , noteId , PROJECT_ID );
111
112
try {
112
113
Samples .getNote (client , noteId , PROJECT_ID );
113
- //above should throw, because note was deleted
114
+ // above should throw, because note was deleted
114
115
fail ("note not deleted" );
115
- } catch (Exception e ) {
116
+ } catch (NotFoundException e ) {
116
117
// test passes
117
118
}
118
-
119
119
}
120
120
121
121
@ Test
@@ -133,29 +133,27 @@ public void testUpdateNote() throws Exception {
133
133
134
134
@ Test
135
135
public void testCreateOccurrence () throws Exception {
136
-
137
136
Occurrence o = Samples .createOccurrence (client , imageUrl , noteId , PROJECT_ID , PROJECT_ID );
138
137
Occurrence retrieved = Samples .getOccurrence (client , o .getName ());
139
138
assertEquals (o .getName (), retrieved .getName ());
140
139
141
- //clean up
140
+ // clean up
142
141
Samples .deleteOccurrence (client , o .getName ());
143
142
}
144
143
145
144
@ Test
146
145
public void testDeleteOccurrence () throws Exception {
147
-
148
146
Occurrence o = Samples .createOccurrence (client , imageUrl , noteId , PROJECT_ID , PROJECT_ID );
149
147
String occName = o .getName ();
150
148
151
149
Samples .deleteOccurrence (client , occName );
152
150
153
151
try {
154
152
Samples .getOccurrence (client , occName );
155
- //getOccurrence should fail, because occurrence was deleted
153
+ // getOccurrence should fail, because occurrence was deleted
156
154
fail ("failed to delete occurrence" );
157
- } catch (Exception e ) {
158
- //test passes
155
+ } catch (NotFoundException e ) {
156
+ // test passes
159
157
}
160
158
}
161
159
@@ -175,7 +173,7 @@ public void testUpdateOccurrence() throws Exception {
175
173
Occurrence got = Samples .getOccurrence (client , o .getName ());
176
174
assertEquals (typeId , got .getVulnerability ().getType ());
177
175
178
- //clean up
176
+ // clean up
179
177
Samples .deleteOccurrence (client , o .getName ());
180
178
}
181
179
@@ -193,7 +191,7 @@ public void testOccurrencesForImage() throws Exception {
193
191
assertEquals (1 , newCount );
194
192
assertEquals (0 , origCount );
195
193
196
- //clean up
194
+ // clean up
197
195
Samples .deleteOccurrence (client , o .getName ());
198
196
}
199
197
@@ -211,7 +209,7 @@ public void testOccurrencesForNote() throws Exception {
211
209
assertEquals (0 , origCount );
212
210
assertEquals (1 , newCount );
213
211
214
- //clean up
212
+ // clean up
215
213
Samples .deleteOccurrence (client , o .getName ());
216
214
}
217
215
0 commit comments