19
19
import static com .google .common .truth .Truth .assertThat ;
20
20
import static com .google .common .truth .Truth .assertWithMessage ;
21
21
22
+ import com .google .api .gax .rpc .AlreadyExistsException ;
22
23
import com .google .cloud .pubsub .v1 .TopicAdminClient ;
23
24
import com .google .cloud .securitycenter .v2 .NotificationConfig ;
24
25
import com .google .cloud .testing .junit4 .MultipleAttemptsRule ;
26
+ import com .google .common .collect .ImmutableList ;
25
27
import com .google .pubsub .v1 .ProjectTopicName ;
26
28
import java .io .ByteArrayOutputStream ;
27
29
import java .io .IOException ;
28
30
import java .io .PrintStream ;
29
- import java .util .UUID ;
30
31
import org .junit .After ;
31
32
import org .junit .AfterClass ;
32
33
import org .junit .Before ;
@@ -49,8 +50,8 @@ public class NotificationIT {
49
50
private static final String PROJECT_ID = System .getenv ("SCC_PROJECT_ID" );
50
51
private static final String LOCATION = "global" ;
51
52
private static final String NOTIFICATION_RULE_CREATE =
52
- "random-notification-id-" + UUID . randomUUID () ;
53
- private static final String NOTIFICATION_TOPIC = "test-topic-" + UUID . randomUUID () ;
53
+ "random-notification-id" ;
54
+ private static final String NOTIFICATION_TOPIC = "test-topic-for-testing" ;
54
55
private static final int MAX_ATTEMPT_COUNT = 3 ;
55
56
private static final int INITIAL_BACKOFF_MILLIS = 120000 ; // 2 minutes
56
57
private static ByteArrayOutputStream stdOut ;
@@ -76,8 +77,12 @@ public static void setUp() throws IOException, InterruptedException {
76
77
requireEnvVar ("GOOGLE_APPLICATION_CREDENTIALS" );
77
78
requireEnvVar ("SCC_PROJECT_ID" );
78
79
79
- // Create pubsub topic.
80
- createPubSubTopic (PROJECT_ID , NOTIFICATION_TOPIC );
80
+ try {
81
+ // Create pubsub topic.
82
+ createPubSubTopic (PROJECT_ID , NOTIFICATION_TOPIC );
83
+ } catch (AlreadyExistsException ex ) {
84
+ System .out .printf ("%s has already been created." , NOTIFICATION_TOPIC );
85
+ }
81
86
82
87
// Create notification rules.
83
88
NotificationConfig result = CreateNotification .createNotificationConfig (PROJECT_ID , LOCATION ,
@@ -94,11 +99,13 @@ public static void cleanUp() throws IOException {
94
99
stdOut = new ByteArrayOutputStream ();
95
100
System .setOut (new PrintStream (stdOut ));
96
101
97
- DeleteNotification . deleteNotificationConfig ( PROJECT_ID , LOCATION , NOTIFICATION_RULE_CREATE );
98
- assertThat ( stdOut . toString ()). contains (
99
- "Deleted Notification config: " + NOTIFICATION_RULE_CREATE );
102
+ ImmutableList < NotificationConfig > notificationConfigs =
103
+ ListNotification . listNotificationConfigs (
104
+ PROJECT_ID , LOCATION );
100
105
101
- deletePubSubTopic (PROJECT_ID , NOTIFICATION_TOPIC );
106
+ for (NotificationConfig notificationConfig : notificationConfigs ) {
107
+ DeleteNotification .deleteNotificationConfig (notificationConfig .getName ());
108
+ }
102
109
103
110
stdOut = null ;
104
111
System .setOut (out );
0 commit comments