GoogleAdsServiceClient implements BackgroundResource { public final SearchPagedResponse search(String customerId, String query) { SearchGoogleAdsRequest request = SearchGoogleAdsRequest.newBuilder().setCustomerId(customerId).setQuery(query).build(); return search(request); } protected  GoogleAdsServiceClient(GoogleAdsServiceSettings settings); @BetaApi("A restructuring of stub classes is planned, so this may break in the future") protected  GoogleAdsServiceClient(GoogleAdsServiceStub stub); static final GoogleAdsServiceClient create(); static final GoogleAdsServiceClient create(GoogleAdsServiceSettings settings); @BetaApi("A restructuring of stub classes is planned, so this may break in the future") static final GoogleAdsServiceClient create(GoogleAdsServiceStub stub); final GoogleAdsServiceSettings getSettings(); @BetaApi("A restructuring of stub classes is planned, so this may break in the future") GoogleAdsServiceStub getStub(); final SearchPagedResponse search(String customerId, String query); final SearchPagedResponse search(SearchGoogleAdsRequest request); final UnaryCallable<SearchGoogleAdsRequest, SearchPagedResponse> searchPagedCallable(); final UnaryCallable<SearchGoogleAdsRequest, SearchGoogleAdsResponse> searchCallable(); final ServerStreamingCallable<SearchGoogleAdsStreamRequest, SearchGoogleAdsStreamResponse> searchStreamCallable(); final MutateGoogleAdsResponse mutate(
      String customerId, List<MutateOperation> mutateOperations); final MutateGoogleAdsResponse mutate(MutateGoogleAdsRequest request); final UnaryCallable<MutateGoogleAdsRequest, MutateGoogleAdsResponse> mutateCallable(); @Override final void close(); @Override void shutdown(); @Override boolean isShutdown(); @Override boolean isTerminated(); @Override void shutdownNow(); @Override boolean awaitTermination(long duration, TimeUnit unit);  }
@Test @SuppressWarnings("all") public void searchTest() { String nextPageToken = ""; long totalResultsCount = 43694645L; GoogleAdsRow resultsElement = GoogleAdsRow.newBuilder().build(); List<GoogleAdsRow> results = Arrays.asList(resultsElement); SearchGoogleAdsResponse expectedResponse = SearchGoogleAdsResponse.newBuilder() .setNextPageToken(nextPageToken) .setTotalResultsCount(totalResultsCount) .addAllResults(results) .build(); mockGoogleAdsService.addResponse(expectedResponse); String customerId = "customerId-1772061412"; String query = "query107944136"; SearchPagedResponse pagedListResponse = client.search(customerId, query); List<GoogleAdsRow> resources = Lists.newArrayList(pagedListResponse.iterateAll()); Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getResultsList().get(0), resources.get(0)); List<AbstractMessage> actualRequests = mockGoogleAdsService.getRequests(); Assert.assertEquals(1, actualRequests.size()); SearchGoogleAdsRequest actualRequest = (SearchGoogleAdsRequest) actualRequests.get(0); Assert.assertEquals(customerId, actualRequest.getCustomerId()); Assert.assertEquals(query, actualRequest.getQuery()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test @SuppressWarnings("all") public void searchExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockGoogleAdsService.addException(exception); try { String customerId = "customerId-1772061412"; String query = "query107944136"; client.search(customerId, query); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { } }