diff options
Diffstat (limited to 'eaaf_core_utils/src/test')
-rw-r--r-- | eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java b/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java index c88e05d5..baedadc8 100644 --- a/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java +++ b/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java @@ -1,5 +1,6 @@ package at.gv.egiz.eaaf.core.test.http; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.net.HttpURLConnection; import java.net.InetAddress; @@ -10,11 +11,13 @@ import java.security.Provider; import java.security.cert.X509Certificate; import org.apache.commons.lang3.RandomStringUtils; +import org.apache.http.StatusLine; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.entity.ContentType; import org.apache.http.impl.client.CloseableHttpClient; import org.junit.After; import org.junit.Assert; @@ -30,8 +33,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import at.gv.egiz.eaaf.core.exceptions.EaafException; import at.gv.egiz.eaaf.core.impl.credential.EaafKeyStoreFactory; import at.gv.egiz.eaaf.core.impl.data.Pair; +import at.gv.egiz.eaaf.core.impl.data.Triple; import at.gv.egiz.eaaf.core.impl.http.HttpClientConfiguration; +import at.gv.egiz.eaaf.core.impl.http.HttpUtils; import at.gv.egiz.eaaf.core.impl.http.IHttpClientFactory; +import at.gv.egiz.eaaf.core.impl.utils.StreamUtils; import okhttp3.HttpUrl; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; @@ -238,8 +244,9 @@ public class HttpClientFactoryTest { //request webservice final HttpUriRequest httpGet1 = new HttpPost(mockServerUrl.url().toString()); - final CloseableHttpResponse httpResp1 = client.execute(httpGet1); - Assert.assertEquals("http statusCode", 200, httpResp1.getStatusLine().getStatusCode()); + final StatusLine httpResp1 = client.execute(httpGet1, + HttpUtils.simpleStatusCodeResponseHandler()); + Assert.assertEquals("http statusCode", 200, httpResp1.getStatusCode()); } @@ -252,21 +259,26 @@ public class HttpClientFactoryTest { final CloseableHttpClient client = httpClientFactory.getHttpClient(config); Assert.assertNotNull("No httpClient", client); - + mockWebServer = new MockWebServer(); mockServerUrl = mockWebServer.url("/sp/junit"); mockWebServer.enqueue(new MockResponse() .setSocketPolicy(SocketPolicy.NO_RESPONSE) .setResponseCode(HttpURLConnection.HTTP_NO_CONTENT)); + + String bodyData = RandomStringUtils.randomAlphanumeric(10); mockWebServer.enqueue(new MockResponse().setResponseCode(200) - .setBody("GetData")); + .setBody(bodyData)); //request webservice final HttpUriRequest httpGet1 = new HttpGet(mockServerUrl.url().toString()); - final CloseableHttpResponse httpResp1 = client.execute(httpGet1); - Assert.assertEquals("http statusCode", 200, httpResp1.getStatusLine().getStatusCode()); - + final Triple<StatusLine, ByteArrayInputStream, ContentType> httpResp1 = client.execute(httpGet1, + HttpUtils.bodyStatusCodeResponseHandler()); + Assert.assertEquals("http statusCode", 200, httpResp1.getFirst().getStatusCode()); + Assert.assertEquals("http statusCode", bodyData, new String(StreamUtils.readStream(httpResp1.getSecond()))); + + } @Test |