1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-2019 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
import org .springframework .mock .http .server .reactive .test .MockServerHttpResponse ;
41
41
42
42
import static org .junit .Assert .*;
43
- import static org .springframework .core .ResolvableType .forClass ;
43
+ import static org .springframework .core .ResolvableType .* ;
44
44
45
45
/**
46
46
* Unit tests for {@link ServerSentEventHttpMessageWriter}.
@@ -88,9 +88,8 @@ public void writeServerSentEvent() {
88
88
testWrite (source , outputMessage , ServerSentEvent .class );
89
89
90
90
StepVerifier .create (outputMessage .getBody ())
91
- .consumeNextWith (stringConsumer ("id:c42\n event:foo\n retry:123\n :bla\n :bla bla\n :bla bla bla\n data:" ))
92
- .consumeNextWith (stringConsumer ("bar\n " ))
93
- .consumeNextWith (stringConsumer ("\n " ))
91
+ .consumeNextWith (stringConsumer (
92
+ "id:c42\n event:foo\n retry:123\n :bla\n :bla bla\n :bla bla bla\n data:bar\n \n " ))
94
93
.expectComplete ()
95
94
.verify ();
96
95
}
@@ -101,12 +100,8 @@ public void writeString() {
101
100
testWrite (source , outputMessage , String .class );
102
101
103
102
StepVerifier .create (outputMessage .getBody ())
104
- .consumeNextWith (stringConsumer ("data:" ))
105
- .consumeNextWith (stringConsumer ("foo\n " ))
106
- .consumeNextWith (stringConsumer ("\n " ))
107
- .consumeNextWith (stringConsumer ("data:" ))
108
- .consumeNextWith (stringConsumer ("bar\n " ))
109
- .consumeNextWith (stringConsumer ("\n " ))
103
+ .consumeNextWith (stringConsumer ("data:foo\n \n " ))
104
+ .consumeNextWith (stringConsumer ("data:bar\n \n " ))
110
105
.expectComplete ()
111
106
.verify ();
112
107
}
@@ -117,12 +112,8 @@ public void writeMultiLineString() {
117
112
testWrite (source , outputMessage , String .class );
118
113
119
114
StepVerifier .create (outputMessage .getBody ())
120
- .consumeNextWith (stringConsumer ("data:" ))
121
- .consumeNextWith (stringConsumer ("foo\n data:bar\n " ))
122
- .consumeNextWith (stringConsumer ("\n " ))
123
- .consumeNextWith (stringConsumer ("data:" ))
124
- .consumeNextWith (stringConsumer ("foo\n data:baz\n " ))
125
- .consumeNextWith (stringConsumer ("\n " ))
115
+ .consumeNextWith (stringConsumer ("data:foo\n data:bar\n \n " ))
116
+ .consumeNextWith (stringConsumer ("data:foo\n data:baz\n \n " ))
126
117
.expectComplete ()
127
118
.verify ();
128
119
}
@@ -136,14 +127,11 @@ public void writeStringWithCustomCharset() {
136
127
137
128
assertEquals (mediaType , outputMessage .getHeaders ().getContentType ());
138
129
StepVerifier .create (outputMessage .getBody ())
139
- .consumeNextWith (stringConsumer ("data:" ))
140
130
.consumeNextWith (dataBuffer -> {
141
- String value =
142
- DataBufferTestUtils .dumpString (dataBuffer , charset );
131
+ String value = DataBufferTestUtils .dumpString (dataBuffer , charset );
143
132
DataBufferUtils .release (dataBuffer );
144
- assertEquals ("\u00A3 \n " , value );
133
+ assertEquals ("data: \u00A3 \n \n " , value );
145
134
})
146
- .consumeNextWith (stringConsumer ("\n " ))
147
135
.expectComplete ()
148
136
.verify ();
149
137
}
@@ -154,14 +142,8 @@ public void writePojo() {
154
142
testWrite (source , outputMessage , Pojo .class );
155
143
156
144
StepVerifier .create (outputMessage .getBody ())
157
- .consumeNextWith (stringConsumer ("data:" ))
158
- .consumeNextWith (stringConsumer ("{\" foo\" :\" foofoo\" ,\" bar\" :\" barbar\" }" ))
159
- .consumeNextWith (stringConsumer ("\n " ))
160
- .consumeNextWith (stringConsumer ("\n " ))
161
- .consumeNextWith (stringConsumer ("data:" ))
162
- .consumeNextWith (stringConsumer ("{\" foo\" :\" foofoofoo\" ,\" bar\" :\" barbarbar\" }" ))
163
- .consumeNextWith (stringConsumer ("\n " ))
164
- .consumeNextWith (stringConsumer ("\n " ))
145
+ .consumeNextWith (stringConsumer ("data:{\" foo\" :\" foofoo\" ,\" bar\" :\" barbar\" }\n \n " ))
146
+ .consumeNextWith (stringConsumer ("data:{\" foo\" :\" foofoofoo\" ,\" bar\" :\" barbarbar\" }\n \n " ))
165
147
.expectComplete ()
166
148
.verify ();
167
149
}
@@ -175,18 +157,12 @@ public void writePojoWithPrettyPrint() {
175
157
testWrite (source , outputMessage , Pojo .class );
176
158
177
159
StepVerifier .create (outputMessage .getBody ())
178
- .consumeNextWith (stringConsumer ("data:" ))
179
- .consumeNextWith (stringConsumer ("{\n " +
160
+ .consumeNextWith (stringConsumer ("data:{\n " +
180
161
"data: \" foo\" : \" foofoo\" ,\n " +
181
- "data: \" bar\" : \" barbar\" \n " + "data:}" ))
182
- .consumeNextWith (stringConsumer ("\n " ))
183
- .consumeNextWith (stringConsumer ("\n " ))
184
- .consumeNextWith (stringConsumer ("data:" ))
185
- .consumeNextWith (stringConsumer ("{\n " +
162
+ "data: \" bar\" : \" barbar\" \n " + "data:}\n \n " ))
163
+ .consumeNextWith (stringConsumer ("data:{\n " +
186
164
"data: \" foo\" : \" foofoofoo\" ,\n " +
187
- "data: \" bar\" : \" barbarbar\" \n " + "data:}" ))
188
- .consumeNextWith (stringConsumer ("\n " ))
189
- .consumeNextWith (stringConsumer ("\n " ))
165
+ "data: \" bar\" : \" barbarbar\" \n " + "data:}\n \n " ))
190
166
.expectComplete ()
191
167
.verify ();
192
168
}
@@ -200,28 +176,10 @@ public void writePojoWithCustomEncoding() {
200
176
201
177
assertEquals (mediaType , outputMessage .getHeaders ().getContentType ());
202
178
StepVerifier .create (outputMessage .getBody ())
203
- .consumeNextWith (dataBuffer1 -> {
204
- String value1 =
205
- DataBufferTestUtils .dumpString (dataBuffer1 , charset );
206
- DataBufferUtils .release (dataBuffer1 );
207
- assertEquals ("data:" , value1 );
208
- })
209
179
.consumeNextWith (dataBuffer -> {
210
180
String value = DataBufferTestUtils .dumpString (dataBuffer , charset );
211
181
DataBufferUtils .release (dataBuffer );
212
- assertEquals ("{\" foo\" :\" foo\uD834 \uDD1E \" ,\" bar\" :\" bar\uD834 \uDD1E \" }" , value );
213
- })
214
- .consumeNextWith (dataBuffer2 -> {
215
- String value2 =
216
- DataBufferTestUtils .dumpString (dataBuffer2 , charset );
217
- DataBufferUtils .release (dataBuffer2 );
218
- assertEquals ("\n " , value2 );
219
- })
220
- .consumeNextWith (dataBuffer3 -> {
221
- String value3 =
222
- DataBufferTestUtils .dumpString (dataBuffer3 , charset );
223
- DataBufferUtils .release (dataBuffer3 );
224
- assertEquals ("\n " , value3 );
182
+ assertEquals ("data:{\" foo\" :\" foo\uD834 \uDD1E \" ,\" bar\" :\" bar\uD834 \uDD1E \" }\n \n " , value );
225
183
})
226
184
.expectComplete ()
227
185
.verify ();
0 commit comments