Search in sources :

Example 51 with AjaxStatus

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);
}
Also used : ProxyHandle(com.androidquery.callback.ProxyHandle) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 52 with AjaxStatus

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"));
}
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 53 with AjaxStatus

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());
}
Also used : Cookie(org.apache.http.cookie.Cookie) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 54 with AjaxStatus

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);
}
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 55 with AjaxStatus

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());
}
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)

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