use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxPutNamedValues.
public void testAjaxPutNamedValues() throws UnsupportedEncodingException {
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("count", "5"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs, "UTF-8");
entity.setContentType("application/x-www-form-urlencoded;charset=UTF-8");
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);
}
};
aq.put(url, "application/x-www-form-urlencoded;charset=UTF-8", entity, JSONObject.class, cb);
waitAsync();
JSONObject jo = (JSONObject) result;
AQUtility.debug(jo);
assertNotNull(jo);
JSONObject params = jo.optJSONObject("params");
assertEquals("5", params.optString("count"));
//assertEquals("PUT", jo.optString("method"));
}
use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.
the class AQueryAsyncTest method testExtendTransformer.
public void testExtendTransformer() {
String url = "https://graph.facebook.com/205050232863343";
AjaxCallback<Profile> cb = new AjaxCallback<Profile>() {
@Override
protected Profile transform(String url, byte[] data, AjaxStatus status) {
Profile profile = null;
if (data != null) {
Gson g = new Gson();
profile = g.fromJson(new String(data), getType());
}
return profile;
}
@Override
public void callback(String url, Profile profile, AjaxStatus status) {
done(url, profile, status);
}
};
aq.ajax(url, Profile.class, cb);
waitAsync(2000);
assertNotNull(result);
}
use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxInactiveActivity.
public void testAjaxInactiveActivity() {
String url = "http://www.google.com/uds/GnewsSearch?q=Obama&v=1.0";
Activity act = getActivity();
act.finish();
assertTrue(act.isFinishing());
AQuery aq = new AQuery(act);
AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject jo, AjaxStatus status) {
assertFalse(true);
done(url, jo, status);
}
};
aq.ajax(url, JSONObject.class, cb);
waitAsync();
JSONObject jo = (JSONObject) result;
assertNull(jo);
}
use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxTransformErrorWontCache.
public void testAjaxTransformErrorWontCache() {
String url = "http://www.google.com";
/*
AjaxCallback<String> cb = new AjaxCallback<String>(){
@Override
public void callback(String url, String str, AjaxStatus status) {
}
};
aq.ajax(url, String.class, 0, cb);
waitAsync(2000);
assertNotNull(aq.getCachedFile(url));
*/
AjaxCallback<JSONObject> cb2 = new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject jo, AjaxStatus status) {
done(url, jo, status);
}
};
aq.ajax(url, JSONObject.class, 0, cb2);
waitAsync(2000);
assertEquals(AjaxStatus.TRANSFORM_ERROR, status.getCode());
JSONObject jo = (JSONObject) result;
assertNull(jo);
File file = aq.getCachedFile(url);
AQUtility.debug("check file", file);
assertNull(file);
}
use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.
the class AQueryAsyncTest method testRetryFailed.
public void testRetryFailed() {
String url = "http://www.androidquery.com/p/retry?wait=5000";
AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>();
cb.weakHandler(this, "jsonCb").timeout(1000);
aq.ajax(url, JSONObject.class, cb);
waitAsync();
JSONObject jo = (JSONObject) result;
assertNull(jo);
assertEquals(-101, status.getCode());
}
Aggregations