28
28
import com .google .cloud .modelarmor .v1 .FilterConfig ;
29
29
import com .google .cloud .modelarmor .v1 .FilterMatchState ;
30
30
import com .google .cloud .modelarmor .v1 .FilterResult ;
31
+ import com .google .cloud .modelarmor .v1 .FloorSetting ;
32
+ import com .google .cloud .modelarmor .v1 .FloorSettingName ;
31
33
import com .google .cloud .modelarmor .v1 .LocationName ;
32
34
import com .google .cloud .modelarmor .v1 .MaliciousUriFilterSettings ;
33
35
import com .google .cloud .modelarmor .v1 .MaliciousUriFilterSettings .MaliciousUriFilterEnforcement ;
46
48
import com .google .cloud .modelarmor .v1 .SdpFinding ;
47
49
import com .google .cloud .modelarmor .v1 .Template ;
48
50
import com .google .cloud .modelarmor .v1 .TemplateName ;
51
+ import com .google .cloud .modelarmor .v1 .UpdateFloorSettingRequest ;
49
52
import com .google .privacy .dlp .v2 .CreateDeidentifyTemplateRequest ;
50
53
import com .google .privacy .dlp .v2 .CreateInspectTemplateRequest ;
51
54
import com .google .privacy .dlp .v2 .DeidentifyConfig ;
72
75
import org .junit .AfterClass ;
73
76
import org .junit .Before ;
74
77
import org .junit .BeforeClass ;
78
+ import org .junit .Ignore ;
75
79
import org .junit .Test ;
76
80
import org .junit .runner .RunWith ;
77
81
import org .junit .runners .JUnit4 ;
80
84
public class SnippetsIT {
81
85
82
86
private static final String PROJECT_ID = System .getenv ("GOOGLE_CLOUD_PROJECT" );
87
+ private static final String FOLDER_ID = System .getenv ()
88
+ .getOrDefault ("MA_FOLDER_ID" , "global" );
89
+ private static final String ORGANIZATION_ID = System .getenv ()
90
+ .getOrDefault ("MA_ORG_ID" , "global" );
83
91
private static final String LOCATION_ID = System .getenv ()
84
92
.getOrDefault ("GOOGLE_CLOUD_PROJECT_LOCATION" , "us-central1" );
85
93
private static final String MA_ENDPOINT = String .format ("modelarmor.%s.rep.googleapis.com:443" ,
@@ -99,7 +107,11 @@ public class SnippetsIT {
99
107
private static String TEST_DEIDENTIFY_TEMPLATE_NAME ;
100
108
private ByteArrayOutputStream stdOut ;
101
109
private PrintStream originalOut ;
110
+ private static String [] floorSettingNames ;
102
111
private static String [] templateToDelete ;
112
+ private static String projectFloorSettingName ;
113
+ private static String folderFloorSettingName ;
114
+ private static String organizationFloorSettingName ;
103
115
104
116
// Check if the required environment variables are set.
105
117
private static void requireEnvVar (String varName ) {
@@ -111,6 +123,17 @@ private static void requireEnvVar(String varName) {
111
123
@ BeforeClass
112
124
public static void beforeAll () throws IOException {
113
125
requireEnvVar ("GOOGLE_CLOUD_PROJECT" );
126
+
127
+ // TODO: Uncomment below once floor setting API issues are resolved.
128
+ // See buganizer ticket b/424365799 for status.
129
+ // requireEnvVar("MA_FOLDER_ID");
130
+ // requireEnvVar("MA_ORG_ID");
131
+
132
+ projectFloorSettingName =
133
+ FloorSettingName .ofProjectLocationName (PROJECT_ID , "global" ).toString ();
134
+ folderFloorSettingName = FloorSettingName .ofFolderLocationName (FOLDER_ID , "global" ).toString ();
135
+ organizationFloorSettingName =
136
+ FloorSettingName .ofOrganizationLocationName (ORGANIZATION_ID , "global" ).toString ();
114
137
115
138
TEST_TEMPLATE_ID = randomId ();
116
139
TEST_RAI_TEMPLATE_ID = randomId ();
@@ -147,6 +170,12 @@ private static String randomId() {
147
170
@ AfterClass
148
171
public static void afterAll () throws IOException {
149
172
requireEnvVar ("GOOGLE_CLOUD_PROJECT" );
173
+
174
+ // TODO: Uncomment below once floor setting API issues are resolved.
175
+ // See buganizer ticket b/424365799 for status.
176
+ // requireEnvVar("MA_FOLDER_ID");
177
+ // requireEnvVar("MA_ORG_ID");
178
+ // resetFloorSettings();
150
179
151
180
// Delete templates after running tests.
152
181
templateToDelete = new String [] {
@@ -380,6 +409,77 @@ private static void deleteTemplate(String templateId) throws IOException {
380
409
}
381
410
}
382
411
412
+ private static void resetFloorSettings () throws IOException {
413
+ floorSettingNames = new String [] {
414
+ projectFloorSettingName , folderFloorSettingName , organizationFloorSettingName
415
+ };
416
+
417
+
418
+ try (ModelArmorClient client = ModelArmorClient .create ()) {
419
+ for (String name : floorSettingNames ) {
420
+ FloorSetting floorSetting = FloorSetting .newBuilder ()
421
+ .setName (name )
422
+ .setFilterConfig (FilterConfig .newBuilder ().build ())
423
+ .setEnableFloorSettingEnforcement (false )
424
+ .build ();
425
+
426
+ UpdateFloorSettingRequest request = UpdateFloorSettingRequest .newBuilder ()
427
+ .setFloorSetting (floorSetting )
428
+ .build ();
429
+
430
+ client .updateFloorSetting (request );
431
+ }
432
+ }
433
+ }
434
+
435
+ // Tests for Folder setting snippets.
436
+
437
+ // TODO: Remove ignore for below tests once floor setting API issues are resolved.
438
+ // See buganizer ticket b/424365799 for status.
439
+
440
+ @ Ignore
441
+ @ Test
442
+ public void testGetOrganizationFloorSetting () throws IOException {
443
+ GetOrganizationFloorSetting .getOrganizationFloorSetting (ORGANIZATION_ID );
444
+ assertThat (stdOut .toString ()).contains ("Fetched floor setting for organization:" );
445
+ }
446
+
447
+ @ Ignore
448
+ @ Test
449
+ public void testGetFolderFloorSetting () throws IOException {
450
+ GetFolderFloorSetting .getFolderFloorSetting (FOLDER_ID );
451
+ assertThat (stdOut .toString ()).contains ("Fetched floor setting for folder:" );
452
+ }
453
+
454
+ @ Ignore
455
+ @ Test
456
+ public void testGetProjectFloorSetting () throws IOException {
457
+ GetProjectFloorSetting .getProjectFloorSetting (PROJECT_ID );
458
+ assertThat (stdOut .toString ()).contains ("Fetched floor setting for project:" );
459
+ }
460
+
461
+ @ Ignore
462
+ @ Test
463
+ public void testUpdateOrganizationFloorSetting () throws IOException {
464
+ UpdateOrganizationsFloorSetting .updateOrganizationFloorSetting (ORGANIZATION_ID );
465
+ assertThat (stdOut .toString ()).contains ("Updated floor setting for organization:" );
466
+ }
467
+
468
+ @ Ignore
469
+ @ Test
470
+ public void testUpdateFolderFloorSetting () throws IOException {
471
+ UpdateFolderFloorSetting .updateFolderFloorSetting (FOLDER_ID );
472
+ assertThat (stdOut .toString ()).contains ("Updated floor setting for folder:" );
473
+ }
474
+
475
+
476
+ @ Ignore
477
+ @ Test
478
+ public void testUpdateProjectFloorSetting () throws IOException {
479
+ UpdateProjectFloorSetting .updateProjectFloorSetting (PROJECT_ID );
480
+ assertThat (stdOut .toString ()).contains ("Updated floor setting for project:" );
481
+ }
482
+
383
483
// Tests for Template CRUD snippets.
384
484
@ Test
385
485
public void testUpdateModelArmorTemplate () throws IOException {
0 commit comments