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,14 @@ private static void requireEnvVar(String varName) {
111
123
@ BeforeClass
112
124
public static void beforeAll () throws IOException {
113
125
requireEnvVar ("GOOGLE_CLOUD_PROJECT" );
126
+ requireEnvVar ("MA_FOLDER_ID" );
127
+ requireEnvVar ("MA_ORG_ID" );
128
+
129
+ projectFloorSettingName =
130
+ FloorSettingName .ofProjectLocationName (PROJECT_ID , "global" ).toString ();
131
+ folderFloorSettingName = FloorSettingName .ofFolderLocationName (FOLDER_ID , "global" ).toString ();
132
+ organizationFloorSettingName =
133
+ FloorSettingName .ofOrganizationLocationName (ORGANIZATION_ID , "global" ).toString ();
114
134
115
135
TEST_TEMPLATE_ID = randomId ();
116
136
TEST_RAI_TEMPLATE_ID = randomId ();
@@ -147,6 +167,10 @@ private static String randomId() {
147
167
@ AfterClass
148
168
public static void afterAll () throws IOException {
149
169
requireEnvVar ("GOOGLE_CLOUD_PROJECT" );
170
+ requireEnvVar ("MA_FOLDER_ID" );
171
+ requireEnvVar ("MA_ORG_ID" );
172
+
173
+ resetFloorSettings ();
150
174
151
175
// Delete templates after running tests.
152
176
templateToDelete = new String [] {
@@ -380,6 +404,67 @@ private static void deleteTemplate(String templateId) throws IOException {
380
404
}
381
405
}
382
406
407
+ private static void resetFloorSettings () throws IOException {
408
+ floorSettingNames = new String [] {
409
+ projectFloorSettingName , folderFloorSettingName , organizationFloorSettingName
410
+ };
411
+
412
+
413
+ try (ModelArmorClient client = ModelArmorClient .create ()) {
414
+ for (String name : floorSettingNames ) {
415
+ FloorSetting floorSetting = FloorSetting .newBuilder ()
416
+ .setName (name )
417
+ .setFilterConfig (FilterConfig .newBuilder ().build ())
418
+ .setEnableFloorSettingEnforcement (false )
419
+ .build ();
420
+
421
+ UpdateFloorSettingRequest request = UpdateFloorSettingRequest .newBuilder ()
422
+ .setFloorSetting (floorSetting )
423
+ .build ();
424
+
425
+ client .updateFloorSetting (request );
426
+ }
427
+ }
428
+ }
429
+
430
+ // Tests for Folder setting snippets.
431
+ @ Test
432
+ public void testGetOrganizationFloorSetting () throws IOException {
433
+ GetOrganizationFloorSetting .getOrganizationFloorSetting (ORGANIZATION_ID );
434
+ assertThat (stdOut .toString ()).contains ("Fetched floor setting for organization:" );
435
+ }
436
+
437
+ @ Test
438
+ public void testGetFolderFloorSetting () throws IOException {
439
+ GetFolderFloorSetting .getFolderFloorSetting (FOLDER_ID );
440
+ assertThat (stdOut .toString ()).contains ("Fetched floor setting for folder:" );
441
+ }
442
+
443
+ @ Test
444
+ public void testGetProjectFloorSetting () throws IOException {
445
+ GetProjectFloorSetting .getProjectFloorSetting (PROJECT_ID );
446
+ assertThat (stdOut .toString ()).contains ("Fetched floor setting for project:" );
447
+ }
448
+
449
+ @ Test
450
+ public void testUpdateOrganizationFloorSetting () throws IOException {
451
+ UpdateOrganizationsFloorSetting .updateOrganizationFloorSetting (ORGANIZATION_ID );
452
+ assertThat (stdOut .toString ()).contains ("Updated floor setting for organization:" );
453
+ }
454
+
455
+ @ Test
456
+ public void testUpdateFolderFloorSetting () throws IOException {
457
+ UpdateFolderFloorSetting .updateFolderFloorSetting (FOLDER_ID );
458
+ assertThat (stdOut .toString ()).contains ("Updated floor setting for folder:" );
459
+ }
460
+
461
+
462
+ @ Test
463
+ public void testUpdateProjectFloorSetting () throws IOException {
464
+ UpdateProjectFloorSetting .updateProjectFloorSetting (PROJECT_ID );
465
+ assertThat (stdOut .toString ()).contains ("Updated floor setting for project:" );
466
+ }
467
+
383
468
// Tests for Template CRUD snippets.
384
469
@ Test
385
470
public void testUpdateModelArmorTemplate () throws IOException {
0 commit comments