Reputation: 3246
Is there something as simple as Spring MockMvc for websocket testing? I saw some questions/answers but all they are at least one year old and it seemed to me not so simple in terms of writing tests. Let's say I've got this controller:
public class ClieantQuery {
private String name;
private int count;
public String getName() { return name; }
public int getCount() { return count; }
}
@Controller
public class WSController {
@MessageMapping("/ws-message")
@SendTo("/message/data")
public List<String> processClientQuery(ClientQuery clientQuery) {
return IntStream.range(0, clientQuery.getCount())
.boxed().map(i -> "Hello " + clientQuery.getName())
.collect(Collectors.toList());
}
}
How might look the class of tests?
Upvotes: 2
Views: 2304
Reputation: 1289
You can use one of the two methods mentioned here (https://github.com/rstoyanchev/spring-websocket-portfolio/tree/master/src/test/java/org/springframework/samples/portfolio/web) to test your controllers, using a SubscribableChannel
as an alternative to MockMvc
to send messages:
Upvotes: 1