use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.
the class AQueryAsyncTest method testWaitBlock.
public void testWaitBlock() {
String url = "http://www.google.com/uds/GnewsSearch?q=Obama&v=1.0";
AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>();
cb.url(url).type(JSONObject.class);
aq.sync(cb);
String u = cb.getUrl();
JSONObject jo = cb.getResult();
AjaxStatus status = cb.getStatus();
assertNotNull(jo);
assertNotNull(jo.opt("responseData"));
checkStatus(status);
}
use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxPostMultiAuth.
public void testAjaxPostMultiAuth() {
String url = "http://www.androidquery.com/p/multipart";
BasicHandle handle = new BasicHandle("username", "1234");
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);
aq.auth(handle).ajax(url, params, JSONObject.class, new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject jo, AjaxStatus status) {
AQUtility.debug(status.getCode(), status.getError());
AQueryAsyncTest.this.result = jo;
}
});
waitAsync();
JSONObject jo = (JSONObject) result;
AQUtility.debug(jo);
assertNotNull(jo);
assertEquals(1234, jo.optInt("data"));
assertEquals(2345, jo.optInt("data2"));
JSONObject headers = jo.optJSONObject("headers");
assertNotNull(headers.optString("Authorization"));
}
use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxPostMultiError.
public void testAjaxPostMultiError() {
String url = "http://www.androidquery.com/p/multipart2";
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);
aq.ajax(url, params, JSONObject.class, new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject jo, AjaxStatus status) {
AQUtility.debug(status.getCode(), status.getError());
AQueryAsyncTest.this.result = jo;
AQueryAsyncTest.this.status = status;
}
});
waitAsync();
JSONObject jo = (JSONObject) result;
AQUtility.debug("error code", status.getCode());
assertNull(jo);
assertEquals(404, status.getCode());
String error = status.getError();
assertNotNull(error);
}
use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxPostMultiInputStream.
public void testAjaxPostMultiInputStream() {
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", new ByteArrayInputStream(data));
params.put("data2", new ByteArrayInputStream(data2));
aq.ajax(url, params, JSONObject.class, new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject jo, AjaxStatus status) {
AQUtility.debug(status.getCode(), status.getError());
AQueryAsyncTest.this.result = jo;
}
});
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.AjaxStatus in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxHeadersGet.
public void testAjaxHeadersGet() {
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<Header> headers = status.getHeaders();
assertTrue(headers.size() > 0);
Header c = headers.get(0);
AQUtility.debug(c.getName(), c.getValue());
}
Aggregations