@Test public void childDebates() throws Exception { Zone z = zoneInfo.getZone(); FlakeId articleId = FlakeId.fromString("aaa"); Article article = article(z, "erlang discussion"); Debate parentDebate = debate(article, "use the right tool", null); List<Debate> debates = asList( debate(article, "ERLANG is bad", null), debate(article, "JAVA is better", null)); when(zoneService.loadZone(z)).thenReturn(zoneInfo); when(articleService.loadArticle(articleId)).thenReturn(article); when(articleService.loadDebateWithoutCache(parentDebate.getDebateId())).thenReturn(parentDebate); when(articleService.listBestDebates(articleId, parentDebate.getDebateId())).thenReturn( DebateTree.fromDepthFirst(debates)); mockMvc.perform(get("/z/programming/debates/aaa/" + parentDebate.getDebateId())) .andExpect(view().name("article/debates")) .andExpect(content().string(containsString("回上層"))) .andExpect(content().string(containsString("use the right tool"))) .andExpect(content().string(containsString("ERLANG is bad"))) .andExpect(content().string(containsString("JAVA is better"))); }
@RequestMapping("/{zone}/debates/{articleId}/{parentDebateId}") public Object childDebates(@PathVariable("zone") String rawZone, @PathVariable("articleId") FlakeId articleFlakeId, @PathVariable("parentDebateId") FlakeId debateFlakeId, HttpServletRequest request) throws IOException { return resolveZone(request, rawZone, zoneInfo -> { return new ModelAndView("article/debates") .addObject("zoneInfo", zoneInfo) .addObject("article", articleService.loadArticle(articleFlakeId)) .addObject("recommendZones", zoneService.listRecommendZones()) .addObject("parentDebate", articleService.loadDebateWithoutCache(debateFlakeId)) .addObject("debateTree", articleService.listBestDebates(articleFlakeId, debateFlakeId)); }); }
ZoneController { @RequestMapping("/{zone}/debates/{articleId}/{parentDebateId}") public Object childDebates(@PathVariable("zone") String rawZone, @PathVariable("articleId") FlakeId articleFlakeId, @PathVariable("parentDebateId") FlakeId debateFlakeId, HttpServletRequest request) throws IOException { return resolveZone(request, rawZone, zoneInfo -> { return new ModelAndView("article/debates") .addObject("zoneInfo", zoneInfo) .addObject("article", articleService.loadArticle(articleFlakeId)) .addObject("recommendZones", zoneService.listRecommendZones()) .addObject("parentDebate", articleService.loadDebateWithoutCache(debateFlakeId)) .addObject("debateTree", articleService.listBestDebates(articleFlakeId, debateFlakeId)); }); } }
ZoneController { @RequestMapping("/{zone}/debates/{articleId}/{parentDebateId}") public Object childDebates(@PathVariable("zone") String rawZone, @PathVariable("articleId") FlakeId articleFlakeId, @PathVariable("parentDebateId") FlakeId debateFlakeId, HttpServletRequest request) throws IOException { return resolveZone(request, rawZone, zoneInfo -> { return new ModelAndView("article/debates") .addObject("zoneInfo", zoneInfo) .addObject("article", articleService.loadArticle(articleFlakeId)) .addObject("recommendZones", zoneService.listRecommendZones()) .addObject("parentDebate", articleService.loadDebateWithoutCache(debateFlakeId)) .addObject("debateTree", articleService.listBestDebates(articleFlakeId, debateFlakeId)); }); }  }
ZoneController { @RequestMapping("/{zone}/debates/{articleId}/{parentDebateId}") public Object childDebates(@PathVariable("zone") String rawZone, @PathVariable("articleId") FlakeId articleFlakeId, @PathVariable("parentDebateId") FlakeId debateFlakeId, HttpServletRequest request) throws IOException { return resolveZone(request, rawZone, zoneInfo -> { return new ModelAndView("article/debates") .addObject("zoneInfo", zoneInfo) .addObject("article", articleService.loadArticle(articleFlakeId)) .addObject("recommendZones", zoneService.listRecommendZones()) .addObject("parentDebate", articleService.loadDebateWithoutCache(debateFlakeId)) .addObject("debateTree", articleService.listBestDebates(articleFlakeId, debateFlakeId)); }); }  @RequestMapping("/{zone}") Object hotArticles(@PathVariable("zone") String rawZone,
      @RequestParam(value = "start", required = false) FlakeId startArticleId,
      HttpServletRequest request); @RequestMapping("/{zone}/hot.rss") Object rssFeed(@PathVariable("zone") String rawZone, HttpServletRequest request); @RequestMapping("/{zone}/new") Object newArticles(@PathVariable("zone") String rawZone,
      @RequestParam(value = "start", required = false) FlakeId startArticleId,
      HttpServletRequest request); @RequestMapping("/{zone}/new-debate") Object newDebates(@PathVariable("zone") String rawZone,
      @RequestParam(value = "start", required = false) FlakeId startDebateId,
      HttpServletRequest request); @RequestMapping({ "/{zone}/article/create-link", "/{zone}/article/create-speak" }) Object createArticle(@PathVariable("zone") String rawZone, HttpServletRequest request); @RequestMapping("/{zone}/honor") Object zoneHonors(@PathVariable("zone") String rawZone, HttpServletRequest request); @RequestMapping("/{zone}/debates/{articleId}") Object articleDebates(@PathVariable("zone") String rawZone,
      @PathVariable("articleId") FlakeId articleFlakeId,
      HttpServletRequest request); @RequestMapping("/{zone}/debates/{articleId}/{parentDebateId}") Object childDebates(@PathVariable("zone") String rawZone,
      @PathVariable("articleId") FlakeId articleFlakeId,
      @PathVariable("parentDebateId") FlakeId debateFlakeId,
      HttpServletRequest request); }
ZoneController { @RequestMapping("/{zone}/debates/{articleId}/{parentDebateId}") public Object childDebates(@PathVariable("zone") String rawZone, @PathVariable("articleId") FlakeId articleFlakeId, @PathVariable("parentDebateId") FlakeId debateFlakeId, HttpServletRequest request) throws IOException { return resolveZone(request, rawZone, zoneInfo -> { return new ModelAndView("article/debates") .addObject("zoneInfo", zoneInfo) .addObject("article", articleService.loadArticle(articleFlakeId)) .addObject("recommendZones", zoneService.listRecommendZones()) .addObject("parentDebate", articleService.loadDebateWithoutCache(debateFlakeId)) .addObject("debateTree", articleService.listBestDebates(articleFlakeId, debateFlakeId)); }); }  @RequestMapping("/{zone}") Object hotArticles(@PathVariable("zone") String rawZone,
      @RequestParam(value = "start", required = false) FlakeId startArticleId,
      HttpServletRequest request); @RequestMapping("/{zone}/hot.rss") Object rssFeed(@PathVariable("zone") String rawZone, HttpServletRequest request); @RequestMapping("/{zone}/new") Object newArticles(@PathVariable("zone") String rawZone,
      @RequestParam(value = "start", required = false) FlakeId startArticleId,
      HttpServletRequest request); @RequestMapping("/{zone}/new-debate") Object newDebates(@PathVariable("zone") String rawZone,
      @RequestParam(value = "start", required = false) FlakeId startDebateId,
      HttpServletRequest request); @RequestMapping({ "/{zone}/article/create-link", "/{zone}/article/create-speak" }) Object createArticle(@PathVariable("zone") String rawZone, HttpServletRequest request); @RequestMapping("/{zone}/honor") Object zoneHonors(@PathVariable("zone") String rawZone, HttpServletRequest request); @RequestMapping("/{zone}/debates/{articleId}") Object articleDebates(@PathVariable("zone") String rawZone,
      @PathVariable("articleId") FlakeId articleFlakeId,
      HttpServletRequest request); @RequestMapping("/{zone}/debates/{articleId}/{parentDebateId}") Object childDebates(@PathVariable("zone") String rawZone,
      @PathVariable("articleId") FlakeId articleFlakeId,
      @PathVariable("parentDebateId") FlakeId debateFlakeId,
      HttpServletRequest request);  }