@@ -31,68 +31,67 @@ import java.net.http.HttpResponse.ResponseInfo
3131import java.nio.charset.StandardCharsets
3232
3333internal class DecompressingSubscriberIntegrationTest {
34- private val client = HttpClient .newHttpClient()
34+ private val client = HttpClient .newHttpClient()
3535
36- @RegisterExtension
37- var wm = WireMockExtension .newInstance()
38- .configureStaticDsl( true )
39- .failOnUnmatchedRequests( true )
40- .options( WireMockConfiguration .wireMockConfig().dynamicPort())
41- .build()
36+ @RepeatedTest( 8 )
37+ fun shouldDecompressLargeBodyWithStringHandler () {
38+ // given
39+ val data = setupLargeBodyDecompressionTest( )
40+ val request = data.request
41+ val expectedBody = data.expectedBody
4242
43- @RepeatedTest(32 )
44- @Throws(Exception ::class )
45- fun shouldDecompressLargeBodyWithStringHandler () {
46- // given
47- val data = setupLargeBodyDecompressionTest()
48- val request = data.request
49- val expectedBody = data.expectedBody
43+ // when
44+ val stringResponse = client.send(request) { info: ResponseInfo ? ->
45+ DecompressingSubscriber (
46+ HttpResponse .BodyHandlers .ofString().apply (info)
47+ )
48+ }
5049
51- // when
52- val stringResponse = client.send(request) { info: ResponseInfo ? ->
53- DecompressingSubscriber (
54- HttpResponse .BodyHandlers .ofString().apply (info)
55- )
56- }
50+ // then
51+ org.junit.jupiter.api.Assertions .assertEquals(expectedBody.length, stringResponse.body().length)
52+ Assertions .assertThat(stringResponse).hasBody(expectedBody)
53+ }
5754
58- // then
59- org.junit.jupiter.api.Assertions .assertEquals(expectedBody.length, stringResponse.body().length)
60- Assertions .assertThat(stringResponse).hasBody(expectedBody)
55+ @RepeatedTest(1 )
56+ @Disabled(" Having problems with InputStream" )
57+ fun shouldHandleLargeBodyWithInputStream () {
58+ // given
59+ val data = setupLargeBodyDecompressionTest()
60+ val request = data.request
61+ val expectedBody = data.expectedBody
62+
63+ // when
64+ val response = client.send(request) { info: ResponseInfo ? ->
65+ DecompressingSubscriber (
66+ HttpResponse .BodyHandlers .ofInputStream().apply (info)
67+ )
6168 }
69+ val body = IOUtils .toString(response.body(), StandardCharsets .UTF_8 )
70+ org.junit.jupiter.api.Assertions .assertEquals(expectedBody.length, body.length)
71+ org.junit.jupiter.api.Assertions .assertEquals(expectedBody, body)
72+ }
6273
63- @RepeatedTest(1 )
64- @Disabled(" Having problems with InputStream" )
65- @Throws(
66- Exception ::class
74+ private fun setupLargeBodyDecompressionTest (body : String = RandomStringUtils .randomAlphabetic(16384 * 10)): LargeBodyDataDecompression {
75+ val gzippedBody = Compression .gzip(body)
76+ val testUrl = " /gzip"
77+ WireMock .stubFor(
78+ WireMock .get(WireMock .urlEqualTo(testUrl))
79+ .willReturn(WireMock .ok().withBody(gzippedBody))
6780 )
68- fun shouldHandleLargeBodyWithInputStream () {
69- // given
70- val data = setupLargeBodyDecompressionTest()
71- val request = data.request
72- val expectedBody = data.expectedBody
81+ val uri = URI .create(wm.runtimeInfo.httpBaseUrl).resolve(testUrl)
82+ val request = HttpRequest .newBuilder(uri).build()
83+ return LargeBodyDataDecompression (request, body)
84+ }
7385
74- // when
75- val response = client.send(request) { info: ResponseInfo ? ->
76- DecompressingSubscriber (
77- HttpResponse .BodyHandlers .ofInputStream().apply (info)
78- )
79- }
80- val body = IOUtils .toString(response.body(), StandardCharsets .UTF_8 )
81- org.junit.jupiter.api.Assertions .assertEquals(expectedBody.length, body.length)
82- org.junit.jupiter.api.Assertions .assertEquals(expectedBody, body)
83- }
86+ internal data class LargeBodyDataDecompression (val request : HttpRequest , val expectedBody : String )
8487
85- private fun setupLargeBodyDecompressionTest (body : String = RandomStringUtils .randomAlphabetic(16384 * 10)): LargeBodyDataDecompression {
86- val gzippedBody = Compression .gzip(body)
87- val testUrl = " /gzip"
88- WireMock .stubFor(
89- WireMock .get(WireMock .urlEqualTo(testUrl))
90- .willReturn(WireMock .ok().withBody(gzippedBody))
91- )
92- val uri = URI .create(wm.runtimeInfo.httpBaseUrl).resolve(testUrl)
93- val request = HttpRequest .newBuilder(uri).build()
94- return LargeBodyDataDecompression (request, body)
95- }
96-
97- internal class LargeBodyDataDecompression (val request : HttpRequest , val expectedBody : String )
88+ companion object {
89+ @RegisterExtension
90+ @JvmStatic
91+ var wm = WireMockExtension .newInstance()
92+ .configureStaticDsl(true )
93+ .failOnUnmatchedRequests(true )
94+ .options(WireMockConfiguration .wireMockConfig().dynamicPort())
95+ .build()
96+ }
9897}
0 commit comments