我有一个api电话:
@RequestMapping(value = "/course", method = RequestMethod.GET)
ResponseEntity<Object> getCourse(HttpServletRequest request, HttpServletResponse response) throwsException {
User user = userDao.getByUsername(request.getRemoteUser());
}
Run Code Online (Sandbox Code Playgroud)
当我从测试类中调用它时,我得到的用户为null,如:
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
Mockito.when(request.getRemoteUser()).thenReturn("test1");
MvcResult result = mockMvc.perform( get( "/course")
.contentType(MediaType.APPLICATION_JSON)
.andExpect( status().isOk() )
.andExpect( content().contentType( "application/json;charset=UTF-8" ) )
.andReturn();
Run Code Online (Sandbox Code Playgroud)
当我调试请求对象时,我可以看到remoteUser=null.那么如何将值传递给远程用户呢?