use of com.google.cloud.asset.v1p1beta1.AssetServiceClient.SearchAllResourcesPagedResponse 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.v1p1beta1.AssetServiceClient.SearchAllResourcesPagedResponse in project java-asset by googleapis.
the class AssetServiceClientTest method searchAllResourcesTest.
@Test
public void searchAllResourcesTest() throws Exception {
StandardResourceMetadata responsesElement = StandardResourceMetadata.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<StandardResourceMetadata> 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.v1p1beta1.AssetServiceClient.SearchAllResourcesPagedResponse in project java-asset by googleapis.
the class SearchAllResourcesExample method searchAllResources.
// Searches for all the resources within the given scope.
public static void searchAllResources(String scope, String query) {
// TODO(developer): Replace these variables before running the sample.
String[] assetTypes = {};
int pageSize = 0;
String pageToken = "";
String orderBy = "";
SearchAllResourcesRequest request = SearchAllResourcesRequest.newBuilder().setScope(scope).setQuery(query).addAllAssetTypes(Arrays.asList(assetTypes)).setPageSize(pageSize).setPageToken(pageToken).setOrderBy(orderBy).build();
// the "close" method on the client to safely clean up any remaining background resources.
try (AssetServiceClient client = AssetServiceClient.create()) {
SearchAllResourcesPagedResponse response = client.searchAllResources(request);
System.out.println("Search completed successfully:\n" + response.getPage().getValues());
} catch (IOException e) {
System.out.println(String.format("Failed to create client:%n%s", e.toString()));
} catch (InvalidArgumentException e) {
System.out.println(String.format("Invalid request:%n%s", e.toString()));
} catch (ApiException e) {
System.out.println(String.format("Error during SearchAllResources:%n%s", e.toString()));
}
}
Aggregations