当前位置: 首页 > news >正文

新网站建设服务页面设计是什么专业

新网站建设服务,页面设计是什么专业,网络推广有哪些常用方法,中山建设网站官网在Spring MVC中对控制器进行集成测试的一种方法是使用Spring提供的集成测试支持。 对于Junit4#xff0c;此支持包括一个名为SpringJunit4ClassRunner的自定义Junit Runner和一个用于加载相关Spring配置的自定义批注。 样本集成测试将遵循以下原则#xff1a; RunWith(Spri… 在Spring MVC中对控制器进行集成测试的一种方法是使用Spring提供的集成测试支持。 对于Junit4此支持包括一个名为SpringJunit4ClassRunner的自定义Junit Runner和一个用于加载相关Spring配置的自定义批注。 样本集成测试将遵循以下原则 RunWith(SpringJUnit4ClassRunner.class) ContextConfiguration(locations{classpath:/META-INF/spring/webmvc-config.xml, contextcontrollertest.xml}) public class ContextControllerTest {Autowiredprivate RequestMappingHandlerAdapter handlerAdapter;Autowiredprivate RequestMappingHandlerMapping handlerMapping;......Testpublic void testContextController() throws Exception{MockHttpServletRequest httpRequest new MockHttpServletRequest(POST,/contexts);httpRequest.addParameter(name, context1);httpRequest.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE,new FlashMap());MockHttpServletResponse response new MockHttpServletResponse();Authentication authentication new UsernamePasswordAuthenticationToken(new CustomUserDetails(..), null);SecurityContextHolder.getContext().setAuthentication(authentication);Object handler this.handlerMapping.getHandler(httpRequest).getHandler();ModelAndView modelAndView handlerAdapter.handle(httpRequest, response, handler);assertThat(modelAndView.getViewName(), is(redirect:/contexts));} } 我已经使用MockHttpServletRequest创建对“ / contexts” uri的虚拟POST请求并为Controller中可用的Spring Security相关细节添加了一些身份验证细节。 正在验证控制器返回的ModelAndView以确保返回的视图名称符合预期。 执行与控制器相关的集成的更好方法是使用一个相对较新的Spring项目Spring-test-mvc 该项目提供了一种流畅的方法来测试控制器流。 使用Spring-test-mvc与上述相同的测试如下所示 Test public void testContextController() throws Exception{Authentication authentication new UsernamePasswordAuthenticationToken(new CustomUserDetails(..), null);SecurityContextHolder.getContext().setAuthentication(authentication);xmlConfigSetup(classpath:/META-INF/spring/webmvc-config.xml, classpath:/org/bk/lmt/web/contextcontrollertest.xml).build().perform(post(/contexts).param(name, context1)).andExpect(status().isOk()).andExpect(view().name(redirect:/contexts)); } 现在测试变得更加简洁无需直接处理MockHttpServletRequest和MockHttpServletResponse实例并且读取效果很好。 我对静态导入的数量和此处涉及的函数调用的数量有所保留但是与其他所有内容一样这只是适应这种测试方法的问题。 WEB-INF位置下的资源也可以通过以下方式与spring-test-mvc一起使用 xmlConfigSetup(/WEB-INF/spring/webmvc-config.xml,classpath:/org/bk/lmt/web/contextcontrollertest.xml).configureWebAppRootDir(src/main/webapp, false).build().perform(post(/contexts).param(name, context1)).andExpect(status().isOk()).andExpect(view().name(redirect:/contexts));xmlConfigSetup(/WEB-INF/spring/webmvc-config.xml, classpath:/org/bk/lmt/web/contextcontrollertest.xml).configureWebAppRootDir(src/main/webapp, false).build().perform(get(/contexts)).andExpect(status().isOk()).andExpect(view().name(contexts/list)); 参考 all和其他博客中的JCG合作伙伴 Biju Kunjummen提供的Spring MVC集成测试 。 翻译自: https://www.javacodegeeks.com/2012/07/spring-mvc-integration-tests.html
http://www.pierceye.com/news/249715/

相关文章:

  • 网上商城网站模板广州建设技术职业学院
  • 养生网站模板下载山东网站建设哪家专业
  • 最新电子产品网站模板网站建设公司 腾佳
  • 跟公司产品做网站用什么程序做网站最好优化
  • 在线代理网页浏览网站山东省城乡住房建设厅网站
  • 网站建设需准备什么彩页模板图片
  • 怎么用网站源码建站网站换空间步骤
  • 酒店网站开发回扣商丘企业网站建设服务
  • 网站建设策划解决方案河北自助建站系统平台
  • 有没有做高仿手表的网站设计师的职责
  • struts2 做的网站seo公司怎样找客户
  • 帮别人做网站赚钱吗中山快速建站合作
  • 保靖网站建设做网站要运用到代码吗
  • 我用织梦5.7做个网站应该把淘宝客店铺链接放到哪frontpage可以制作网页吗
  • 潍坊优化网站排名在线网页设计培训机构
  • c做的网站ps做 网站标准尺寸
  • 老虎淘客系统可以做网站吗wordpress po mo
  • 网站的建设与维护那个网站做图片好
  • 昆山网站建设详细方案建设企业网站初始必备的六大功能
  • 做网站是前端还是后端网站规划 设计 制作 发布与管理过程
  • 黄山网站开发威县做网站哪里便宜
  • 网站怎么分类视频聚合网站怎么做不侵权
  • 有没有做问卷还能赚钱的网站套别人的网站模板吗
  • 东莞做汽车有没有买票的网站做谷歌推广一个月赚10万
  • 抚州城乡建设厅网站建设局官网查询
  • 汉中微信网站建设装修3d效果图怎么制作
  • wordpress 主题放哪站内关键词自然排名优化
  • 网站备案后经营做网站实例教程
  • 软件网站怎么做的python下载安装教程
  • 旅游网站开发分析报告网站建设教程搭建芽嘱湖南岚鸿信赖