AdServiceClient implements BackgroundResource { public final Ad getAd(AdName resourceName) { GetAdRequest request = GetAdRequest.newBuilder() .setResourceName(resourceName == null ? null : resourceName.toString()) .build(); return getAd(request); } protected  AdServiceClient(AdServiceSettings settings); @BetaApi("A restructuring of stub classes is planned, so this may break in the future") protected  AdServiceClient(AdServiceStub stub); static final AdServiceClient create(); static final AdServiceClient create(AdServiceSettings settings); @BetaApi("A restructuring of stub classes is planned, so this may break in the future") static final AdServiceClient create(AdServiceStub stub); final AdServiceSettings getSettings(); @BetaApi("A restructuring of stub classes is planned, so this may break in the future") AdServiceStub getStub(); final Ad getAd(AdName resourceName); final Ad getAd(String resourceName); final Ad getAd(GetAdRequest request); final UnaryCallable<GetAdRequest, Ad> getAdCallable(); final MutateAdsResponse mutateAds(String customerId, List<AdOperation> operations); final MutateAdsResponse mutateAds(MutateAdsRequest request); final UnaryCallable<MutateAdsRequest, MutateAdsResponse> mutateAdsCallable(); @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 getAdTest() { com.google.ads.googleads.v5.services.AdName resourceName2 = com.google.ads.googleads.v5.services.AdName.of("[CUSTOMER]", "[AD]"); long id = 3355L; String trackingUrlTemplate = "trackingUrlTemplate-1611329070"; String finalUrlSuffix = "finalUrlSuffix-1825164662"; String displayUrl = "displayUrl1714674802"; boolean addedByGoogleAds = false; com.google.ads.googleads.v5.services.AdName name = com.google.ads.googleads.v5.services.AdName.of("[CUSTOMER]", "[AD]"); Ad expectedResponse = Ad.newBuilder() .setResourceName(resourceName2.toString()) .setId(id) .setTrackingUrlTemplate(trackingUrlTemplate) .setFinalUrlSuffix(finalUrlSuffix) .setDisplayUrl(displayUrl) .setAddedByGoogleAds(addedByGoogleAds) .setName(name.toString()) .build(); mockAdService.addResponse(expectedResponse); AdName resourceName = AdName.of("[CUSTOMER]", "[AD]"); Ad actualResponse = client.getAd(resourceName); Assert.assertEquals(expectedResponse, actualResponse); List<AbstractMessage> actualRequests = mockAdService.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetAdRequest actualRequest = (GetAdRequest) actualRequests.get(0); Assert.assertEquals(resourceName, AdName.parse(actualRequest.getResourceName())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test @SuppressWarnings("all") public void getAdExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockAdService.addException(exception); try { AdName resourceName = AdName.of("[CUSTOMER]", "[AD]"); client.getAd(resourceName); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { } }