use of org.jsoup.nodes.Document in project jsoup by jhy.
the class UrlConnectTest method invalidProxyFails.
@Test
public void invalidProxyFails() throws IOException {
boolean caught = false;
String url = "https://jsoup.org";
try {
Document doc = Jsoup.connect(url).proxy("localhost", 8889).get();
} catch (IOException e) {
caught = e instanceof ConnectException;
}
assertTrue(caught);
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class UrlConnectTest method fetchHandlesXml.
@Test
public void fetchHandlesXml() throws IOException {
// should auto-detect xml and use XML parser, unless explicitly requested the html parser
String xmlUrl = "http://direct.infohound.net/tools/parse-xml.xml";
Connection con = Jsoup.connect(xmlUrl);
Document doc = con.get();
Connection.Request req = con.request();
assertTrue(req.parser().getTreeBuilder() instanceof XmlTreeBuilder);
assertEquals("<xml> <link> one </link> <table> Two </table> </xml>", StringUtil.normaliseWhitespace(doc.outerHtml()));
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class UrlConnectTest method fetchURIWithWihtespace.
@Test
public void fetchURIWithWihtespace() throws IOException {
Connection con = Jsoup.connect("http://try.jsoup.org/#with whitespaces");
Document doc = con.get();
assertTrue(doc.title().contains("jsoup"));
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class UrlConnectTest method handles200WithNoContent.
@Test
public void handles200WithNoContent() throws IOException {
Connection con = Jsoup.connect("http://direct.infohound.net/tools/200-no-content.pl").userAgent(browserUa);
Connection.Response res = con.execute();
Document doc = res.parse();
assertEquals(200, res.statusCode());
con = Jsoup.connect("http://direct.infohound.net/tools/200-no-content.pl").parser(Parser.xmlParser()).userAgent(browserUa);
res = con.execute();
doc = res.parse();
assertEquals(200, res.statusCode());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class UrlConnectTest method handlesUt8fInUrl.
@Test
public void handlesUt8fInUrl() throws IOException {
String url = "http://direct.infohound.net/tools/test💩.html";
String urlEscaped = "http://direct.infohound.net/tools/test%F0%9F%92%A9.html";
Connection.Response res = Jsoup.connect(url).execute();
Document doc = res.parse();
assertEquals("💩!", doc.body().text());
assertEquals(urlEscaped, doc.location());
}
Aggregations