I'm testing a controller that returns a Map
@RequestMapping("/")
@ResponseBody
public Map<String, String> getMessages(@RequestBody String foo) {
Map<String, String> map = boo.getMap(foo);
return map;
}
Test:
...
resultActions
.andDo(print())
.andExpect(status().isOk())
.andExpect(
content().contentTypeCompatibleWith(
MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$", notNullValue()))
.andExpect(jsonPath(EXPRESSION, equalsTo(foo));
...
Which expression should I use to read the key and the value from the Map?
Edit: A way around to solve it could be:
MvcResult result = resultActions.andReturn();
MockHttpServletResponse response = result.getResponse();
String content = response.getContentAsString();
Gson gson = new Gson();
Type typeOfT = new TypeToken<Map>() {
}.getType();
Map<String, String> map = gson.fromJson(content, typeOfT);
And then loop through the map checking the values. But is there a way to do it with jsonPath
?