Polish contribution and related code
This commit is contained in:
@@ -42,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Sebastien Deleuze
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class ServerSentEventHttpMessageReaderTests extends AbstractLeakCheckingTests {
|
||||
class ServerSentEventHttpMessageReaderTests extends AbstractLeakCheckingTests {
|
||||
|
||||
private Jackson2JsonDecoder jsonDecoder = new Jackson2JsonDecoder();
|
||||
|
||||
@@ -50,20 +50,20 @@ public class ServerSentEventHttpMessageReaderTests extends AbstractLeakCheckingT
|
||||
|
||||
|
||||
@Test
|
||||
public void cantRead() {
|
||||
void cannotRead() {
|
||||
assertThat(reader.canRead(ResolvableType.forClass(Object.class), new MediaType("foo", "bar"))).isFalse();
|
||||
assertThat(reader.canRead(ResolvableType.forClass(Object.class), null)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canRead() {
|
||||
void canRead() {
|
||||
assertThat(reader.canRead(ResolvableType.forClass(Object.class), new MediaType("text", "event-stream"))).isTrue();
|
||||
assertThat(reader.canRead(ResolvableType.forClass(ServerSentEvent.class), new MediaType("foo", "bar"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void readServerSentEvents() {
|
||||
void readServerSentEvents() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/")
|
||||
.body(Mono.just(stringBuffer(
|
||||
"id:c42\nevent:foo\nretry:123\n:bla\n:bla bla\n:bla bla bla\ndata:bar\n\n" +
|
||||
@@ -96,7 +96,7 @@ public class ServerSentEventHttpMessageReaderTests extends AbstractLeakCheckingT
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void readServerSentEventsWithMultipleChunks() {
|
||||
void readServerSentEventsWithMultipleChunks() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/")
|
||||
.body(Flux.just(
|
||||
stringBuffer("id:c42\nev"),
|
||||
@@ -127,7 +127,7 @@ public class ServerSentEventHttpMessageReaderTests extends AbstractLeakCheckingT
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readString() {
|
||||
void readString() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/")
|
||||
.body(Mono.just(stringBuffer("data:foo\ndata:bar\n\ndata:baz\n\n")));
|
||||
|
||||
@@ -142,7 +142,7 @@ public class ServerSentEventHttpMessageReaderTests extends AbstractLeakCheckingT
|
||||
}
|
||||
|
||||
@Test
|
||||
public void trimWhitespace() {
|
||||
void trimWhitespace() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/")
|
||||
.body(Mono.just(stringBuffer("data: \tfoo \ndata:bar\t\n\n")));
|
||||
|
||||
@@ -156,15 +156,14 @@ public class ServerSentEventHttpMessageReaderTests extends AbstractLeakCheckingT
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readPojo() {
|
||||
void readPojo() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/")
|
||||
.body(Mono.just(stringBuffer(
|
||||
"""
|
||||
data:{"foo": "foofoo", "bar": "barbar"}
|
||||
.body(Mono.just(stringBuffer("""
|
||||
data:{"foo": "foofoo", "bar": "barbar"}
|
||||
|
||||
data:{"foo": "foofoofoo", "bar": "barbarbar"}
|
||||
data:{"foo": "foofoofoo", "bar": "barbarbar"}
|
||||
|
||||
""")));
|
||||
""")));
|
||||
|
||||
Flux<Pojo> data = reader.read(ResolvableType.forClass(Pojo.class), request,
|
||||
Collections.emptyMap()).cast(Pojo.class);
|
||||
@@ -194,7 +193,7 @@ public class ServerSentEventHttpMessageReaderTests extends AbstractLeakCheckingT
|
||||
}
|
||||
|
||||
@Test // SPR-15331
|
||||
public void decodeFullContentAsString() {
|
||||
void decodeFullContentAsString() {
|
||||
String body = "data:foo\ndata:bar\n\ndata:baz\n\n";
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/")
|
||||
.body(Mono.just(stringBuffer(body)));
|
||||
@@ -208,13 +207,11 @@ public class ServerSentEventHttpMessageReaderTests extends AbstractLeakCheckingT
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readError() {
|
||||
Flux<DataBuffer> body =
|
||||
Flux.just(stringBuffer("data:foo\ndata:bar\n\ndata:baz\n\n"))
|
||||
.concatWith(Flux.error(new RuntimeException()));
|
||||
void readError() {
|
||||
Flux<DataBuffer> body = Flux.just(stringBuffer("data:foo\ndata:bar\n\ndata:baz\n\n"))
|
||||
.concatWith(Flux.error(new RuntimeException()));
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/")
|
||||
.body(body);
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/").body(body);
|
||||
|
||||
Flux<String> data = reader.read(ResolvableType.forClass(String.class),
|
||||
request, Collections.emptyMap()).cast(String.class);
|
||||
@@ -227,7 +224,7 @@ public class ServerSentEventHttpMessageReaderTests extends AbstractLeakCheckingT
|
||||
}
|
||||
|
||||
@Test
|
||||
public void maxInMemoryLimit() {
|
||||
void maxInMemoryLimit() {
|
||||
this.reader.setMaxInMemorySize(17);
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/")
|
||||
@@ -242,10 +239,10 @@ public class ServerSentEventHttpMessageReaderTests extends AbstractLeakCheckingT
|
||||
}
|
||||
|
||||
@Test // gh-24312
|
||||
public void maxInMemoryLimitAllowsReadingPojoLargerThanDefaultSize() {
|
||||
void maxInMemoryLimitAllowsReadingPojoLargerThanDefaultSize() {
|
||||
int limit = this.jsonDecoder.getMaxInMemorySize();
|
||||
|
||||
String fooValue = getStringOfSize(limit) + "and then some more";
|
||||
String fooValue = "x".repeat(limit) + " and then some more";
|
||||
String content = "data:{\"foo\": \"" + fooValue + "\"}\n\n";
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/").body(Mono.just(stringBuffer(content)));
|
||||
|
||||
@@ -272,12 +269,4 @@ public class ServerSentEventHttpMessageReaderTests extends AbstractLeakCheckingT
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private static String getStringOfSize(long size) {
|
||||
StringBuilder content = new StringBuilder("Aa");
|
||||
while (content.length() < size) {
|
||||
content.append(content);
|
||||
}
|
||||
return content.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class StandardMultipartHttpServletRequestTests {
|
||||
class StandardMultipartHttpServletRequestTests {
|
||||
|
||||
@Test
|
||||
public void filename() throws Exception {
|
||||
void filename() {
|
||||
String disposition = "form-data; name=\"file\"; filename=\"myFile.txt\"";
|
||||
StandardMultipartHttpServletRequest request = requestWithPart("file", disposition, "");
|
||||
|
||||
@@ -49,7 +49,7 @@ public class StandardMultipartHttpServletRequestTests {
|
||||
}
|
||||
|
||||
@Test // SPR-13319
|
||||
public void filenameRfc5987() throws Exception {
|
||||
void filenameRfc5987() {
|
||||
String disposition = "form-data; name=\"file\"; filename*=\"UTF-8''foo-%c3%a4-%e2%82%ac.html\"";
|
||||
StandardMultipartHttpServletRequest request = requestWithPart("file", disposition, "");
|
||||
|
||||
@@ -59,7 +59,7 @@ public class StandardMultipartHttpServletRequestTests {
|
||||
}
|
||||
|
||||
@Test // SPR-15205
|
||||
public void filenameRfc2047() throws Exception {
|
||||
void filenameRfc2047() {
|
||||
String disposition = "form-data; name=\"file\"; filename=\"=?UTF-8?Q?Declara=C3=A7=C3=A3o.pdf?=\"";
|
||||
StandardMultipartHttpServletRequest request = requestWithPart("file", disposition, "");
|
||||
|
||||
@@ -69,7 +69,7 @@ public class StandardMultipartHttpServletRequestTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartFileResource() throws IOException {
|
||||
void multipartFileResource() throws IOException {
|
||||
String name = "file";
|
||||
String disposition = "form-data; name=\"" + name + "\"; filename=\"myFile.txt\"";
|
||||
StandardMultipartHttpServletRequest request = requestWithPart(name, disposition, "myBody");
|
||||
@@ -83,18 +83,17 @@ public class StandardMultipartHttpServletRequestTests {
|
||||
MockHttpOutputMessage output = new MockHttpOutputMessage();
|
||||
new FormHttpMessageConverter().write(map, null, output);
|
||||
|
||||
assertThat(output.getBodyAsString(StandardCharsets.UTF_8)).contains(
|
||||
"""
|
||||
Content-Disposition: form-data; name="file"; filename="myFile.txt"\r
|
||||
Content-Type: text/plain\r
|
||||
Content-Length: 6\r
|
||||
\r
|
||||
myBody\r
|
||||
""");
|
||||
assertThat(output.getBodyAsString(StandardCharsets.UTF_8)).contains("""
|
||||
Content-Disposition: form-data; name="file"; filename="myFile.txt"
|
||||
Content-Type: text/plain
|
||||
Content-Length: 6
|
||||
|
||||
myBody
|
||||
""".replace("\n", "\r\n"));
|
||||
}
|
||||
|
||||
|
||||
private StandardMultipartHttpServletRequest requestWithPart(String name, String disposition, String content) {
|
||||
private static StandardMultipartHttpServletRequest requestWithPart(String name, String disposition, String content) {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
MockPart part = new MockPart(name, null, content.getBytes(StandardCharsets.UTF_8));
|
||||
part.getHeaders().set("Content-Disposition", disposition);
|
||||
|
||||
Reference in New Issue
Block a user