2626import java .util .concurrent .TimeUnit ;
2727import java .util .regex .Matcher ;
2828import java .util .regex .Pattern ;
29-
29+ import com .google .api .gax .rpc .InvalidArgumentException ;
30+ import com .google .cloud .securitycenter .v1 .Asset ;
31+ import com .google .cloud .securitycenter .v1 .ListAssetsRequest ;
32+ import com .google .cloud .securitycenter .v1 .SecurityCenterClient ;
33+ import com .google .cloud .securitycenter .v2 .OrganizationName ;
34+ import com .google .cloud .securitycenter .v2 .SecurityMarks ;
35+ import com .google .cloud .testing .junit4 .MultipleAttemptsRule ;
3036import org .junit .After ;
3137import org .junit .AfterClass ;
3238import org .junit .Before ;
3541import org .junit .Test ;
3642import org .junit .runner .RunWith ;
3743import org .junit .runners .JUnit4 ;
38-
39- import com .google .api .gax .rpc .InvalidArgumentException ;
40- import com .google .cloud .securitycenter .v1 .Asset ;
41- import com .google .cloud .securitycenter .v1 .ListAssetsRequest ;
42- import com .google .cloud .securitycenter .v1 .SecurityCenterClient ;
43- import com .google .cloud .securitycenter .v2 .OrganizationName ;
44- import com .google .cloud .securitycenter .v2 .SecurityMarks ;
45- import com .google .cloud .testing .junit4 .MultipleAttemptsRule ;
46-
4744import vtwo .assets .AddDeleteSecurityMarks ;
4845import vtwo .assets .AddSecurityMarksToAssets ;
4946import vtwo .assets .DeleteAssetsSecurityMarks ;
@@ -57,7 +54,8 @@ public class AssetSecurityMarksIT {
5754 private static ByteArrayOutputStream stdOut ;
5855
5956 @ Rule
60- public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule (3 , 120000 ); // 2 minutes
57+ public final MultipleAttemptsRule multipleAttemptsRule =
58+ new MultipleAttemptsRule (3 , 120000 ); // 2 minutes
6159
6260 // Check if the required environment variables are set.
6361 public static void requireEnvVar (String envVarName ) {
@@ -74,9 +72,9 @@ private static String extractAssetId(String assetPath) {
7472 }
7573 return assetPath ;
7674 }
77-
78- @ SuppressWarnings ("deprecation" )
79- @ BeforeClass
75+
76+ @ SuppressWarnings ("deprecation" )
77+ @ BeforeClass
8078 public static void setUp () throws IOException , InterruptedException {
8179 final PrintStream out = System .out ;
8280 stdOut = new ByteArrayOutputStream ();
@@ -86,20 +84,18 @@ public static void setUp() throws IOException, InterruptedException {
8684
8785 // Fetch a valid asset ID dynamically
8886 try (SecurityCenterClient client = SecurityCenterClient .create ()) {
89- OrganizationName orgName = OrganizationName .of (ORGANIZATION_ID );
90- ListAssetsRequest request = ListAssetsRequest .newBuilder ()
91- .setParent (orgName .toString ())
92- .setPageSize (1 )
93- .build ();
94-
95- Asset asset = client .listAssets (request ).iterateAll ().iterator ().next ().getAsset ();
96- assetName = asset .getName (); // Get the full resource name for the asset
97- assetId = extractAssetId (assetName );
87+ OrganizationName orgName = OrganizationName .of (ORGANIZATION_ID );
88+ ListAssetsRequest request =
89+ ListAssetsRequest .newBuilder ().setParent (orgName .toString ()).setPageSize (1 ).build ();
90+
91+ Asset asset = client .listAssets (request ).iterateAll ().iterator ().next ().getAsset ();
92+ assetName = asset .getName (); // Get the full resource name for the asset
93+ assetId = extractAssetId (assetName );
9894 } catch (InvalidArgumentException e ) {
99- System .err .println ("Error retrieving asset ID: " + e .getMessage ());
100- throw e ;
95+ System .err .println ("Error retrieving asset ID: " + e .getMessage ());
96+ throw e ;
10197 }
102-
98+
10399 stdOut = null ;
104100 System .setOut (out );
105101 TimeUnit .MINUTES .sleep (1 );
@@ -124,26 +120,26 @@ public static void cleanUp() {
124120
125121 @ Test
126122 public void testAddSecurityMarksToAsset () throws IOException {
127- SecurityMarks response = AddSecurityMarksToAssets . addToAsset (
128- ORGANIZATION_ID , LOCATION , assetId );
123+ SecurityMarks response =
124+ AddSecurityMarksToAssets . addToAsset ( ORGANIZATION_ID , LOCATION , assetId );
129125
130126 assertTrue (response .getMarksOrThrow ("key_a" ).contains ("value_a" ));
131127 assertTrue (response .getMarksOrThrow ("key_b" ).contains ("value_b" ));
132128 }
133129
134130 @ Test
135131 public void testDeleteSecurityMarksOnAsset () throws IOException {
136- SecurityMarks response = DeleteAssetsSecurityMarks . deleteSecurityMarks (
137- ORGANIZATION_ID , LOCATION , assetId );
132+ SecurityMarks response =
133+ DeleteAssetsSecurityMarks . deleteSecurityMarks ( ORGANIZATION_ID , LOCATION , assetId );
138134
139135 assertFalse (response .containsMarks ("key_a" ));
140136 assertFalse (response .containsMarks ("key_b" ));
141137 }
142138
143139 @ Test
144140 public void testAddAndDeleteSecurityMarks () throws IOException {
145- SecurityMarks response = AddDeleteSecurityMarks . addDeleteSecurityMarks (
146- ORGANIZATION_ID , LOCATION , assetId );
141+ SecurityMarks response =
142+ AddDeleteSecurityMarks . addDeleteSecurityMarks ( ORGANIZATION_ID , LOCATION , assetId );
147143
148144 // Assert update for key_a
149145 assertTrue (response .getMarksOrThrow ("key_a" ).contains ("new_value_for_a" ));
@@ -152,4 +148,3 @@ public void testAddAndDeleteSecurityMarks() throws IOException {
152148 assertFalse (response .getMarksMap ().containsKey ("key_b" ));
153149 }
154150}
155-
0 commit comments