From 94d9c5ef0ee7a9069db372f13b9014a39634a1e2 Mon Sep 17 00:00:00 2001 From: David del Real Sifuentes Date: Tue, 20 Oct 2026 23:39:10 +0000 Subject: [PATCH 1/2] fix(asset): update BatchGetAssetsHistory sample and IT fixture - Set ContentType.RESOURCE in BatchGetAssetsHistoryExample - Create and clean up a temporary GCS bucket in QuickStartIT for testBatchGetAssetsHistory --- .../asset/BatchGetAssetsHistoryExample.java | 2 +- .../java/com/example/asset/QuickStartIT.java | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/asset/src/main/java/com/example/asset/BatchGetAssetsHistoryExample.java b/asset/src/main/java/com/example/asset/BatchGetAssetsHistoryExample.java index e244bfe767c..48a3c552deb 100644 --- a/asset/src/main/java/com/example/asset/BatchGetAssetsHistoryExample.java +++ b/asset/src/main/java/com/example/asset/BatchGetAssetsHistoryExample.java @@ -40,7 +40,7 @@ public static void main(String... args) throws Exception { String[] assetNames = args[0].split(","); try (AssetServiceClient client = AssetServiceClient.create()) { ProjectName parent = ProjectName.of(projectId); - ContentType contentType = ContentType.CONTENT_TYPE_UNSPECIFIED; + ContentType contentType = ContentType.RESOURCE; TimeWindow readTimeWindow = TimeWindow.newBuilder().build(); BatchGetAssetsHistoryRequest request = BatchGetAssetsHistoryRequest.newBuilder() diff --git a/asset/src/test/java/com/example/asset/QuickStartIT.java b/asset/src/test/java/com/example/asset/QuickStartIT.java index 8616d0e0009..00d5d566d21 100644 --- a/asset/src/test/java/com/example/asset/QuickStartIT.java +++ b/asset/src/test/java/com/example/asset/QuickStartIT.java @@ -27,6 +27,7 @@ import com.google.cloud.bigquery.DatasetInfo; import com.google.cloud.bigquery.testing.RemoteBigQueryHelper; import com.google.cloud.storage.BlobInfo; +import com.google.cloud.storage.BucketInfo; import com.google.cloud.storage.Storage; import com.google.cloud.storage.Storage.BlobListOption; import com.google.cloud.storage.StorageOptions; @@ -36,7 +37,9 @@ import java.util.UUID; import java.util.concurrent.TimeUnit; import org.junit.After; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.rules.Timeout; @@ -53,6 +56,8 @@ public class QuickStartIT { private static final String bucketName = "java-docs-samples-testing"; private static final String[] assetTypes = { "compute.googleapis.com/Network" }; + private static final String testBucket = "java-docs-test-bucket-" + UUID.randomUUID().toString(); + private ByteArrayOutputStream bout; private PrintStream out; private PrintStream originalPrintStream; @@ -134,7 +139,7 @@ public void testExportAssetBigqueryExample() throws Exception { @Test public void testBatchGetAssetsHistory() throws Exception { - String bucketAssetName = String.format("//storage.googleapis.com/%s", bucketName); + String bucketAssetName = String.format("//storage.googleapis.com/%s", testBucket); BatchGetAssetsHistoryExample.main(bucketAssetName); String got = bout.toString(); if (!got.isEmpty()) { @@ -142,6 +147,18 @@ public void testBatchGetAssetsHistory() throws Exception { } } + @BeforeClass + public static void createTestBucket() { + Storage storage = StorageOptions.getDefaultInstance().getService(); + storage.create(BucketInfo.of(testBucket)); + } + + @AfterClass + public static void deleteTestBucket() { + Storage storage = StorageOptions.getDefaultInstance().getService(); + storage.delete(testBucket); + } + protected String getDataset(String datasetName) throws BigQueryException { bigquery.create(DatasetInfo.newBuilder(datasetName).build()); return String.format( From d5e0e0c88828f602cac48e4e35228c22a4d45a8c Mon Sep 17 00:00:00 2001 From: David del Real Sifuentes Date: Wed, 21 Oct 2026 18:01:06 +0000 Subject: [PATCH 2/2] Adressed comments on PR. --- .../java/com/example/asset/BatchGetAssetsHistoryExample.java | 2 -- asset/src/test/java/com/example/asset/QuickStartIT.java | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/asset/src/main/java/com/example/asset/BatchGetAssetsHistoryExample.java b/asset/src/main/java/com/example/asset/BatchGetAssetsHistoryExample.java index 48a3c552deb..18471594f46 100644 --- a/asset/src/main/java/com/example/asset/BatchGetAssetsHistoryExample.java +++ b/asset/src/main/java/com/example/asset/BatchGetAssetsHistoryExample.java @@ -33,8 +33,6 @@ public class BatchGetAssetsHistoryExample { // Use the default project Id. private static final String projectId = ServiceOptions.getDefaultProjectId(); - // Export assets for a project. - // @param args path where the results will be exported to. public static void main(String... args) throws Exception { // Asset names, e.g.: "//storage.googleapis.com/[BUCKET_NAME]" String[] assetNames = args[0].split(","); diff --git a/asset/src/test/java/com/example/asset/QuickStartIT.java b/asset/src/test/java/com/example/asset/QuickStartIT.java index 00d5d566d21..1a9a1dad98c 100644 --- a/asset/src/test/java/com/example/asset/QuickStartIT.java +++ b/asset/src/test/java/com/example/asset/QuickStartIT.java @@ -142,9 +142,7 @@ public void testBatchGetAssetsHistory() throws Exception { String bucketAssetName = String.format("//storage.googleapis.com/%s", testBucket); BatchGetAssetsHistoryExample.main(bucketAssetName); String got = bout.toString(); - if (!got.isEmpty()) { - assertThat(got).contains(bucketAssetName); - } + assertThat(got).contains(bucketAssetName); } @BeforeClass