spring - java.lang.AssertionError: Status expected:<200> but was:<400> -


it's controller...

@requestmapping(value = "/user", method = requestmethod.post, consumes = mediatype.application_json_value, produces = mediatype.application_json_value, headers = "accept=application/json") public @responsebody responsemessage getuser(@requestbody availableuser uuid) {     logger.info("enter getuser method's body");     return manager.availableuser(uuid); } 

it's testcontroller...

@test  public void testgetuser() throws exception  {     availableuser availableuser=new availableuser();     list<string> lst =new arraylist<string>();     lst.add("test1");     lst.add("test2");     availableuser.setuuid(lst);     this.mockmvc.perform(post("/user").contenttype(mediatype.application_json).accept(mediatype.application_json))         .andexpect(status().iscreated())         .andexpect(status().isok());          when(manager.availableuser(availableuser)).thenreturn(message); } 

i don't know how pass object when controller method call ("/user") form testcontroller.

and got error message java.lang.assertionerror: status expected:<200> was:<400>

if you're using jackson, simplest approach serialize availableuser json string using instance of objectmapper:

@test  public void testgetuser() throws exception  {     // same stuff     objectmapper mapper = new objectmapper();     this.mockmvc         .perform(                   post("/user")                  .contenttype(mediatype.application_json)                  .accept(mediatype.application_json)                  .content(mapper.writevalueasstring(availableuser))         )         .andexpect(status().iscreated())         .andexpect(status().isok());     // same before } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -