use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxProxyStaticBasicCredential.
public void testAjaxProxyStaticBasicCredential() throws ClientProtocolException, IOException {
String url = "http://www.google.com";
String host = "192.168.1.6";
int port = 8081;
String user = "Peter";
String password = "orange99";
//AjaxCallback.setProxy(host, port, user, password);
ProxyHandle handle = new BasicProxyHandle(host, port, user, password);
AjaxCallback.setProxyHandle(handle);
aq.ajax(url, String.class, new AjaxCallback<String>() {
@Override
public void callback(String url, String json, AjaxStatus status) {
done(url, json, status);
}
});
waitAsync();
assertNotNull(result);
}
use of com.androidquery.callback.AjaxStatus 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.AjaxStatus in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxCookieGet.
public void testAjaxCookieGet() {
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);
}
});
waitAsync();
assertNotNull(result);
List<Cookie> cookies = status.getCookies();
assertTrue(cookies.size() > 0);
Cookie c = cookies.get(0);
AQUtility.debug(c.getName(), c.getValue());
}
use of com.androidquery.callback.AjaxStatus 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);
}
use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.
the class AQueryAsyncTest method testFile404NotOverwritenOldFile.
public void testFile404NotOverwritenOldFile() throws IOException {
String url = "http://androidquery.appspot.com/test/fake";
File old = AQUtility.getCacheFile(AQUtility.getCacheDir(getActivity()), url);
if (old != null) {
old.createNewFile();
AQUtility.write(old, new byte[1234]);
}
old = aq.getCachedFile(url);
assertNotNull(old);
assertEquals(1234, old.length());
AjaxCallback<File> cb = new AjaxCallback<File>();
cb.url(url).type(File.class);
aq.sync(cb);
File file = cb.getResult();
AjaxStatus status = cb.getStatus();
assertNull(file);
assertEquals(404, status.getCode());
old = aq.getCachedFile(url);
assertNotNull(old);
assertEquals(1234, old.length());
}
Aggregations