use of com.google.cloud.asset.v1p5beta1.AssetServiceClient.ListAssetsPagedResponse 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.v1p5beta1.AssetServiceClient.ListAssetsPagedResponse in project java-asset by googleapis.
the class ListAssetsExample method listAssets.
public static void listAssets(String projectId, String[] assetTypes, ContentType contentType) throws IOException, IllegalArgumentException {
try (AssetServiceClient client = AssetServiceClient.create()) {
ProjectName parent = ProjectName.of(projectId);
// Build initial ListAssetsRequest without setting page token.
ListAssetsRequest request = ListAssetsRequest.newBuilder().setParent(parent.toString()).addAllAssetTypes(Arrays.asList(assetTypes)).setContentType(contentType).build();
// Repeatedly call ListAssets until page token is empty.
ListAssetsPagedResponse response = client.listAssets(request);
System.out.println(response);
while (!response.getNextPageToken().isEmpty()) {
request = request.toBuilder().setPageToken(response.getNextPageToken()).build();
response = client.listAssets(request);
System.out.println(response);
}
}
}
use of com.google.cloud.asset.v1p5beta1.AssetServiceClient.ListAssetsPagedResponse 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()));
}
use of com.google.cloud.asset.v1p5beta1.AssetServiceClient.ListAssetsPagedResponse in project java-asset 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);
ListAssetsRequest request = ListAssetsRequest.newBuilder().setParent("parent-995424086").setReadTime(Timestamp.newBuilder().build()).addAllAssetTypes(new ArrayList<String>()).setContentType(ContentType.forNumber(0)).setPageSize(883849137).setPageToken("pageToken873572522").build();
ListAssetsPagedResponse pagedListResponse = client.listAssets(request);
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(request.getParent(), actualRequest.getParent());
Assert.assertEquals(request.getReadTime(), actualRequest.getReadTime());
Assert.assertEquals(request.getAssetTypesList(), actualRequest.getAssetTypesList());
Assert.assertEquals(request.getContentType(), actualRequest.getContentType());
Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize());
Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations