package com.tsu.junit;

import net.tsz.afinal.FinalHttp;
import net.tsz.afinal.http.AjaxCallBack;
import android.test.AndroidTestCase;

/**
 * 
* @Project: AfinalExceise
* @PackagName: com.tsu.junit
* @ClassName: TestFinalHttp
* @Description: TODO
* @author tadeshanc@gmail.com
* @date 2013-12-31
 */
public class TestFinalHttp extends AndroidTestCase{

	private FinalHttp finalHttp;
	private String URL;
	
	/**
	 * FinalHttpص㣺
	 *  1.ṩ̳߳ز
	 *  2.ṩ get put 
	 *  3.ṩdownload 
	 */
	/**
	 * FinalHttpʵ
	 *  public FinalHttp() {
	 *  
	 * 
	 * 	//ãʱ汾ӷʽȵȣ
        BasicHttpParams httpParams = new BasicHttpParams();
        ConnManagerParams.setTimeout(httpParams, socketTimeout);
        ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(maxConnections));
        ConnManagerParams.setMaxTotalConnections(httpParams, 10);
        HttpConnectionParams.setSoTimeout(httpParams, socketTimeout);
        HttpConnectionParams.setConnectionTimeout(httpParams, socketTimeout);
        HttpConnectionParams.setTcpNoDelay(httpParams, true);
        HttpConnectionParams.setSocketBufferSize(httpParams, DEFAULT_SOCKET_BUFFER_SIZE);
        HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);

		//ʵ httpClient
        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
        ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry);
        httpContext = new SyncBasicHttpContext(new BasicHttpContext());
        
        httpClient = new DefaultHttpClient(cm, httpParams);
        httpClient.addRequestInterceptor(new HttpRequestInterceptor() {
            public void process(HttpRequest request, HttpContext context) {
                if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
                    request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
                }
                for (String header : clientHeaderMap.keySet()) {
                    request.addHeader(header, clientHeaderMap.get(header));
                }
            }
        });

        httpClient.addResponseInterceptor(new HttpResponseInterceptor() {
            public void process(HttpResponse response, HttpContext context) {
                final HttpEntity entity = response.getEntity();
                if (entity == null) {
                    return;
                }
                final Header encoding = entity.getContentEncoding();
                if (encoding != null) {
                    for (HeaderElement element : encoding.getElements()) {
                        if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
                            response.setEntity(new InflatingEntity(response.getEntity()));
                            break;
                        }
                    }
                }
            }
        });
		
		//ӵHandler
        httpClient.setHttpRequestRetryHandler(new RetryHandler(maxRetries));
        //һclientHashMap
        clientHeaderMap = new HashMap<String, String>();
        
    }
	 */
	
	
	
	@Override
	protected void setUp() throws Exception {
		// TODO Auto-generated method stub
		super.setUp();
		//Ҫ2 1.ṩһhttpClient 2.httpParams
		finalHttp = new FinalHttp();
	}
	
	@Override
	protected void tearDown() throws Exception {
		// TODO Auto-generated method stub
		super.tearDown();
		finalHttp = null;
	}

	
	//ʱҷFinalHttp첽ûеԪԣΪȡ,д
	
	public void testGet(){
		finalHttp.get(URL,new AjaxCallBack<String>(){

			// ȽҪ
			@Override
			public void onLoading(long count, long current) {
				// TODO Auto-generated method stub
				super.onLoading(count, current);
			}

			@Override
			public void onSuccess(String t) {
				// TODO Auto-generated method stub
				super.onSuccess(t);
			}

			@Override
			public void onFailure(Throwable t, int errorNo, String strMsg) {
				// TODO Auto-generated method stub
				super.onFailure(t, errorNo, strMsg);
			}
			
		});
	}
}

@@ -3533,18 +3533,26 @@
 %0A%09%7D%0A%0A%09%0A%09
-//
+%0A%09/**%0A%09 * 
 %CA%B1%D2%B7FinalH
@@ -3565,16 +3565,27 @@
 %D4%AA%D4%A3%CE%AA%C8%A1,%D0%B4%0A%09
+ * get%0A%09 */
 %0A%09public

test finalHttp