Search in sources :

Example 1 with SearchAllIamPoliciesResponse

use of com.google.cloud.asset.v1.SearchAllIamPoliciesResponse in project gapic-generator-java by googleapis.

the class AsyncSearchAllIamPoliciesPaged method asyncSearchAllIamPoliciesPaged.

public static void asyncSearchAllIamPoliciesPaged() throws Exception {
    // It may require modifications to work in your environment.
    try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
        SearchAllIamPoliciesRequest request = SearchAllIamPoliciesRequest.newBuilder().setScope("scope109264468").setQuery("query107944136").setPageSize(883849137).setPageToken("pageToken873572522").addAllAssetTypes(new ArrayList<String>()).setOrderBy("orderBy-1207110587").build();
        while (true) {
            SearchAllIamPoliciesResponse response = assetServiceClient.searchAllIamPoliciesCallable().call(request);
            for (IamPolicySearchResult element : response.getResponsesList()) {
            // doThingsWith(element);
            }
            String nextPageToken = response.getNextPageToken();
            if (!Strings.isNullOrEmpty(nextPageToken)) {
                request = request.toBuilder().setPageToken(nextPageToken).build();
            } else {
                break;
            }
        }
    }
}
Also used : SearchAllIamPoliciesResponse(com.google.cloud.asset.v1.SearchAllIamPoliciesResponse) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) SearchAllIamPoliciesRequest(com.google.cloud.asset.v1.SearchAllIamPoliciesRequest) IamPolicySearchResult(com.google.cloud.asset.v1.IamPolicySearchResult)

Example 2 with SearchAllIamPoliciesResponse

use of com.google.cloud.asset.v1.SearchAllIamPoliciesResponse in project gapic-generator-java by googleapis.

the class AssetServiceClientTest method searchAllIamPoliciesTest.

@Test
public void searchAllIamPoliciesTest() throws Exception {
    IamPolicySearchResult responsesElement = IamPolicySearchResult.newBuilder().build();
    SearchAllIamPoliciesResponse expectedResponse = SearchAllIamPoliciesResponse.newBuilder().setNextPageToken("").addAllResults(Arrays.asList(responsesElement)).build();
    mockAssetService.addResponse(expectedResponse);
    String scope = "scope109264468";
    String query = "query107944136";
    SearchAllIamPoliciesPagedResponse pagedListResponse = client.searchAllIamPolicies(scope, query);
    List<IamPolicySearchResult> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getResultsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockAssetService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    SearchAllIamPoliciesRequest actualRequest = ((SearchAllIamPoliciesRequest) actualRequests.get(0));
    Assert.assertEquals(scope, actualRequest.getScope());
    Assert.assertEquals(query, actualRequest.getQuery());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : SearchAllIamPoliciesPagedResponse(com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Aggregations

AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)1 SearchAllIamPoliciesPagedResponse (com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse)1 IamPolicySearchResult (com.google.cloud.asset.v1.IamPolicySearchResult)1 SearchAllIamPoliciesRequest (com.google.cloud.asset.v1.SearchAllIamPoliciesRequest)1 SearchAllIamPoliciesResponse (com.google.cloud.asset.v1.SearchAllIamPoliciesResponse)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 Test (org.junit.Test)1