Search in sources :

Example 1 with ListAssetsResponse

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;
            }
        }
    }
}
Also used : ListAssetsRequest(com.google.cloud.asset.v1.ListAssetsRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ArrayList(java.util.ArrayList) Asset(com.google.cloud.asset.v1.Asset) ListAssetsResponse(com.google.cloud.asset.v1.ListAssetsResponse)

Example 2 with ListAssetsResponse

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListAssetsPagedResponse(com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse) Test(org.junit.Test)

Example 3 with ListAssetsResponse

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ResourceName(com.google.api.resourcenames.ResourceName) ListAssetsPagedResponse(com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse) Test(org.junit.Test)

Aggregations

ListAssetsPagedResponse (com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Test (org.junit.Test)2 ResourceName (com.google.api.resourcenames.ResourceName)1 Asset (com.google.cloud.asset.v1.Asset)1 AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)1 ListAssetsRequest (com.google.cloud.asset.v1.ListAssetsRequest)1 ListAssetsResponse (com.google.cloud.asset.v1.ListAssetsResponse)1 ArrayList (java.util.ArrayList)1