Skip to content

Commit

Permalink
fix 2 failing java test
Browse files Browse the repository at this point in the history
improve client declaration in the test
  • Loading branch information
Victor Benarbia committed Dec 31, 2023
1 parent 33e30bf commit 9966b3f
Show file tree
Hide file tree
Showing 21 changed files with 190 additions and 211 deletions.
17 changes: 8 additions & 9 deletions src/test/java/serpapi/AppleAppStoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ public void search() throws SerpApiException {
if(System.getenv("API_KEY") == null)
return;

// set search context
// setup serpapi client
Map<String, String> auth = new HashMap<>();
auth.put("api_key", System.getenv("API_KEY"));
SerpApi client = new SerpApi(auth);

// run search
Map<String, String> parameter = new HashMap<>();
parameter.put("engine", "apple_app_store");
parameter.put("api_key", System.getenv("API_KEY"));

SerpApi serpapi = new SerpApi(parameter);

// set search parameter
parameter.put("term", "coffee");

JsonObject results = serpapi.search(parameter);
parameter.put("term", "coffee");
JsonObject results = client.search(parameter);
assertTrue(results.getAsJsonArray("organic_results").size() > 5);
}

Expand Down
17 changes: 8 additions & 9 deletions src/test/java/serpapi/BaiduTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ public void search() throws SerpApiException {
if(System.getenv("API_KEY") == null)
return;

// set search context
// setup serpapi client
Map<String, String> auth = new HashMap<>();
auth.put("api_key", System.getenv("API_KEY"));
SerpApi client = new SerpApi(auth);

// run search
Map<String, String> parameter = new HashMap<>();
parameter.put("engine", "baidu");
parameter.put("api_key", System.getenv("API_KEY"));

SerpApi serpapi = new SerpApi(parameter);

// set search parameter
parameter.put("q", "coffee");

JsonObject results = serpapi.search(parameter);
parameter.put("q", "coffee");
JsonObject results = client.search(parameter);
assertTrue(results.getAsJsonArray("organic_results").size() > 5);
}

Expand Down
19 changes: 9 additions & 10 deletions src/test/java/serpapi/BingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@ public void search() throws SerpApiException {
if(System.getenv("API_KEY") == null)
return;

// set search context
// setup serpapi client
Map<String, String> auth = new HashMap<>();
auth.put("api_key", System.getenv("API_KEY"));
SerpApi client = new SerpApi(auth);

// run search
Map<String, String> parameter = new HashMap<>();
parameter.put("engine", "bing");
parameter.put("api_key", System.getenv("API_KEY"));

SerpApi serpapi = new SerpApi(parameter);

// set search parameter
parameter.put("q", "coffee");

JsonObject results = serpapi.search(parameter);
assertTrue(results.getAsJsonArray("organic_results").size() > 5);
parameter.put("q", "coffee");
JsonObject results = client.search(parameter);
assertTrue(results.getAsJsonArray("organic_results").size() > 1);
}

}
17 changes: 8 additions & 9 deletions src/test/java/serpapi/DuckduckgoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ public void search() throws SerpApiException {
if(System.getenv("API_KEY") == null)
return;

// set search context
// setup serpapi client
Map<String, String> auth = new HashMap<>();
auth.put("api_key", System.getenv("API_KEY"));
SerpApi client = new SerpApi(auth);

// run search
Map<String, String> parameter = new HashMap<>();
parameter.put("engine", "duckduckgo");
parameter.put("api_key", System.getenv("API_KEY"));

SerpApi serpapi = new SerpApi(parameter);

// set search parameter
parameter.put("q", "coffee");

JsonObject results = serpapi.search(parameter);
parameter.put("q", "coffee");
JsonObject results = client.search(parameter);
assertTrue(results.getAsJsonArray("organic_results").size() > 5);
}

Expand Down
17 changes: 8 additions & 9 deletions src/test/java/serpapi/EbayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ public void search() throws SerpApiException {
if(System.getenv("API_KEY") == null)
return;

// set search context
// setup serpapi client
Map<String, String> auth = new HashMap<>();
auth.put("api_key", System.getenv("API_KEY"));
SerpApi client = new SerpApi(auth);

// run search
Map<String, String> parameter = new HashMap<>();
parameter.put("engine", "ebay");
parameter.put("api_key", System.getenv("API_KEY"));

SerpApi serpapi = new SerpApi(parameter);

// set search parameter
parameter.put("_nkw", "coffee");

JsonObject results = serpapi.search(parameter);
parameter.put("_nkw", "coffee");
JsonObject results = client.search(parameter);
assertTrue(results.getAsJsonArray("organic_results").size() > 5);
}

Expand Down
17 changes: 8 additions & 9 deletions src/test/java/serpapi/GoogleAutocompleteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ public void search() throws SerpApiException {
if(System.getenv("API_KEY") == null)
return;

// set search context
// setup serpapi client
Map<String, String> auth = new HashMap<>();
auth.put("api_key", System.getenv("API_KEY"));
SerpApi client = new SerpApi(auth);

// run search
Map<String, String> parameter = new HashMap<>();
parameter.put("engine", "google_autocomplete");
parameter.put("api_key", System.getenv("API_KEY"));

SerpApi serpapi = new SerpApi(parameter);

// set search parameter
parameter.put("q", "coffee");

JsonObject results = serpapi.search(parameter);
parameter.put("q", "coffee");
JsonObject results = client.search(parameter);
assertTrue(results.getAsJsonArray("suggestions").size() > 5);
}

Expand Down
17 changes: 8 additions & 9 deletions src/test/java/serpapi/GoogleEventsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ public void search() throws SerpApiException {
if(System.getenv("API_KEY") == null)
return;

// set search context
// setup serpapi client
Map<String, String> auth = new HashMap<>();
auth.put("api_key", System.getenv("API_KEY"));
SerpApi client = new SerpApi(auth);

// run search
Map<String, String> parameter = new HashMap<>();
parameter.put("engine", "google_events");
parameter.put("api_key", System.getenv("API_KEY"));

SerpApi serpapi = new SerpApi(parameter);

// set search parameter
parameter.put("q", "coffee");

JsonObject results = serpapi.search(parameter);
parameter.put("q", "coffee");
JsonObject results = client.search(parameter);
assertTrue(results.getAsJsonArray("events_results").size() > 5);
}

Expand Down
21 changes: 10 additions & 11 deletions src/test/java/serpapi/GoogleImagesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ public void search() throws SerpApiException {
if(System.getenv("API_KEY") == null)
return;

// set search context
// setup serpapi client
Map<String, String> auth = new HashMap<>();
auth.put("api_key", System.getenv("API_KEY"));
SerpApi client = new SerpApi(auth);

// run search
Map<String, String> parameter = new HashMap<>();
parameter.put("engine", "google_images");
parameter.put("api_key", System.getenv("API_KEY"));

SerpApi serpapi = new SerpApi(parameter);

// set search parameter
parameter.put("engine", "google_images");
parameter.put("tbm", "isch");
parameter.put("q", "coffee");

JsonObject results = serpapi.search(parameter);
parameter.put("engine", "google_images");
parameter.put("tbm", "isch");
parameter.put("q", "coffee");
JsonObject results = client.search(parameter);
assertTrue(results.getAsJsonArray("images_results").size() > 5);
}

Expand Down
17 changes: 8 additions & 9 deletions src/test/java/serpapi/GoogleJobsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ public void search() throws SerpApiException {
if(System.getenv("API_KEY") == null)
return;

// set search context
// setup serpapi client
Map<String, String> auth = new HashMap<>();
auth.put("api_key", System.getenv("API_KEY"));
SerpApi client = new SerpApi(auth);

// run search
Map<String, String> parameter = new HashMap<>();
parameter.put("engine", "google_jobs");
parameter.put("api_key", System.getenv("API_KEY"));

SerpApi serpapi = new SerpApi(parameter);

// set search parameter
parameter.put("q", "coffee");

JsonObject results = serpapi.search(parameter);
parameter.put("q", "coffee");
JsonObject results = client.search(parameter);
assertTrue(results.getAsJsonArray("jobs_results").size() > 5);
}

Expand Down
19 changes: 9 additions & 10 deletions src/test/java/serpapi/GoogleLocalServicesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@ public void search() throws SerpApiException {
if(System.getenv("API_KEY") == null)
return;

// set search context
// setup serpapi client
Map<String, String> auth = new HashMap<>();
auth.put("api_key", System.getenv("API_KEY"));
SerpApi client = new SerpApi(auth);

// run search
Map<String, String> parameter = new HashMap<>();
parameter.put("engine", "google_local_services");
parameter.put("api_key", System.getenv("API_KEY"));

SerpApi serpapi = new SerpApi(parameter);

// set search parameter
parameter.put("q", "electrician");
parameter.put("data_cid", "6745062158417646970");

JsonObject results = serpapi.search(parameter);
parameter.put("q", "electrician");
parameter.put("data_cid", "6745062158417646970");
JsonObject results = client.search(parameter);
assertTrue(results.getAsJsonArray("local_ads").size() > 5);
}

Expand Down
21 changes: 10 additions & 11 deletions src/test/java/serpapi/GoogleMapsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ public void search() throws SerpApiException {
if(System.getenv("API_KEY") == null)
return;

// set search context
// setup serpapi client
Map<String, String> auth = new HashMap<>();
auth.put("api_key", System.getenv("API_KEY"));
SerpApi client = new SerpApi(auth);

// run search
Map<String, String> parameter = new HashMap<>();
parameter.put("engine", "google_maps");
parameter.put("api_key", System.getenv("API_KEY"));

SerpApi serpapi = new SerpApi(parameter);

// set search parameter
parameter.put("q", "pizza");
parameter.put("ll", "@40.7455096,-74.0083012,15.1z");
parameter.put("type", "search");

JsonObject results = serpapi.search(parameter);
parameter.put("q", "pizza");
parameter.put("ll", "@40.7455096,-74.0083012,15.1z");
parameter.put("type", "search");
JsonObject results = client.search(parameter);
assertTrue(results.getAsJsonArray("local_results").size() > 5);
}

Expand Down
22 changes: 10 additions & 12 deletions src/test/java/serpapi/GooglePlayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@ public void search() throws SerpApiException {
if(System.getenv("API_KEY") == null)
return;

// set search context
// setup serpapi client
Map<String, String> auth = new HashMap<>();
auth.put("api_key", System.getenv("API_KEY"));
SerpApi client = new SerpApi(auth);

// run search
Map<String, String> parameter = new HashMap<>();
parameter.put("engine", "google_play");
parameter.put("api_key", System.getenv("API_KEY"));

SerpApi serpapi = new SerpApi(parameter);

// set search parameter
parameter.put("q", "kite");
parameter.put("store", "apps");
parameter.put("max_results", "2");

JsonObject results = serpapi.search(parameter);
assertTrue(results.getAsJsonArray("organic_results").size() > 2);
parameter.put("q", "kite");
parameter.put("store", "apps");
JsonObject results = client.search(parameter);
assertTrue(results.getAsJsonArray("organic_results").size() > 1);
}

}
41 changes: 21 additions & 20 deletions src/test/java/serpapi/GoogleProductTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@
*/
public class GoogleProductTest {

@Test
public void search() throws SerpApiException {
// skip test if no api_key provided
if(System.getenv("API_KEY") == null)
return;

// set search context
Map<String, String> parameter = new HashMap<>();
parameter.put("engine", "google_product");
parameter.put("api_key", System.getenv("API_KEY"));

SerpApi serpapi = new SerpApi(parameter);

// set search parameter
parameter.put("q", "coffee");
parameter.put("product_id", "4887235756540435899");

JsonObject results = serpapi.search(parameter);
assertTrue(results.getAsJsonArray("product_results").size() > 5);
}
// TODO wait on https://github.com/serpapi/SerpApi/issues/4432

// @Test
// public void search() throws SerpApiException {
// // skip test if no api_key provided
// if(System.getenv("API_KEY") == null)
// return;

// // setup serpapi client
// Map<String, String> auth = new HashMap<>();
// auth.put("api_key", System.getenv("API_KEY"));
// SerpApi client = new SerpApi(auth);

// // run search
// Map<String, String> parameter = new HashMap<>();
// parameter.put("engine", "google_product");
// parameter.put("q", "coffee");
// parameter.put("product_id", "4887235756540435899");
// JsonObject results = client.search(parameter);
// assertTrue(results.getAsJsonArray("product_results").size() > 5);
// }

}
Loading

0 comments on commit 9966b3f

Please sign in to comment.