-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSearchApiTest.java
More file actions
42 lines (33 loc) · 1.1 KB
/
SearchApiTest.java
File metadata and controls
42 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package serpapi;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
/**
* Test SerpApi.search() method.
*/
public class SearchApiTest {
@Test
public void search() throws SerpApiException, InterruptedException {
// skip test if no api_key provided
if(System.getenv("SERPAPI_KEY") == null) {
fail("SERPAPI_KEY is not set");
}
Map<String, String> auth = new HashMap<>();
auth.put("api_key", System.getenv("SERPAPI_KEY"));
SerpApi serpapi = new SerpApi(auth);
Map<String, String> parameter = new HashMap<>();
parameter.put("q", "Coffee");
parameter.put("location", "Austin, Texas, United States");
parameter.put("hl", "en");
parameter.put("gl", "us");
parameter.put("google_domain", "google.com");
parameter.put("safe", "active");
parameter.put("start", "10");
parameter.put("device", "desktop");
JsonObject results = serpapi.search(parameter);
assertTrue(results.getAsJsonArray("organic_results").size() > 5);
}
}