use of com.google.cloud.asset.v1.SearchAllResourcesResponse in project gapic-generator-java by googleapis.
the class AssetServiceClientTest method searchAllResourcesTest.
@Test
public void searchAllResourcesTest() throws Exception {
ResourceSearchResult responsesElement = ResourceSearchResult.newBuilder().build();
SearchAllResourcesResponse expectedResponse = SearchAllResourcesResponse.newBuilder().setNextPageToken("").addAllResults(Arrays.asList(responsesElement)).build();
mockAssetService.addResponse(expectedResponse);
String scope = "scope109264468";
String query = "query107944136";
List<String> assetTypes = new ArrayList<>();
SearchAllResourcesPagedResponse pagedListResponse = client.searchAllResources(scope, query, assetTypes);
List<ResourceSearchResult> 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());
SearchAllResourcesRequest actualRequest = ((SearchAllResourcesRequest) actualRequests.get(0));
Assert.assertEquals(scope, actualRequest.getScope());
Assert.assertEquals(query, actualRequest.getQuery());
Assert.assertEquals(assetTypes, actualRequest.getAssetTypesList());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.asset.v1.SearchAllResourcesResponse in project gapic-generator-java by googleapis.
the class AsyncSearchAllResourcesPaged method asyncSearchAllResourcesPaged.
public static void asyncSearchAllResourcesPaged() throws Exception {
// It may require modifications to work in your environment.
try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
SearchAllResourcesRequest request = SearchAllResourcesRequest.newBuilder().setScope("scope109264468").setQuery("query107944136").addAllAssetTypes(new ArrayList<String>()).setPageSize(883849137).setPageToken("pageToken873572522").setOrderBy("orderBy-1207110587").setReadMask(FieldMask.newBuilder().build()).build();
while (true) {
SearchAllResourcesResponse response = assetServiceClient.searchAllResourcesCallable().call(request);
for (ResourceSearchResult element : response.getResponsesList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
}
Aggregations