java - WebMvcConfigurationSupport override makes ModelAndView null in MockMVC test -


while trying put mockmvc test work, found json not supported. using answer thread: configure mappingjacksonhttpmessageconverter

i able resolve extending webmvcconfigurationsupport class. however, when use override, appears though modelandview data returned in tests null. know can response data using this:

string content = result.getresponse().getcontentasstring(); 

but, have explanation why modelandview data null?

here mockmvc test class:

@runwith(springjunit4classrunner.class) @webappconfiguration @contextconfiguration("test-rest-context.xml") public class accountcontrollertest {   @autowired private webapplicationcontext webapplicationcontext;  private mockmvc mockmvc;  private mediatype contenttype = new mediatype(mediatype.application_json.gettype(),         mediatype.application_json.getsubtype(),         charset.forname("utf8"));  @before public void setup() throws exception {     this.mockmvc = mockmvcbuilders.webappcontextsetup(this.webapplicationcontext).build(); }  @test public void findcustomerbyid() throws exception {     mvcresult result = mockmvc.perform(get("/api/account/customers/{customerid}", "123").accept(contenttype)             .param("fields", "id", "email", "username")             .contenttype(contenttype))             .andexpect(status().isok())             .andreturn();      modelandview mav = result.getmodelandview();     // mav null here after extend webmvcconfigurationsupport class.  }     } 


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -