Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/serpapi/SerpApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public SerpApi() {
* @throws SerpApiException wraps backend error message
*/
public String html(Map<String, String> parameter) throws SerpApiException {
return get("/client", "html", parameter);
return get("/search", "html", parameter);
}

/***
Expand Down
51 changes: 51 additions & 0 deletions src/test/java/serpapi/HtmlApiTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package serpapi;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.*;

/**
* Test SerpApi.html() method.
*
* Offline: the HTTP client is stubbed, so no network call and no SERPAPI_KEY
* are needed. What matters here is the request this client builds, which can
* be asserted without a live backend.
*/
public class HtmlApiTest {

/**
* Stubbed HTTP client that records the query it was asked to send.
*/
private static class RecordingHttp extends SerpApiHttp {
Map<String, String> recorded;

RecordingHttp() {
super("/search");
}

@Override
public String get(Map<String, String> parameter) {
this.recorded = parameter;
return "<html><body>coffee</body></html>";
}
}

@Test
public void htmlRequestsHtmlOutputFromSearchEndpoint() throws SerpApiException {
SerpApi serpapi = new SerpApi(new HashMap<>());
RecordingHttp http = new RecordingHttp();
serpapi.client = http;

Map<String, String> parameter = new HashMap<>();
parameter.put("q", "coffee");
String content = serpapi.html(parameter);

assertEquals("html", http.recorded.get("output"));
assertEquals("coffee", http.recorded.get("q"));
assertEquals("/search", http.path);
assertTrue(content.startsWith("<html>"));
}
}
Loading