use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxCache.
//Test: public <K> T ajax(String url, Class<K> type, long expire, AjaxCallback<K> callback)
public void testAjaxCache() {
AQUtility.cleanCache(AQUtility.getCacheDir(getActivity()), 0, 0);
String url = "http://www.google.com/uds/GnewsSearch?q=Obama&v=1.0";
File file = aq.getCachedFile(url);
assertNull(file);
AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject jo, AjaxStatus status) {
done(url, jo, status);
}
};
aq.ajax(url, JSONObject.class, 15 * 60 * 1000, cb);
waitAsync(2000);
JSONObject jo = (JSONObject) result;
assertNotNull(jo);
assertNotNull(jo.opt("responseData"));
File cached = aq.getCachedFile(url);
assertTrue(cached.exists());
assertTrue(cached.length() > 100);
}
use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.
the class AQueryAsyncTest method testWaitNullUrlCacheBlock.
public void testWaitNullUrlCacheBlock() {
String url = null;
AjaxCallback<String> cb = new AjaxCallback<String>();
cb.url(url).type(String.class).fileCache(true).expire(15 * 60 * 1000);
aq.sync(cb);
String res = cb.getResult();
AjaxStatus status = cb.getStatus();
assertNull(res);
assertNotNull(status);
assertEquals(AjaxStatus.NETWORK_ERROR, status.getCode());
}
use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxPut.
public void testAjaxPut() throws UnsupportedEncodingException {
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);
}
};
StringEntity entity = new StringEntity(new JSONObject().toString());
aq.put(url, "application/json", entity, JSONObject.class, cb);
waitAsync();
JSONObject jo = (JSONObject) result;
AQUtility.debug(jo);
assertNotNull(jo);
assertEquals("PUT", jo.optString("method"));
}
use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxAdvance.
//Test: public <K> T ajax(AjaxCallback<K> callback)
public void testAjaxAdvance() {
String url = "http://www.google.com/uds/GnewsSearch?q=Obama&v=1.0";
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);
aq.ajax(cb);
waitAsync();
JSONObject jo = (JSONObject) result;
assertNotNull(jo);
assertNotNull(jo.opt("responseData"));
}
use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxNetworkUrlCallback.
public void testAjaxNetworkUrlCallback() {
String url = "http://dummy.com/1234";
String networkUrl = "http://www.google.com/uds/GnewsSearch?q=Obama&v=1.0";
AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject jo, AjaxStatus status) {
done(url, jo, status);
}
}.networkUrl(networkUrl);
aq.ajax(url, JSONObject.class, 1000, cb);
waitAsync();
JSONObject jo = (JSONObject) result;
assertNotNull(jo);
assertNotNull(jo.opt("responseData"));
waitSec(2000);
File file = aq.getCachedFile(url);
assertNotNull(file);
}
Aggregations