4141 *
4242 * <p>Only depends on a basic configuration file with devtoken, OAuth etc.
4343 *
44- * <p>Retrieves all accessible customers and iterates through all their campaigns .
44+ * <p>Retrieves all accessible customers and issues a search request for each customer .
4545 */
4646@ RunWith (JUnit4 .class )
4747public class SmokeTest {
4848
4949 @ Rule public Timeout timeout = new Timeout (20_000 , TimeUnit .MILLISECONDS );
5050
5151 @ Test
52- public void ensureCanReadAllAvailableCustomersCampaigns () throws IOException {
53- GoogleAdsClient client = GoogleAdsClient .newBuilder ().fromPropertiesFile ().build ();
52+ public void ensureCanReadAllAvailableCustomers () throws IOException {
53+ GoogleAdsClient client =
54+ GoogleAdsClient .newBuilder ()
55+ .fromPropertiesFile ()
56+ // Sets the login-customer-id to null. If this is set in the properties file, then
57+ // attempts to issue requests against accessible accounts in a different manager account
58+ // hierarchy will fail. With login-customer-id not set, the Google Ads API will set it
59+ // to the customer ID in each search request, which will result in a successful request
60+ // because this test only queries customers who are directly accessible with the
61+ // provided credentials.
62+ .setLoginCustomerId (null )
63+ .build ();
5464 List <String > accessibleCustomerIds = getAvailableCustomerIds (client );
5565 if (accessibleCustomerIds .isEmpty ()) {
5666 fail (
5767 "No accessible customers returned by CustomerService.ListAccessibleCustomers(). Please"
5868 + " provide a refresh token which has access to customers in order to run functional"
5969 + " tests" );
6070 }
61- fetchAllCampaigns (client , accessibleCustomerIds );
71+ fetchAllCustomers (client , accessibleCustomerIds );
6272 }
6373
6474 private static List <String > getAvailableCustomerIds (GoogleAdsClient client ) {
@@ -76,22 +86,22 @@ private static List<String> getAvailableCustomerIds(GoogleAdsClient client) {
7686 }
7787 }
7888
79- private static void fetchAllCampaigns (
89+ /** Fetches the {@code Customer} object for each accessible customer. */
90+ private static void fetchAllCustomers (
8091 GoogleAdsClient client , List <String > accessibleCustomerIds ) {
81- int numCampaigns = 0 ;
92+ int numCustomers = 0 ;
8293 try (GoogleAdsServiceClient googleAdsServiceClient =
8394 client .getLatestVersion ().createGoogleAdsServiceClient ()) {
8495 for (String customerId : accessibleCustomerIds ) {
8596 SearchPagedResponse response =
8697 googleAdsServiceClient .search (
8798 customerId ,
88- "SELECT campaign.id, campaign.status, campaign.start_date "
89- + "FROM campaign "
90- + "WHERE campaign.status != 'REMOVED'" );
91- numCampaigns += StreamSupport .stream (response .iterateAll ().spliterator (), false ).count ();
99+ "SELECT customer.id, customer.manager, customer.currency_code,"
100+ + " customer.descriptive_name FROM customer" );
101+ numCustomers += StreamSupport .stream (response .iterateAll ().spliterator (), false ).count ();
92102 }
93103 }
94- System .out .println ("Retrieved " + numCampaigns + " campaigns " );
95- assertTrue ("Expected to read at least one campaign for smoke test." , numCampaigns > 0 );
104+ System .out .println ("Retrieved " + numCustomers + " customers " );
105+ assertTrue ("Expected to read at least one customer for smoke test." , numCustomers > 0 );
96106 }
97107}
0 commit comments