You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/asciidoc/index.adoc
+47-1Lines changed: 47 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36530,7 +36530,12 @@ server-side while <<websocket-fallback>> explains the SockJS protocol and shows
36530
36530
how to configure and use it.
36531
36531
36532
36532
<<websocket-stomp-overview>> introduces the STOMP messaging protocol.
36533
-
36533
+
<<websocket-stomp-enable>> demonstrates how to configure STOMP support in Spring.
36534
+
<<websocket-stomp-handle>> explains how to use it including writing annotated message
36535
+
handling methods, sending messages, choosing message broker options, as
36536
+
well as working with the special "user" destinations. Finally
36537
+
<<websocket-stomp-testing>> lists three approaches to testing STOMP/WebSocket
36538
+
applications.
36534
36539
36535
36540
36536
36541
@@ -37612,6 +37617,47 @@ So in that case the client could subscribe to `/user/exchange/amq.direct/positio
37612
37617
ActiveMQ has http://activemq.apache.org/delete-inactive-destinations.html[configuration options]
37613
37618
for purging inactive destinations.
37614
37619
37620
+
[[websocket-stomp-testing]]
37621
+
===== Testing Message Handling Controllers
37622
+
37623
+
There are two main approaches to testing applications using Spring's STOMP over
37624
+
WebSocket support. The first is to write server-side tests verifying the functionality
37625
+
of controllers and their annotated message handling methods. The second is to write
37626
+
full end-to-end tests that involve running a client and a server.
37627
+
37628
+
The two approaches are not mutually exclusive. On the contrary each has a place
37629
+
in an overall test strategy. Server-side tests are more focused and easier to write
37630
+
and maintain. End-to-end integration tests on the other hand are more complete and
37631
+
test much more but they're also more involved to write and maintain.
37632
+
37633
+
The simplest form of server-side tests is to write controller unit tests. However
37634
+
this is not useful enough since much of what a controller does depends on its
37635
+
annotations. Pure unit tests simply can't test that.
37636
+
37637
+
Ideally controllers under test should be invoked as they are at runtime, much like
37638
+
the approach to testing controllers handling HTTP requests using the Spring MVC Test
37639
+
framework. i.e. without running a Servlet container but relying on the Spring Framework
37640
+
to invoke the annotated controllers. Just like with Spring MVC Test here there are two
37641
+
two possible alternatives, either using a "context-based" or "standalone" setup:
37642
+
37643
+
1. Load the actual Spring configuration with the help of the
37644
+
Spring TestContext framework, inject "clientInboundChannel" as a test field, and
37645
+
use it to send messages to be handled by controller methods.
37646
+
37647
+
2. Manually set up the minimum Spring framework infrastructure required to invoke
37648
+
controllers (namely the `SimpAnnotationMethodMessageHandler`) and pass messages for
37649
+
controllers directly to it.
37650
+
37651
+
Both of these setup scenarios are demonstrated in the
37652
+
https://github.com/rstoyanchev/spring-websocket-portfolio/tree/master/src/test/java/org/springframework/samples/portfolio/web[tests for the stock portfolio]
37653
+
sample application.
37654
+
37655
+
The second approach is to create end-to-end integration tests. For that you will need
37656
+
to run a WebSocket server in embedded mode and connect to it as a WebSocket client
The https://github.com/rstoyanchev/spring-websocket-portfolio/tree/master/src/test/java/org/springframework/samples/portfolio/web[tests for the stock portfolio]
37659
+
sample application also demonstrate this approach using Tomcat as the embedded
37660
+
WebSocket server and a simple STOMP client for test purposes.
0 commit comments