1
1
/*
2
- * Copyright 2002-2020 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
40
40
* Unit tests for {@link ServerSentEventHttpMessageReader}.
41
41
*
42
42
* @author Sebastien Deleuze
43
+ * @author Juergen Hoeller
43
44
*/
44
45
public class ServerSentEventHttpMessageReaderTests extends AbstractLeakCheckingTests {
45
46
@@ -66,7 +67,7 @@ public void readServerSentEvents() {
66
67
MockServerHttpRequest request = MockServerHttpRequest .post ("/" )
67
68
.body (Mono .just (stringBuffer (
68
69
"id:c42\n event:foo\n retry:123\n :bla\n :bla bla\n :bla bla bla\n data:bar\n \n " +
69
- "id:c43\n event:bar\n retry:456\n data:baz\n \n " )));
70
+ "id:c43\n event:bar\n retry:456\n data:baz\n \n data: \n \n data: \n \ n " )));
70
71
71
72
Flux <ServerSentEvent > events = this .reader
72
73
.read (ResolvableType .forClassWithGenerics (ServerSentEvent .class , String .class ),
@@ -87,6 +88,8 @@ public void readServerSentEvents() {
87
88
assertThat (event .comment ()).isNull ();
88
89
assertThat (event .data ()).isEqualTo ("baz" );
89
90
})
91
+ .consumeNextWith (event -> assertThat (event .data ()).isNull ())
92
+ .consumeNextWith (event -> assertThat (event .data ()).isNull ())
90
93
.expectComplete ()
91
94
.verify ();
92
95
}
@@ -175,7 +178,7 @@ public void readPojo() {
175
178
.verify ();
176
179
}
177
180
178
- @ Test // gh-24389
181
+ @ Test // gh-24389
179
182
void readPojoWithCommentOnly () {
180
183
MockServerHttpRequest request = MockServerHttpRequest .post ("/" )
181
184
.body (Flux .just (stringBuffer (":ping\n " ), stringBuffer ("\n " )));
@@ -221,7 +224,6 @@ public void readError() {
221
224
222
225
@ Test
223
226
public void maxInMemoryLimit () {
224
-
225
227
this .reader .setMaxInMemorySize (17 );
226
228
227
229
MockServerHttpRequest request = MockServerHttpRequest .post ("/" )
@@ -235,9 +237,8 @@ public void maxInMemoryLimit() {
235
237
.verify ();
236
238
}
237
239
238
- @ Test // gh-24312
240
+ @ Test // gh-24312
239
241
public void maxInMemoryLimitAllowsReadingPojoLargerThanDefaultSize () {
240
-
241
242
int limit = this .jsonDecoder .getMaxInMemorySize ();
242
243
243
244
String fooValue = getStringOfSize (limit ) + "and then some more" ;
@@ -259,13 +260,6 @@ public void maxInMemoryLimitAllowsReadingPojoLargerThanDefaultSize() {
259
260
.verify ();
260
261
}
261
262
262
- private static String getStringOfSize (long size ) {
263
- StringBuilder content = new StringBuilder ("Aa" );
264
- while (content .length () < size ) {
265
- content .append (content );
266
- }
267
- return content .toString ();
268
- }
269
263
270
264
private DataBuffer stringBuffer (String value ) {
271
265
byte [] bytes = value .getBytes (StandardCharsets .UTF_8 );
@@ -274,4 +268,12 @@ private DataBuffer stringBuffer(String value) {
274
268
return buffer ;
275
269
}
276
270
271
+ private static String getStringOfSize (long size ) {
272
+ StringBuilder content = new StringBuilder ("Aa" );
273
+ while (content .length () < size ) {
274
+ content .append (content );
275
+ }
276
+ return content .toString ();
277
+ }
278
+
277
279
}
0 commit comments