use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxPostJson.
public void testAjaxPostJson() throws UnsupportedEncodingException, JSONException {
String url = "http://www.androidquery.com/p/doNothing";
AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject jo, AjaxStatus status) {
done(url, jo, status);
}
};
JSONObject input = new JSONObject();
input.putOpt("hello", "world");
aq.post(url, input, JSONObject.class, cb);
waitAsync();
JSONObject jo = (JSONObject) result;
AQUtility.debug(jo);
assertNotNull(jo);
assertEquals("POST", jo.optString("method"));
}
use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxCookie.
public void testAjaxCookie() {
String url = "http://www.androidquery.com/p/doNothing";
AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject jo, AjaxStatus status) {
done(url, jo, status);
}
};
cb.url(url).type(JSONObject.class).cookie("hello", "world").cookie("foo", "bar");
aq.ajax(cb);
waitAsync();
JSONObject jo = (JSONObject) result;
AQUtility.debug(jo);
assertNotNull(jo);
JSONObject cookies = (JSONObject) jo.optJSONObject("cookies");
assertNotNull(cookies);
assertEquals("world", cookies.optString("hello"));
assertEquals("bar", cookies.optString("foo"));
}
use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxBitmap.
public void testAjaxBitmap() {
String url = ICON_URL;
AjaxCallback<Bitmap> cb = new AjaxCallback<Bitmap>() {
@Override
public void callback(String url, Bitmap bm, AjaxStatus status) {
done(url, bm, status);
}
};
aq.ajax(url, Bitmap.class, 15 * 60 * 1000, cb);
waitAsync(2000);
assertNotNull(result);
File cached = aq.getCachedFile(url);
assertTrue(cached.exists());
assertTrue(cached.length() > 100);
}
use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.
the class AQueryAsyncTest method testWaitBlockInputStream.
public void testWaitBlockInputStream() {
String url = "http://www.google.com/uds/GnewsSearch?q=Obama&v=1.0";
AjaxCallback<InputStream> cb = new AjaxCallback<InputStream>();
cb.url(url).type(InputStream.class);
aq.sync(cb);
String u = cb.getUrl();
InputStream is = cb.getResult();
AjaxStatus status = cb.getStatus();
byte[] data = AQUtility.toBytes(is);
JSONObject jo = null;
String str = null;
try {
str = new String(data, "UTF-8");
jo = (JSONObject) new JSONTokener(str).nextValue();
} catch (Exception e) {
AQUtility.debug(e);
AQUtility.debug(str);
}
assertNotNull(jo);
assertNotNull(jo.opt("responseData"));
checkStatus(status);
}
use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxTimeout.
public void testAjaxTimeout() {
String url = "http://farm6.static.flickr.com/5035/5802797131_a729dac808_b.jpg";
AjaxCallback<File> cb = new AjaxCallback<File>();
cb.url(url).type(File.class).timeout(1);
aq.sync(cb);
File file = cb.getResult();
AjaxStatus status = cb.getStatus();
assertNull(file);
assertTrue(status.getCode() == AjaxStatus.NETWORK_ERROR);
}
Aggregations