}
@Test
public void testSaving() {
WebDownloader downloader = new WebDownloader();
try {
downloader.setUrl("http://www.google.com");
downloader.setMethod(WebDownloader.METHOD_POST);
downloader.setBufferSize(512);
downloader.setFollowsRedirects(false);
downloader.setCacheEnabled(true);
downloader.setUserAgent(WebDownloader.CHROME_UA);
downloader.addFormElement("q", "Your mother");
downloader.addFormElement("name", "die!");
String source = downloader.getXML(0);
System.out.println(source);
downloader = new WebDownloader();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e1) {
fail(e1.getMessage());
}
Document doc = null;
try {
doc = db.parse(new InputSource(new StringReader(source)));
} catch (SAXException e) {
fail(e.getMessage());
} catch (IOException e) {
fail(e.getMessage());
}
downloader.loadFromXML(doc.getFirstChild());
assertEquals(source, downloader.getXML(0));
} catch (MalformedURLException e) {
fail(e.getMessage());
}
}