Search in sources :

Example 11 with AjaxStatus

use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.

the class AQueryAsyncTest method testAjaxCache.

//Test: public <K> T ajax(String url, Class<K> type, long expire, AjaxCallback<K> callback)
public void testAjaxCache() {
    AQUtility.cleanCache(AQUtility.getCacheDir(getActivity()), 0, 0);
    String url = "http://www.google.com/uds/GnewsSearch?q=Obama&v=1.0";
    File file = aq.getCachedFile(url);
    assertNull(file);
    AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() {

        @Override
        public void callback(String url, JSONObject jo, AjaxStatus status) {
            done(url, jo, status);
        }
    };
    aq.ajax(url, JSONObject.class, 15 * 60 * 1000, cb);
    waitAsync(2000);
    JSONObject jo = (JSONObject) result;
    assertNotNull(jo);
    assertNotNull(jo.opt("responseData"));
    File cached = aq.getCachedFile(url);
    assertTrue(cached.exists());
    assertTrue(cached.length() > 100);
}
Also used : JSONObject(org.json.JSONObject) File(java.io.File) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 12 with AjaxStatus

use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.

the class AQueryAsyncTest method testWaitNullUrlCacheBlock.

public void testWaitNullUrlCacheBlock() {
    String url = null;
    AjaxCallback<String> cb = new AjaxCallback<String>();
    cb.url(url).type(String.class).fileCache(true).expire(15 * 60 * 1000);
    aq.sync(cb);
    String res = cb.getResult();
    AjaxStatus status = cb.getStatus();
    assertNull(res);
    assertNotNull(status);
    assertEquals(AjaxStatus.NETWORK_ERROR, status.getCode());
}
Also used : AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 13 with AjaxStatus

use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.

the class AQueryAsyncTest method testAjaxPut.

public void testAjaxPut() throws UnsupportedEncodingException {
    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);
        }
    };
    StringEntity entity = new StringEntity(new JSONObject().toString());
    aq.put(url, "application/json", entity, JSONObject.class, cb);
    waitAsync();
    JSONObject jo = (JSONObject) result;
    AQUtility.debug(jo);
    assertNotNull(jo);
    assertEquals("PUT", jo.optString("method"));
}
Also used : StringEntity(org.apache.http.entity.StringEntity) JSONObject(org.json.JSONObject) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 14 with AjaxStatus

use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.

the class AQueryAsyncTest method testAjaxAdvance.

//Test: public <K> T ajax(AjaxCallback<K> callback)
public void testAjaxAdvance() {
    String url = "http://www.google.com/uds/GnewsSearch?q=Obama&v=1.0";
    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);
    aq.ajax(cb);
    waitAsync();
    JSONObject jo = (JSONObject) result;
    assertNotNull(jo);
    assertNotNull(jo.opt("responseData"));
}
Also used : JSONObject(org.json.JSONObject) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 15 with AjaxStatus

use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.

the class AQueryAsyncTest method testAjaxNetworkUrlCallback.

public void testAjaxNetworkUrlCallback() {
    String url = "http://dummy.com/1234";
    String networkUrl = "http://www.google.com/uds/GnewsSearch?q=Obama&v=1.0";
    AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() {

        @Override
        public void callback(String url, JSONObject jo, AjaxStatus status) {
            done(url, jo, status);
        }
    }.networkUrl(networkUrl);
    aq.ajax(url, JSONObject.class, 1000, cb);
    waitAsync();
    JSONObject jo = (JSONObject) result;
    assertNotNull(jo);
    assertNotNull(jo.opt("responseData"));
    waitSec(2000);
    File file = aq.getCachedFile(url);
    assertNotNull(file);
}
Also used : JSONObject(org.json.JSONObject) File(java.io.File) AjaxStatus(com.androidquery.callback.AjaxStatus)

Aggregations

AjaxStatus (com.androidquery.callback.AjaxStatus)55 BitmapAjaxCallback (com.androidquery.callback.BitmapAjaxCallback)33 AjaxCallback (com.androidquery.callback.AjaxCallback)28 AbstractAjaxCallback (com.androidquery.callback.AbstractAjaxCallback)27 JSONObject (org.json.JSONObject)27 File (java.io.File)15 HashMap (java.util.HashMap)11 LinkedHashMap (java.util.LinkedHashMap)10 JsonObject (com.google.gson.JsonObject)8 Bitmap (android.graphics.Bitmap)7 Location (android.location.Location)4 ImageView (android.widget.ImageView)4 LocationAjaxCallback (com.androidquery.callback.LocationAjaxCallback)4 ArrayList (java.util.ArrayList)3 NameValuePair (org.apache.http.NameValuePair)3 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)3 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)3 ProxyHandle (com.androidquery.callback.ProxyHandle)2 Gson (com.google.gson.Gson)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2