java - Error in MockMvc test case for controller -


i have written junit test case controller layer method, , failing due mismatch in expected outcome. test case follows:

 @test     public void testgetnodestatuscount() throws exception {          listnodes listnodes = new listnodes();        // argumentcaptor<integer> userid = argumentcaptor.forclass(integer.class);         when(usermanagementhelper.getnodestatuscount(0)).thenreturn(             new responseentity<listnodes>(listnodes, new httpheaders(),                 httpstatus.ok));          mockmvc.perform(get("/usermgmt/nodestatus")).andexpect(status().isok());      } 

method test case written follows :

@requestmapping(value = "/nodestatus", method = requestmethod.get, produces = mediatype.application_json_value)     @responsebody     public responseentity<listnodes> getnodestatuscount(@requestparam("userid") int userid) {         return usermanagementhepler.getnodestatuscount(userid);     }  

failure message : enter image description here

thing not getting if status has been set ok how getting 400 in place of 200.

one more thing new mockmvc testing "controller", please suggest me source learn this.

you controller expects required request parameter, why status 400 (bad request)

you can modify test include request parameter mockmvc.perform(get("/usermgmt/nodestatus?userid=0")).andexpect(status().isok());

or can make request parameter optional @requestparam(value = "userid", required = false, defaultvalue = "0")


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -