use of com.google.cloud.asset.v1.ListAssetsResponse in project gapic-generator-java by googleapis.
the class AsyncListAssetsPaged method asyncListAssetsPaged.
public static void asyncListAssetsPaged() throws Exception {
// It may require modifications to work in your environment.
try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
ListAssetsRequest request = ListAssetsRequest.newBuilder().setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()).setReadTime(Timestamp.newBuilder().build()).addAllAssetTypes(new ArrayList<String>()).setContentType(ContentType.forNumber(0)).setPageSize(883849137).setPageToken("pageToken873572522").addAllRelationshipTypes(new ArrayList<String>()).build();
while (true) {
ListAssetsResponse response = assetServiceClient.listAssetsCallable().call(request);
for (Asset element : response.getResponsesList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
}
use of com.google.cloud.asset.v1.ListAssetsResponse in project gapic-generator-java by googleapis.
the class AssetServiceClientTest method listAssetsTest2.
@Test
public void listAssetsTest2() throws Exception {
Asset responsesElement = Asset.newBuilder().build();
ListAssetsResponse expectedResponse = ListAssetsResponse.newBuilder().setNextPageToken("").addAllAssets(Arrays.asList(responsesElement)).build();
mockAssetService.addResponse(expectedResponse);
String parent = "parent-995424086";
ListAssetsPagedResponse pagedListResponse = client.listAssets(parent);
List<Asset> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getAssetsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockAssetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListAssetsRequest actualRequest = ((ListAssetsRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.asset.v1.ListAssetsResponse in project gapic-generator-java by googleapis.
the class AssetServiceClientTest method listAssetsTest.
@Test
public void listAssetsTest() throws Exception {
Asset responsesElement = Asset.newBuilder().build();
ListAssetsResponse expectedResponse = ListAssetsResponse.newBuilder().setNextPageToken("").addAllAssets(Arrays.asList(responsesElement)).build();
mockAssetService.addResponse(expectedResponse);
ResourceName parent = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]");
ListAssetsPagedResponse pagedListResponse = client.listAssets(parent);
List<Asset> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getAssetsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockAssetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListAssetsRequest actualRequest = ((ListAssetsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations