Search in sources :

Example 1 with ListAssetsPagedResponse

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

Example 2 with ListAssetsPagedResponse

use of com.google.cloud.asset.v1.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);
        }
    }
}
Also used : ListAssetsRequest(com.google.cloud.asset.v1.ListAssetsRequest) ProjectName(com.google.cloud.asset.v1.ProjectName) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ListAssetsPagedResponse(com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse)

Example 3 with ListAssetsPagedResponse

use of com.google.cloud.asset.v1.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()));
}
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)

Example 4 with ListAssetsPagedResponse

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

Aggregations

ListAssetsPagedResponse (com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse)3 AbstractMessage (com.google.protobuf.AbstractMessage)3 Test (org.junit.Test)3 ResourceName (com.google.api.resourcenames.ResourceName)1 AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)1 ListAssetsRequest (com.google.cloud.asset.v1.ListAssetsRequest)1 ProjectName (com.google.cloud.asset.v1.ProjectName)1 ListAssetsPagedResponse (com.google.cloud.asset.v1p5beta1.AssetServiceClient.ListAssetsPagedResponse)1