Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ 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(",");
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()
Expand Down
23 changes: 19 additions & 4 deletions asset/src/test/java/com/example/asset/QuickStartIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -134,12 +139,22 @@ 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()) {
assertThat(got).contains(bucketAssetName);
}
assertThat(got).contains(bucketAssetName);
}

@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 {
Expand Down
Loading