diff --git a/polaris-core/src/test/java/org/apache/polaris/service/storage/gcp/GcpCredentialsStorageIntegrationTest.java b/polaris-core/src/test/java/org/apache/polaris/service/storage/gcp/GcpCredentialsStorageIntegrationTest.java index f1a7afc636..c4f026d86a 100644 --- a/polaris-core/src/test/java/org/apache/polaris/service/storage/gcp/GcpCredentialsStorageIntegrationTest.java +++ b/polaris-core/src/test/java/org/apache/polaris/service/storage/gcp/GcpCredentialsStorageIntegrationTest.java @@ -37,6 +37,7 @@ import com.google.cloud.storage.StorageException; import com.google.cloud.storage.StorageOptions; import java.io.IOException; +import java.io.InputStream; import java.util.Arrays; import java.util.Date; import java.util.HashSet; @@ -177,6 +178,12 @@ private AccessConfig subscopedCredsForOperations( Optional.of(REFRESH_ENDPOINT)); } + private JsonNode readResource(ObjectMapper mapper, String name) throws IOException { + try (InputStream in = GcpCredentialsStorageIntegrationTest.class.getResourceAsStream(name)) { + return mapper.readTree(in); + } + } + @Test public void testGenerateAccessBoundary() throws IOException { CredentialAccessBoundary credentialAccessBoundary = @@ -185,10 +192,7 @@ public void testGenerateAccessBoundary() throws IOException { assertThat(credentialAccessBoundary).isNotNull(); ObjectMapper mapper = new ObjectMapper(); JsonNode parsedRules = mapper.convertValue(credentialAccessBoundary, JsonNode.class); - JsonNode refRules = - mapper.readTree( - GcpCredentialsStorageIntegrationTest.class.getResource( - "gcp-testGenerateAccessBoundary.json")); + JsonNode refRules = readResource(mapper, "gcp-testGenerateAccessBoundary.json"); assertThat(parsedRules) .usingRecursiveComparison( RecursiveComparisonConfiguration.builder() @@ -211,9 +215,7 @@ public void testGenerateAccessBoundaryWithMultipleBuckets() throws IOException { ObjectMapper mapper = new ObjectMapper(); JsonNode parsedRules = mapper.convertValue(credentialAccessBoundary, JsonNode.class); JsonNode refRules = - mapper.readTree( - GcpCredentialsStorageIntegrationTest.class.getResource( - "gcp-testGenerateAccessBoundaryWithMultipleBuckets.json")); + readResource(mapper, "gcp-testGenerateAccessBoundaryWithMultipleBuckets.json"); assertThat(parsedRules) .usingRecursiveComparison( RecursiveComparisonConfiguration.builder() @@ -232,10 +234,7 @@ public void testGenerateAccessBoundaryWithoutList() throws IOException { assertThat(credentialAccessBoundary).isNotNull(); ObjectMapper mapper = new ObjectMapper(); JsonNode parsedRules = mapper.convertValue(credentialAccessBoundary, JsonNode.class); - JsonNode refRules = - mapper.readTree( - GcpCredentialsStorageIntegrationTest.class.getResource( - "gcp-testGenerateAccessBoundaryWithoutList.json")); + JsonNode refRules = readResource(mapper, "gcp-testGenerateAccessBoundaryWithoutList.json"); assertThat(parsedRules) .usingRecursiveComparison( RecursiveComparisonConfiguration.builder() @@ -254,10 +253,7 @@ public void testGenerateAccessBoundaryWithoutWrites() throws IOException { assertThat(credentialAccessBoundary).isNotNull(); ObjectMapper mapper = new ObjectMapper(); JsonNode parsedRules = mapper.convertValue(credentialAccessBoundary, JsonNode.class); - JsonNode refRules = - mapper.readTree( - GcpCredentialsStorageIntegrationTest.class.getResource( - "gcp-testGenerateAccessBoundaryWithoutWrites.json")); + JsonNode refRules = readResource(mapper, "gcp-testGenerateAccessBoundaryWithoutWrites.json"); assertThat(parsedRules) .usingRecursiveComparison( RecursiveComparisonConfiguration.builder()