mirror of
https://github.com/Athou/commafeed.git
synced 2026-10-07 04:44:50 +00:00
Merge pull request #2208 from Athou/renovate/org.mock-server-mockserver-junit-jupiter-7.x
chore(deps): update dependency org.mock-server:mockserver-junit-jupiter to v7.3.0
This commit is contained in:
@@ -477,7 +477,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mock-server</groupId>
|
<groupId>org.mock-server</groupId>
|
||||||
<artifactId>mockserver-junit-jupiter</artifactId>
|
<artifactId>mockserver-junit-jupiter</artifactId>
|
||||||
<version>7.2.0</version>
|
<version>7.3.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.commafeed.backend;
|
package com.commafeed.backend;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.net.NoRouteToHostException;
|
import java.net.NoRouteToHostException;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
@@ -11,6 +13,8 @@ import java.util.Arrays;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.zip.DeflaterOutputStream;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.hc.client5.http.ConnectTimeoutException;
|
import org.apache.hc.client5.http.ConnectTimeoutException;
|
||||||
@@ -315,15 +319,15 @@ class HttpGetterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void gzip() throws Exception {
|
void gzip() throws Exception {
|
||||||
supportsCompression("gzip");
|
supportsCompression("gzip", GZIPOutputStream::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void deflate() throws Exception {
|
void deflate() throws Exception {
|
||||||
supportsCompression("deflate");
|
supportsCompression("deflate", DeflaterOutputStream::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
void supportsCompression(String encoding) throws Exception {
|
void supportsCompression(String encoding, CompressionFunction compressionFunction) throws Exception {
|
||||||
String body = "my body";
|
String body = "my body";
|
||||||
|
|
||||||
HttpGetterTest.this.mockServerClient.when(HttpRequest.request().withMethod("GET")).respond(req -> {
|
HttpGetterTest.this.mockServerClient.when(HttpRequest.request().withMethod("GET")).respond(req -> {
|
||||||
@@ -333,14 +337,23 @@ class HttpGetterTest {
|
|||||||
acceptEncodingHeader));
|
acceptEncodingHeader));
|
||||||
}
|
}
|
||||||
|
|
||||||
// MockServer 6.x automatically compresses the body based on the Content-Encoding header
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||||
return HttpResponse.response().withBody(body.getBytes()).withHeader(HttpHeaders.CONTENT_ENCODING, encoding);
|
try (OutputStream compressionOutputStream = compressionFunction.apply(output)) {
|
||||||
|
compressionOutputStream.write(body.getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
return HttpResponse.response().withBody(output.toByteArray()).withHeader(HttpHeaders.CONTENT_ENCODING, encoding);
|
||||||
});
|
});
|
||||||
|
|
||||||
HttpResult result = getter.get(HttpGetterTest.this.feedUrl);
|
HttpResult result = getter.get(HttpGetterTest.this.feedUrl);
|
||||||
Assertions.assertEquals(body, new String(result.content()));
|
Assertions.assertEquals(body, new String(result.content()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface CompressionFunction {
|
||||||
|
OutputStream apply(OutputStream input) throws IOException;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
|
|||||||
Reference in New Issue
Block a user