Search in sources :

Example 36 with AjaxStatus

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

the class AQueryPerformanceTest method testAjaxPostDuration.

//Test: <K> T ajax(String url, Map<String, Object> params, Class<K> type, AjaxCallback<K> callback)
public void testAjaxPostDuration() {
    String url = "http://192.168.1.165/p/doNothing";
    long totalDur = 0;
    Map<String, String> params = new HashMap<String, String>();
    params.put("q", "androidquery");
    AjaxCallback.setReuseHttpClient(false);
    for (int i = 0; i < 1000; i++) {
        AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>();
        cb.type(JSONObject.class).url(url).params(params);
        aq.sync(cb);
        //JSONObject jo = (JSONObject) cb.getResult();
        AjaxStatus status = cb.getStatus();
        if (i > 0) {
            totalDur += status.getDuration();
        }
    }
    AjaxCallback.setReuseHttpClient(true);
    AQUtility.debug("duration", totalDur);
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) AjaxCallback(com.androidquery.callback.AjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 37 with AjaxStatus

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

the class AQueryAsyncTest method testAjaxTimeoutFiveSeconds.

public void testAjaxTimeoutFiveSeconds() {
    String url = "http://farm6.static.flickr.com/5035/5802797131_a729dac808_b.jpg";
    url = "http://deelay.me/10000/" + url;
    AjaxCallback.setTimeout(5000);
    AjaxCallback<File> cb = new AjaxCallback<File>();
    cb.url(url).type(File.class);
    long start = System.currentTimeMillis();
    aq.sync(cb);
    File file = cb.getResult();
    AjaxStatus status = cb.getStatus();
    long end = System.currentTimeMillis();
    long diff = end - start;
    AQUtility.debug("timeout", diff);
    assertTrue(diff < 10000);
    assertNull(file);
    assertTrue(status.getCode() == AjaxStatus.NETWORK_ERROR);
}
Also used : 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 38 with AjaxStatus

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

the class AQueryAsyncTest method testAjaxLongBitmapURL.

public void testAjaxLongBitmapURL() {
    String dummy = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
    String title = "Very long title " + dummy + dummy + dummy + dummy + dummy;
    AQUtility.debug("title len", title.length());
    String url = "https://chart.googleapis.com/chart?chid=1234&cht=lc&chtt=" + title + "&chs=300x200&chxt=x&chd=t:40,20,50,20,100";
    AjaxCallback<Bitmap> cb = new AjaxCallback<Bitmap>() {

        @Override
        public void callback(String url, Bitmap bm, AjaxStatus status) {
            done(url, bm, status);
        }
    };
    aq.ajax(url, Bitmap.class, 15 * 60 * 1000, cb);
    waitAsync(2000);
    assertNotNull(result);
    File cached = aq.getCachedFile(url);
    assertTrue(cached.exists());
    assertTrue(cached.length() > 100);
}
Also used : Bitmap(android.graphics.Bitmap) 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 39 with AjaxStatus

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

the class AQueryAsyncTest method testAjaxPostMultiWithProxy.

public void testAjaxPostMultiWithProxy() {
    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;
        }
    };
    cb.proxy("192.168.0.102", 3128);
    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"));
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JsonObject(com.google.gson.JsonObject) 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 40 with AjaxStatus

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

the class AQueryAsyncTest method testAjaxPutNamedValues.

public void testAjaxPutNamedValues() throws UnsupportedEncodingException {
    List<NameValuePair> pairs = new ArrayList<NameValuePair>();
    pairs.add(new BasicNameValuePair("count", "5"));
    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs, "UTF-8");
    entity.setContentType("application/x-www-form-urlencoded;charset=UTF-8");
    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);
        }
    };
    aq.put(url, "application/x-www-form-urlencoded;charset=UTF-8", entity, JSONObject.class, cb);
    waitAsync();
    JSONObject jo = (JSONObject) result;
    AQUtility.debug(jo);
    assertNotNull(jo);
    JSONObject params = jo.optJSONObject("params");
    assertEquals("5", params.optString("count"));
//assertEquals("PUT", jo.optString("method"));
}
Also used : NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) JSONObject(org.json.JSONObject) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) 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