本文整理汇总了Java中org.springframework.mock.web.MockHttpServletRequest.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java MockHttpServletRequest.getAttribute方法的具体用法?Java MockHttpServletRequest.getAttribute怎么用?Java MockHttpServletRequest.getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.mock.web.MockHttpServletRequest
的用法示例。
在下文中一共展示了MockHttpServletRequest.getAttribute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPage
import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void testPage() throws Exception{
//模拟请求拿到返回值
MvcResult result = movkMVC.perform(MockMvcRequestBuilders.get("/emps").param("pn", "3")).andReturn();
//请求成功以后,请求域中会有pageInfo:我们可以取出pageinfo进行验证
MockHttpServletRequest request = result.getRequest();
PageInfo pi = (PageInfo)request.getAttribute("PageInfo");
System.out.println("当前页码:"+pi.getPageNum());
System.out.println("总页码:"+pi.getPages());
System.out.println("总记录数:"+pi.getTotal());
System.out.println("在页面需要连续显示的页码");
int[] nums= pi.getNavigatepageNums();
for(int i:nums){
System.out.println(" "+i);
}
//获取员工数据
List<Employee> list= pi.getList();
for(Employee employee : list ){
System.out.println("ID:" +employee.getEmpId()+"==>Name:"+employee.getEmpName());
}
}
示例2: renderView
import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
private Map<?, ?> renderView() throws Exception{
final ModelAndView modelAndView = this.getModelAndViewUponServiceValidationWithSecurePgtUrl();
final JstlView v = (JstlView) resolver.resolveViewName(modelAndView.getViewName(), Locale.getDefault());
final MockHttpServletRequest req = new MockHttpServletRequest(new MockServletContext());
v.setServletContext(req.getServletContext());
req.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE,
new GenericWebApplicationContext(req.getServletContext()));
final Cas30ResponseView view = new Cas30ResponseView(v);
view.setServicesManager(this.servicesManager);
view.setCasAttributeEncoder(new DefaultCasAttributeEncoder(this.servicesManager));
final MockHttpServletResponse resp = new MockHttpServletResponse();
view.render(modelAndView.getModel(), req, resp);
return (Map<?, ?>) req.getAttribute(CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_ATTRIBUTES);
}
示例3: renderView
import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
private Map<?, ?> renderView() throws Exception {
final ModelAndView modelAndView = this.getModelAndViewUponServiceValidationWithSecurePgtUrl();
final MockHttpServletRequest req = new MockHttpServletRequest(new MockServletContext());
req.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, new GenericWebApplicationContext(req.getServletContext()));
final ProtocolAttributeEncoder encoder = new DefaultCasProtocolAttributeEncoder(this.servicesManager, NoOpCipherExecutor.getInstance());
final View viewDelegated = new View() {
@Override
public String getContentType() {
return MediaType.TEXT_HTML_VALUE;
}
@Override
public void render(final Map<String, ?> map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
map.forEach(request::setAttribute);
}
};
final Cas30ResponseView view = new Cas30ResponseView(true, encoder, servicesManager,
"attribute", viewDelegated, true);
final MockHttpServletResponse resp = new MockHttpServletResponse();
view.render(modelAndView.getModel(), req, resp);
return (Map<?, ?>) req.getAttribute(CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_ATTRIBUTES);
}