use of com.androidquery.callback.AjaxStatus 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.AjaxStatus in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxPost.
//Test: <K> T ajax(String url, Map<String, Object> params, Class<K> type, AjaxCallback<K> callback)
public void testAjaxPost() {
String url = "http://www.androidquery.com/p/doNothing";
Map<String, String> params = new HashMap<String, String>();
params.put("q", "androidquery");
aq.ajax(url, params, JSONObject.class, new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject jo, AjaxStatus status) {
done(url, jo, status);
}
});
waitAsync();
JSONObject jo = (JSONObject) result;
assertNotNull(jo);
assertNotNull(jo.opt("params"));
assertEquals("POST", jo.optString("method"));
}
use of com.androidquery.callback.AjaxStatus 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.AjaxStatus 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.AjaxStatus in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxPostMultiWithProxyHandle.
public void testAjaxPostMultiWithProxyHandle() {
BasicProxyHandle handle = new BasicProxyHandle("192.168.0.102", 3128, null, null);
AjaxCallback.setProxyHandle(handle);
String url = "http://www.androidquery.com/p/multipart";
Map<String, Object> params = new HashMap<String, Object>();
byte[] data = new byte[1234];
byte[] data2 = new byte[2345];
params.put("data", data);
params.put("data2", data2);
AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject jo, AjaxStatus status) {
AQUtility.debug(status.getCode(), status.getError());
AQueryAsyncTest.this.result = jo;
}
};
aq.ajax(url, params, JSONObject.class, cb);
waitAsync();
JSONObject jo = (JSONObject) result;
AQUtility.debug(jo);
assertNotNull(jo);
assertEquals(1234, jo.optInt("data"));
assertEquals(2345, jo.optInt("data2"));
}
Aggregations