use of com.androidquery.callback.AjaxCallback 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"));
}
use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.
the class AQueryAsyncTest method testFile404.
public void testFile404() {
String url = "http://androidquery.appspot.com/test/fake";
File old = aq.getCachedFile(url);
if (old != null) {
old.delete();
}
old = aq.getCachedFile(url);
assertNull(old);
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();
AjaxStatus status = cb.getStatus();
assertNull(file);
assertEquals(404, status.getCode());
old = aq.getCachedFile(url);
assertNull(old);
}
use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxProxy.
//http://www.proxynova.com/proxy-server-list/
public void testAjaxProxy() throws ClientProtocolException, IOException {
String url = "http://www.google.com";
aq.ajax(url, String.class, new AjaxCallback<String>() {
@Override
public void callback(String url, String json, AjaxStatus status) {
done(url, json, status);
}
}.proxy("192.168.0.105", 3128));
waitAsync();
assertNotNull(result);
List<Header> headers = status.getHeaders();
assertTrue(headers.size() > 0);
Header c = headers.get(0);
AQUtility.debug(c.getName(), c.getValue());
}
use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxPostWithEmptyParams.
public void testAjaxPostWithEmptyParams() {
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).method(AQuery.METHOD_POST);
aq.ajax(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 testIOError.
public void testIOError() {
AQUtility.cleanCache(AQUtility.getCacheDir(getActivity()), 0, 0);
String LAND_URL = "http://farm6.static.flickr.com/5035/5802797131_a729dac808_b.jpg";
File file = aq.getCachedFile(LAND_URL);
assertNull(file);
AQUtility.TEST_IO_EXCEPTION = true;
AjaxCallback<File> cb = new AjaxCallback<File>() {
@Override
public void callback(String url, File file, AjaxStatus status) {
done(url, file, status);
}
};
cb.fileCache(true);
aq.ajax(LAND_URL, File.class, 0, cb);
waitAsync();
file = (File) result;
assertNull(result);
File file2 = aq.getCachedFile(LAND_URL);
if (file2 != null) {
AQUtility.debug("file length", file2.length());
}
assertNull(file2);
}
Aggregations