ytterrr
ytterrr

Reputation: 3246

What is the simplest way to cover websocket controller with unit tests in Spring?

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

Answers (1)

Related Questions