18
18
19
19
import org .apache .commons .logging .Log ;
20
20
import org .apache .commons .logging .LogFactory ;
21
- import org .hamcrest .Matchers ;
22
21
import org .junit .After ;
23
22
import org .junit .Before ;
24
23
import org .junit .Ignore ;
31
30
import org .springframework .scheduling .concurrent .ThreadPoolTaskScheduler ;
32
31
import org .springframework .util .concurrent .ListenableFutureCallback ;
33
32
import org .springframework .web .context .support .AnnotationConfigWebApplicationContext ;
34
- import org .springframework .web .socket .CloseStatus ;
35
33
import org .springframework .web .socket .TextMessage ;
36
34
import org .springframework .web .socket .WebSocketSession ;
37
35
import org .springframework .web .socket .WebSocketTestServer ;
64
62
65
63
import static org .junit .Assert .assertEquals ;
66
64
import static org .junit .Assert .assertNotNull ;
67
- import static org .junit .Assert .assertThat ;
68
65
import static org .junit .Assert .assertTrue ;
69
- import static org .hamcrest .Matchers .*;
70
66
import static org .junit .Assert .fail ;
71
67
72
68
/**
@@ -166,20 +162,20 @@ public void echoXhr() throws Exception {
166
162
167
163
@ Ignore
168
164
@ Test
169
- public void closeAfterOneMessageWebSocket () throws Exception {
170
- testCloseAfterOneMessage (createWebSocketTransport ());
165
+ public void receiveOneMessageWebSocket () throws Exception {
166
+ testReceiveOneMessage (createWebSocketTransport ());
171
167
}
172
168
173
169
@ Test
174
- public void closeAfterOneMessageXhrStreaming () throws Exception {
175
- testCloseAfterOneMessage (createXhrTransport ());
170
+ public void receiveOneMessageXhrStreaming () throws Exception {
171
+ testReceiveOneMessage (createXhrTransport ());
176
172
}
177
173
178
174
@ Test
179
- public void closeAfterOneMessageXhr () throws Exception {
175
+ public void receiveOneMessageXhr () throws Exception {
180
176
AbstractXhrTransport xhrTransport = createXhrTransport ();
181
177
xhrTransport .setXhrStreamingDisabled (true );
182
- testCloseAfterOneMessage (xhrTransport );
178
+ testReceiveOneMessage (xhrTransport );
183
179
}
184
180
185
181
@ Test
@@ -251,7 +247,7 @@ private void testEcho(int messageCount, Transport transport) throws Exception {
251
247
session .close ();
252
248
}
253
249
254
- private void testCloseAfterOneMessage (Transport transport ) throws Exception {
250
+ private void testReceiveOneMessage (Transport transport ) throws Exception {
255
251
TestClientHandler clientHandler = new TestClientHandler ();
256
252
initSockJsClient (transport );
257
253
this .sockJsClient .doHandshake (clientHandler , this .baseUrl + "/test" ).get ();
@@ -263,16 +259,6 @@ private void testCloseAfterOneMessage(Transport transport) throws Exception {
263
259
TextMessage message = new TextMessage ("message1" );
264
260
serverHandler .session .sendMessage (message );
265
261
clientHandler .awaitMessage (message , 5000 );
266
-
267
- CloseStatus expected = new CloseStatus (3500 , "Oops" );
268
- serverHandler .session .close (expected );
269
- CloseStatus actual = clientHandler .awaitCloseStatus (5000 );
270
- if (transport instanceof XhrTransport ) {
271
- assertThat (actual , Matchers .anyOf (equalTo (expected ), equalTo (new CloseStatus (3000 , "Go away!" ))));
272
- }
273
- else {
274
- assertEquals (expected , actual );
275
- }
276
262
}
277
263
278
264
@@ -324,8 +310,6 @@ private static class TestClientHandler extends TextWebSocketHandler {
324
310
325
311
private volatile Throwable transportError ;
326
312
327
- private volatile CloseStatus closeStatus ;
328
-
329
313
330
314
@ Override
331
315
public void afterConnectionEstablished (WebSocketSession session ) throws Exception {
@@ -342,11 +326,6 @@ public void handleTransportError(WebSocketSession session, Throwable exception)
342
326
this .transportError = exception ;
343
327
}
344
328
345
- @ Override
346
- public void afterConnectionClosed (WebSocketSession session , CloseStatus status ) throws Exception {
347
- this .closeStatus = status ;
348
- }
349
-
350
329
public void awaitMessageCount (final int count , long timeToWait ) throws Exception {
351
330
awaitEvent (() -> receivedMessages .size () >= count , timeToWait ,
352
331
count + " number of messages. Received so far: " + this .receivedMessages );
@@ -364,14 +343,6 @@ else if (this.transportError != null) {
364
343
fail ("Timed out waiting for [" + expected + "]" );
365
344
}
366
345
}
367
-
368
- public CloseStatus awaitCloseStatus (long timeToWait ) throws InterruptedException {
369
- awaitEvent (() -> this .closeStatus != null || this .transportError != null , timeToWait , " CloseStatus" );
370
- if (this .transportError != null ) {
371
- throw new AssertionError ("Transport error" , this .transportError );
372
- }
373
- return this .closeStatus ;
374
- }
375
346
}
376
347
377
348
private static class TestServerHandler extends TextWebSocketHandler {
0 commit comments