forked from Archives/Athou_commafeed
add a test case for feeds that do not return a content length
This commit is contained in:
@@ -17,6 +17,7 @@ import org.junit.jupiter.params.ParameterizedTest;
|
|||||||
import org.junit.jupiter.params.provider.ValueSource;
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
import org.mockserver.client.MockServerClient;
|
import org.mockserver.client.MockServerClient;
|
||||||
import org.mockserver.junit.jupiter.MockServerExtension;
|
import org.mockserver.junit.jupiter.MockServerExtension;
|
||||||
|
import org.mockserver.model.ConnectionOptions;
|
||||||
import org.mockserver.model.Delay;
|
import org.mockserver.model.Delay;
|
||||||
import org.mockserver.model.HttpRequest;
|
import org.mockserver.model.HttpRequest;
|
||||||
import org.mockserver.model.HttpResponse;
|
import org.mockserver.model.HttpResponse;
|
||||||
@@ -51,7 +52,7 @@ class HttpGetterTest {
|
|||||||
ApplicationSettings settings = new ApplicationSettings();
|
ApplicationSettings settings = new ApplicationSettings();
|
||||||
settings.setUserAgent("http-getter-test");
|
settings.setUserAgent("http-getter-test");
|
||||||
settings.setBackgroundThreads(3);
|
settings.setBackgroundThreads(3);
|
||||||
settings.setMaxFeedResponseSize(DataSize.kilobytes(1));
|
settings.setMaxFeedResponseSize(DataSize.kilobytes(10));
|
||||||
|
|
||||||
CommaFeedConfiguration config = new CommaFeedConfiguration();
|
CommaFeedConfiguration config = new CommaFeedConfiguration();
|
||||||
config.setApplicationSettings(settings);
|
config.setApplicationSettings(settings);
|
||||||
@@ -175,12 +176,25 @@ class HttpGetterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void largeFeedWithContentLengthHeader() {
|
void largeFeedWithContentLengthHeader() {
|
||||||
byte[] bytes = new byte[(int) DataSize.kilobytes(10).toBytes()];
|
byte[] bytes = new byte[(int) DataSize.kilobytes(100).toBytes()];
|
||||||
Arrays.fill(bytes, (byte) 1);
|
Arrays.fill(bytes, (byte) 1);
|
||||||
this.mockServerClient.when(HttpRequest.request().withMethod("GET")).respond(HttpResponse.response().withBody(bytes));
|
this.mockServerClient.when(HttpRequest.request().withMethod("GET")).respond(HttpResponse.response().withBody(bytes));
|
||||||
|
|
||||||
IOException e = Assertions.assertThrows(IOException.class, () -> getter.getBinary(this.feedUrl, TIMEOUT));
|
IOException e = Assertions.assertThrows(IOException.class, () -> getter.getBinary(this.feedUrl, TIMEOUT));
|
||||||
Assertions.assertEquals("Response size (10000 bytes) exceeds the maximum allowed size (1000 bytes)", e.getMessage());
|
Assertions.assertEquals("Response size (100000 bytes) exceeds the maximum allowed size (10000 bytes)", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void largeFeedWithoutContentLengthHeader() {
|
||||||
|
byte[] bytes = new byte[(int) DataSize.kilobytes(100).toBytes()];
|
||||||
|
Arrays.fill(bytes, (byte) 1);
|
||||||
|
this.mockServerClient.when(HttpRequest.request().withMethod("GET"))
|
||||||
|
.respond(HttpResponse.response()
|
||||||
|
.withBody(bytes)
|
||||||
|
.withConnectionOptions(ConnectionOptions.connectionOptions().withSuppressContentLengthHeader(true)));
|
||||||
|
|
||||||
|
IOException e = Assertions.assertThrows(IOException.class, () -> getter.getBinary(this.feedUrl, TIMEOUT));
|
||||||
|
Assertions.assertEquals("Response size exceeds the maximum allowed size (10000 bytes)", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user