pass remoteUser value in HttpServletRequest to mockmvc perform test

前提是你 提交于 2019-12-04 13:01:05

You can use RequestPostProcessor in order to modify the MockHttpServletRequest in any fashion you want. In your case:

mockMvc.perform(get("/course").with(request -> {
                    request.setRemoteUser("USER");
                    return request;
                })...

And if you're stuck with older versions of Java:

mockMvc.perform(get("/course").with(new RequestPostProcessor() {
            @Override
            public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
                request.setRemoteUser("USER");
                return request;
            }
        })...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!