use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxFileUrl.
public void testAjaxFileUrl() {
String url = "http://www.google.com/uds/GnewsSearch?q=Obama&v=1.0";
AjaxCallback<File> cb = new AjaxCallback<File>();
cb.url(url).type(File.class);
//aq.ajax(url, JSONObject.class, cb);
aq.sync(cb);
File file = cb.getResult();
assertNotNull(file);
AQUtility.debug(file.getAbsolutePath());
String path = file.getAbsolutePath();
AjaxCallback<String> cb2 = new AjaxCallback<String>();
cb2.url(path).fileCache(true).type(String.class);
aq.sync(cb2);
String html = cb2.getResult();
AQUtility.debug(html);
assertNotNull(html);
}
use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.
the class AQueryAsyncTest method testFile404NotOverwritenOldFile.
public void testFile404NotOverwritenOldFile() throws IOException {
String url = "http://androidquery.appspot.com/test/fake";
File old = AQUtility.getCacheFile(AQUtility.getCacheDir(getActivity()), url);
if (old != null) {
old.createNewFile();
AQUtility.write(old, new byte[1234]);
}
old = aq.getCachedFile(url);
assertNotNull(old);
assertEquals(1234, old.length());
AjaxCallback<File> cb = new AjaxCallback<File>();
cb.url(url).type(File.class);
aq.sync(cb);
File file = cb.getResult();
AjaxStatus status = cb.getStatus();
assertNull(file);
assertEquals(404, status.getCode());
old = aq.getCachedFile(url);
assertNotNull(old);
assertEquals(1234, old.length());
}
Aggregations