Update httpClient test

This commit is contained in:
DOHA 2014-11-25 14:03:28 +02:00
parent d042d236f1
commit 13f7e2a692
2 changed files with 179 additions and 184 deletions

View File

@ -15,9 +15,7 @@ import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -33,10 +31,7 @@ public class HttpClientUnshortenLiveTest {
@Before @Before
public final void before() { public final void before() {
final HttpParams httpParameters = new BasicHttpParams(); client = HttpClientBuilder.create().disableRedirectHandling().build();
httpParameters.setParameter("http.protocol.handle-redirects", false);
client = new DefaultHttpClient(httpParameters);
} }
// tests // tests

View File

@ -8,12 +8,12 @@ import java.io.InputStream;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException; import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.BasicCookieStore; import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.cookie.BasicClientCookie; import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.BasicHttpContext;
@ -70,12 +70,12 @@ public class HttpClientCookieLiveTest {
cookie.setDomain(".github.com"); cookie.setDomain(".github.com");
cookie.setPath("/"); cookie.setPath("/");
cookieStore.addCookie(cookie); cookieStore.addCookie(cookie);
final DefaultHttpClient client = new DefaultHttpClient(); final HttpClient client = HttpClientBuilder.create()
client.setCookieStore(cookieStore); .setDefaultCookieStore(cookieStore).build();
final HttpGet request = new HttpGet("http://www.github.com"); final HttpGet request = new HttpGet("http://www.github.com");
response = client.execute(request); response = (CloseableHttpResponse) client.execute(request);
assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
} }