1414import org .junit .jupiter .api .Test ;
1515import org .junit .jupiter .api .extension .ExtendWith ;
1616
17+ import java .io .ByteArrayInputStream ;
18+ import java .io .ByteArrayOutputStream ;
1719import java .io .IOException ;
1820import java .io .OutputStream ;
1921import java .io .Writer ;
2022import java .net .ServerSocket ;
23+ import java .nio .charset .StandardCharsets ;
2124import java .util .concurrent .TimeUnit ;
2225import java .util .stream .Collectors ;
2326import java .util .stream .IntStream ;
27+ import java .util .zip .GZIPInputStream ;
2428
2529import static java .lang .String .format ;
2630import static org .hamcrest .MatcherAssert .assertThat ;
@@ -100,7 +104,6 @@ void it_sends_the_body_once_for_202_and_location_with_get_without_token(Vertx ve
100104 if (exception != null ) {
101105 throw exception ;
102106 }
103- assertThat (testServer .receivedBody .toString ("utf-8" ), is (equalTo (requestBody )));
104107 }
105108
106109 @ Test
@@ -225,11 +228,10 @@ public void start(Promise<Void> startPromise) {
225228
226229 ctx .request ().handler (receivedBody ::appendBuffer );
227230 ctx .request ().endHandler (e -> {
228- String receivedBodyString = receivedBody .toString ("utf-8" );
229231 ctx .response ().setChunked (true );
230232 ctx .response ().write (responseBody );
231233 ctx .response ().end ();
232- testContext .verify (() -> assertThat (receivedBodyString , is (equalTo (expectedBody ))));
234+ testContext .verify (() -> assertThat (unzipBody () , is (equalTo (expectedBody ))));
233235 });
234236 });
235237 });
@@ -239,6 +241,21 @@ public void start(Promise<Void> startPromise) {
239241 .listen (port , e -> startPromise .complete ());
240242 }
241243
244+ private String unzipBody () {
245+ ByteArrayOutputStream out = new ByteArrayOutputStream ();
246+ ByteArrayInputStream compressedIn = new ByteArrayInputStream (receivedBody .getBytes ());
247+ byte [] buffer = new byte [4096 ];
248+ try (GZIPInputStream uncompressedIn = new GZIPInputStream (compressedIn )) {
249+ int read ;
250+ while ((read = uncompressedIn .read (buffer , 0 , buffer .length )) != -1 ) {
251+ out .write (buffer , 0 , read );
252+ }
253+ } catch (IOException ex ) {
254+ throw new IllegalStateException (ex );
255+ }
256+ return new String (out .toByteArray (), StandardCharsets .UTF_8 );
257+ }
258+
242259 }
243260
244261}
0 commit comments