11package org .baeldung .httpclient ;
22
33import static org .hamcrest .Matchers .emptyArray ;
4- import static org .hamcrest .Matchers .equalTo ;
54import static org .hamcrest .Matchers .not ;
6- import static org .hamcrest .Matchers .notNullValue ;
75import static org .junit .Assert .assertThat ;
86
97import java .io .IOException ;
1614import org .apache .http .client .config .RequestConfig ;
1715import org .apache .http .client .methods .CloseableHttpResponse ;
1816import org .apache .http .client .methods .HttpGet ;
19- import org .apache .http .client .methods .HttpPost ;
2017import org .apache .http .conn .ConnectTimeoutException ;
21- import org .apache .http .entity .ContentType ;
2218import org .apache .http .impl .client .CloseableHttpClient ;
2319import org .apache .http .impl .client .DefaultHttpClient ;
2420import org .apache .http .impl .client .HttpClientBuilder ;
2521import org .apache .http .impl .client .HttpClients ;
2622import org .apache .http .impl .conn .BasicHttpClientConnectionManager ;
2723import org .apache .http .params .CoreProtocolPNames ;
2824import org .apache .http .params .HttpProtocolParams ;
29- import org .apache .http .util .EntityUtils ;
3025import org .junit .After ;
3126import org .junit .Before ;
3227import org .junit .Test ;
@@ -63,35 +58,6 @@ public final void after() throws IllegalStateException, IOException {
6358
6459 // tests
6560
66- // simple request - response
67-
68- @ Test
69- public final void whenExecutingBasicGetRequest_thenNoExceptions () throws ClientProtocolException , IOException {
70- response = instance .execute (new HttpGet (SAMPLE_URL ));
71- }
72-
73- @ Test
74- public final void givenGetRequestExecuted_whenAnalyzingTheResponse_thenCorrectStatusCode () throws ClientProtocolException , IOException {
75- response = instance .execute (new HttpGet (SAMPLE_URL ));
76- assertThat (response .getStatusLine ().getStatusCode (), equalTo (200 ));
77- }
78-
79- @ Test
80- public final void givenGetRequestExecuted_whenAnalyzingTheResponse_thenCorrectMimeType () throws ClientProtocolException , IOException {
81- response = instance .execute (new HttpGet (SAMPLE_URL ));
82- final String contentMimeType = ContentType .getOrDefault (response .getEntity ()).getMimeType ();
83-
84- assertThat (contentMimeType , equalTo (ContentType .TEXT_HTML .getMimeType ()));
85- }
86-
87- @ Test
88- public final void givenGetRequestExecuted_whenAnalyzingTheResponse_thenCorrectBody () throws ClientProtocolException , IOException {
89- response = instance .execute (new HttpGet (SAMPLE_URL ));
90- final String bodyAsString = EntityUtils .toString (response .getEntity ());
91-
92- assertThat (bodyAsString , notNullValue ());
93- }
94-
9561 @ Test (expected = ConnectTimeoutException .class )
9662 public final void givenLowTimeout_whenExecutingRequestWithTimeout_thenException () throws ClientProtocolException , IOException {
9763 final RequestConfig requestConfig = RequestConfig .custom ().setConnectionRequestTimeout (50 ).setConnectTimeout (50 ).setSocketTimeout (20 ).build ();
@@ -100,13 +66,6 @@ public final void givenLowTimeout_whenExecutingRequestWithTimeout_thenException(
10066 response = instance .execute (request );
10167 }
10268
103- // tests - non-GET
104-
105- @ Test
106- public final void whenExecutingBasicRequest_thenNoExceptions () throws ClientProtocolException , IOException {
107- instance .execute (new HttpPost (SAMPLE_URL ));
108- }
109-
11069 // tests - configs
11170
11271 @ Test
0 commit comments