Überprüfen Karte Schlüssel/Werte-mit jsonPath

Teste ich einen regler gibt eine Karte

@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));
 ...

Welchen Ausdruck soll ich verwenden, um Lesen Sie die Schlüssel und den Wert von der Karte?

Bearbeiten:
Ein Weg, um es zu lösen sein könnte:

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);

Und dann in einer Schleife durch die anzeigen der überprüfung der Werte. Aber gibt es einen Weg, es zu tun mit jsonPath?

InformationsquelleAutor xedo | 2015-05-01
Schreibe einen Kommentar