Ich habe Klasse Type1
wie folgt aus:vererbten Klasse Gang in @RequestMapping mit MockMVC
public class Type1 extends TypeParent {}
Ich habe eine Methode Post in meinem Controller Hexe Ich werde mit MockMvc
testen:
@RequestMapping(value = "/actions", method = RequestMethod.POST)
public Map<String, Name> gettypes(@Valid @RequestBody Type1 request) { ... }
Aber ich verstehe nicht, warum der folgende Testcode nicht funktioniert.
Type1 type= new Type1();
mockMvc.perform(post("/actions").contentType(JsonUtils.APPLICATION_JSON_UTF8).content(JsonUtils.toJson(type)))
.andExpect(status().isOk())
.andDo(print());
Ausgang:
java.lang.AssertionError: Status expected:<200> but was:<400>
Sonst mit: TypeParent typeParent = new TypeParent();
ist es Arbeit sehr fein:
mockMvc.perform(post("/actions").contentType(JsonUtils.APPLICATION_JSON_UTF8)
.content(JsonUtils.toJson(typeParent)))
.andExpect(status().isOk())
.andDo(print());
Ich verstand, dass eine geerbte Objekt vorbei, nicht funktioniert, wie kann ich tun Löse dieses Problem?
Können Sie bitte versuchen Sie dies: 'mockMvc.perform (post ("/ Aktionen") content (JsonUtils.APPLICATION_JSON_UTF8) .content (JsonUtils.toJson (Typ)).) .andDo (print()) .andExpect (status(). isOk()); ' und setzen Sie die Fehlerausgabe hier? – mtyurt
Gelöst Ausnahme: Type = org.springframework.http.converter.HttpMessageNotReadableException MockHttpServletResponse: Status = 400 – aryan
denke ich, das Problem in (@RequestBody Typ1 Anfrage), weil 'Typ' eine andere Klasse geerbt wird, sollte es Arbeit sein. aber ich weiß nicht, wie ich es lösen soll? – aryan