Home | History | Annotate | Download | only in shadows
      1 package com.xtremelabs.robolectric.shadows;
      2 
      3 import com.xtremelabs.robolectric.Robolectric;
      4 import com.xtremelabs.robolectric.internal.Implementation;
      5 import com.xtremelabs.robolectric.internal.Implements;
      6 import com.xtremelabs.robolectric.internal.RealObject;
      7 import org.apache.http.HttpHost;
      8 import org.apache.http.HttpRequest;
      9 import org.apache.http.HttpResponse;
     10 import org.apache.http.client.ClientProtocolException;
     11 import org.apache.http.client.HttpClient;
     12 import org.apache.http.client.ResponseHandler;
     13 import org.apache.http.client.methods.HttpUriRequest;
     14 import org.apache.http.conn.ClientConnectionManager;
     15 import org.apache.http.impl.client.DefaultHttpClient;
     16 import org.apache.http.params.HttpParams;
     17 import org.apache.http.protocol.HttpContext;
     18 
     19 import android.content.Context;
     20 import android.net.http.AndroidHttpClient;
     21 
     22 import java.io.IOException;
     23 
     24 @Implements(AndroidHttpClient.class)
     25 public class ShadowAndroidHttpClient {
     26     @RealObject private AndroidHttpClient client;
     27 
     28     private HttpClient httpClient = new DefaultHttpClient();
     29 
     30     @Implementation
     31     public static AndroidHttpClient newInstance(String userAgent) {
     32         return Robolectric.newInstanceOf(AndroidHttpClient.class);
     33     }
     34 
     35     @Implementation
     36     public static AndroidHttpClient newInstance(String userAgent, Context context) {
     37         return Robolectric.newInstanceOf(AndroidHttpClient.class);
     38     }
     39 
     40     @Implementation
     41     public HttpParams getParams() {
     42         return httpClient.getParams();
     43     }
     44 
     45     @Implementation
     46     public ClientConnectionManager getConnectionManager() {
     47         return httpClient.getConnectionManager();
     48     }
     49 
     50     @Implementation
     51     public HttpResponse execute(HttpUriRequest httpUriRequest) throws IOException, ClientProtocolException {
     52         return httpClient.execute(httpUriRequest);
     53     }
     54 
     55     @Implementation
     56     public HttpResponse execute(HttpUriRequest httpUriRequest, HttpContext httpContext) throws IOException, ClientProtocolException {
     57         return httpClient.execute(httpUriRequest, httpContext);
     58     }
     59 
     60     @Implementation
     61     public HttpResponse execute(HttpHost httpHost, HttpRequest httpRequest) throws IOException, ClientProtocolException {
     62         return httpClient.execute(httpHost, httpRequest);
     63     }
     64 
     65     @Implementation
     66     public HttpResponse execute(HttpHost httpHost, HttpRequest httpRequest, HttpContext httpContext) throws IOException, ClientProtocolException {
     67         return httpClient.execute(httpHost, httpRequest, httpContext);
     68     }
     69 
     70     @Implementation
     71     public <T> T execute(HttpUriRequest httpUriRequest, ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException {
     72         return httpClient.execute(httpUriRequest, responseHandler);
     73     }
     74 
     75     @Implementation
     76     public <T> T execute(HttpUriRequest httpUriRequest, ResponseHandler<? extends T> responseHandler, HttpContext httpContext) throws IOException, ClientProtocolException {
     77         return httpClient.execute(httpUriRequest, responseHandler, httpContext);
     78     }
     79 
     80     @Implementation
     81     public <T> T execute(HttpHost httpHost, HttpRequest httpRequest, ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException {
     82         return httpClient.execute(httpHost, httpRequest, responseHandler);
     83     }
     84 
     85     @Implementation
     86     public <T> T execute(HttpHost httpHost, HttpRequest httpRequest, ResponseHandler<? extends T> responseHandler, HttpContext httpContext) throws IOException, ClientProtocolException {
     87         return httpClient.execute(httpHost, httpRequest, responseHandler, httpContext);
     88     }
     89 }
     90