gpt4 book ai didi

io.kaif.service.ZoneService.loadZone()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 10:57:20 28 4
gpt4 key购买 nike

本文整理了Java中io.kaif.service.ZoneService.loadZone()方法的一些代码示例,展示了ZoneService.loadZone()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneService.loadZone()方法的具体详情如下:
包路径:io.kaif.service.ZoneService
类名称:ZoneService
方法名:loadZone

ZoneService.loadZone介绍

暂无

代码示例

代码示例来源:origin: kaif-open/kaif

private Object resolveZone(HttpServletRequest request,
  String decodedRawZone,
  Function<ZoneInfo, ModelAndView> onZoneInfo) {
 // note that decodedRawZone already do http url decode, and PathVariable already trim()
 // space of value
 return Zone.tryFallback(decodedRawZone).map(zone -> {
  if (!zone.value().equals(decodedRawZone)) {
   String orgUrl = request.getRequestURL().toString();
   // replace pattern is combine of fallback pattern and valid pattern
   // TODO refactor replace rule to Zone
   String location = orgUrl.replaceFirst("/z/[a-zA-Z0-9_\\-]+", "/z/" + zone);
   //check if fallback success, this prevent infinite redirect loop
   if (!location.equals(orgUrl)) {
    RedirectView redirectView = new RedirectView(location);
    redirectView.setPropagateQueryParams(true);
    redirectView.setExpandUriTemplateVariables(false);
    redirectView.setExposeModelAttributes(false);
    redirectView.setExposeContextBeansAsAttributes(false);
    redirectView.setExposePathVariables(false);
    redirectView.setContextRelative(true);
    redirectView.setStatusCode(HttpStatus.PERMANENT_REDIRECT);
    return redirectView;
   }
  }
  return onZoneInfo.apply(zoneService.loadZone(zone));
 }).orElseThrow(() -> new EmptyResultDataAccessException("no such zone: " + decodedRawZone, 1));
}

代码示例来源:origin: kaif-open/kaif

@Test
public void getZone_cached() throws Exception {
 service.createDefault("def", "dddd");
 ZoneInfo cached = service.loadZone(Zone.valueOf("def"));
 assertSame(cached, service.loadZone(Zone.valueOf("def")));
}

代码示例来源:origin: kaif-open/kaif

@Test
public void rssFeed_invalid_xml_character() throws Exception {
 Zone z = zoneInfo.getZone();
 when(zoneService.loadZone(z)).thenReturn(zoneInfo);
 Article article1 = article(z, "bad-character \b in xml");
 when(articleService.listRssHotZoneArticlesWithCache(z)).thenReturn(//
   asList(article1));
 mockMvc.perform(get("/z/programming/hot.rss"))
   .andExpect(xpath("/rss/channel/item[1]/title").string("bad-character  in xml"));
}

代码示例来源:origin: kaif-open/kaif

@Test
public void newArticlesWithPaging() throws Exception {
 Zone z = zoneInfo.getZone();
 when(zoneService.loadZone(z)).thenReturn(zoneInfo);
 Article article1 = article(z, "erlang discussion");
 Article article2 = article(z, FlakeId.fromString("csharp"), "C# too many features");
 when(articleService.listLatestZoneArticles(z, FlakeId.fromString("bcdefg"))).thenReturn(//
   asList(article1, article2));
 mockMvc.perform(get("/z/programming/new?start=bcdefg"))
   .andExpect(content().string(containsString("href=\"/z/programming/new?start=csharp\"")));
}

代码示例来源:origin: kaif-open/kaif

@Test
public void updateTheme() throws Exception {
 service.createDefault("twfaq", "TW FAQ");
 service.loadZone(Zone.valueOf("twfaq"));//populate cache
 service.updateTheme(Zone.valueOf("twfaq"), ZoneInfo.THEME_KAIF);
 assertEquals(ZoneInfo.THEME_KAIF, service.loadZone(Zone.valueOf("twfaq")).getTheme());
}

代码示例来源:origin: kaif-open/kaif

@Test
public void createSpeak() throws Exception {
 when(zoneService.loadZone(Zone.valueOf("programming"))).thenReturn(zoneInfo);
 ZoneInfo another = zoneDefault("another");
 when(zoneService.listCitizenZones()).thenReturn(asList(zoneInfo, another));
 mockMvc.perform(get("/z/programming/article/create-speak"))
   .andExpect(view().name("article/create"))
   .andExpect(model().attribute("candidateZoneInfos", hasItem(another)))
   .andExpect(model().attribute("candidateZoneInfos", not(hasItem(zoneInfo))))
   .andExpect(content().string(containsString("id=\"contentInput\"")));
}

代码示例来源:origin: kaif-open/kaif

@Test
public void newDebatesWithPaging() throws Exception {
 Zone z = zoneInfo.getZone();
 when(zoneService.loadZone(z)).thenReturn(zoneInfo);
 Article a = article(z, "golang must be");
 Debate d1 = debate(a, "cool", null);
 Debate d2 = debate(a, "poor", null);
 when(articleService.listLatestZoneDebates(z, FlakeId.fromString("abcdefghi"))).thenReturn(//
   asList(d1, d2));
 when(articleService.listArticlesByDebatesWithCache(asList(d1.getDebateId(),
   d2.getDebateId()))).thenReturn(asList(a));
 mockMvc.perform(get("/z/programming/new-debate").param("start", "abcdefghi"))
   .andExpect(content().string(containsString("cool")))
   .andExpect(content().string(containsString("poor")));
}

代码示例来源:origin: kaif-open/kaif

@Test
public void createLink() throws Exception {
 when(zoneService.loadZone(Zone.valueOf("programming"))).thenReturn(zoneInfo);
 mockMvc.perform(get("/z/programming/article/create-link"))
   .andExpect(view().name("article/create"))
   .andExpect(content().string(containsString("id=\"urlInput\"")));
}

代码示例来源:origin: kaif-open/kaif

@Test
public void rssFeed_no_articles() throws Exception {
 Zone z = zoneInfo.getZone();
 when(zoneService.loadZone(z)).thenReturn(zoneInfo);
 String pubDateStr = RFC1123_FORMATTER.format(zoneInfo.getCreateTime());
 when(articleService.listRssHotZoneArticlesWithCache(z)).thenReturn(Collections.emptyList());
 mockMvc.perform(get("/z/programming/hot.rss"))
   .andExpect(xpath("/rss/channel/title").string("programming kaif.io"))
   .andExpect(xpath("/rss/channel/description").string("programming-alias 熱門"))
   .andExpect(xpath("/rss/channel/pubDate").string(pubDateStr));
}

代码示例来源:origin: kaif-open/kaif

@Test
public void hotArticlesWithPaging() throws Exception {
 Zone z = zoneInfo.getZone();
 when(zoneService.loadZone(z)).thenReturn(zoneInfo);
 Article article1 = article(z, "javascript discussion");
 Article article2 = article(z, FlakeId.fromString("phpone"), "php-lang discussion");
 when(articleService.listHotZoneArticles(z, FlakeId.fromString("123456"))).thenReturn(//
   asList(article1, article2));
 when(zoneService.listAdministratorsWithCache(z)).thenReturn(asList("admin1", "admin2"));
 mockMvc.perform(get("/z/programming?start=123456"))
   .andExpect(content().string(containsString("/css/z-theme-default.css")))
   .andExpect(content().string(containsString("programming-alias")))
   .andExpect(content().string(containsString("php-lang")))
   .andExpect(content().string(containsString("admin1")))
   .andExpect(content().string(containsString("href=\"/z/programming?start=phpone\"")));
}

代码示例来源:origin: kaif-open/kaif

@Test
public void newArticles() throws Exception {
 Zone z = zoneInfo.getZone();
 when(zoneService.loadZone(z)).thenReturn(zoneInfo);
 when(articleService.listLatestZoneArticles(z, null)).thenReturn(//
   asList(article(z, "java 123"), article(z, "ruby 999"), article(z, "golang 456")));
 mockMvc.perform(get("/z/programming/new"))
   .andExpect(content().string(containsString("programming-alias")))
   .andExpect(content().string(containsString("java")))
   .andExpect(content().string(containsString("golang")))
   .andExpect(content().string(containsString("ruby")))
   .andExpect(content().string(containsString("moments ago"))); // relativeTime()
}

代码示例来源:origin: kaif-open/kaif

@Test
public void articleDebates_speakArticle() throws Exception {
 Zone z = zoneInfo.getZone();
 FlakeId articleId = FlakeId.fromString("aaa");
 Article article = articleSpeak(z, articleId, "erlang");
 List<Debate> debates = asList(//
   debate(article, "ERLANG is bad", null));
 when(zoneService.loadZone(z)).thenReturn(zoneInfo);
 when(articleService.loadArticle(articleId)).thenReturn(article);
 when(articleService.listBestDebates(articleId, null)).thenReturn(DebateTree.fromDepthFirst(
   debates));
 mockMvc.perform(get("/z/programming/debates/aaa"))
   .andExpect(view().name("article/debates"))
   .andExpect(content().string(containsString("erlang-content")))
   .andExpect(content().string(containsString("ERLANG is bad")));
}

代码示例来源:origin: kaif-open/kaif

@Test
public void hot_redirectFallback() throws Exception {
 when(zoneService.loadZone(Zone.valueOf("programming"))).thenReturn(zoneInfo);
 mockMvc.perform(get("/z/Programming?xyz"))
   .andExpect(status().isPermanentRedirect())
   .andExpect(redirectedUrl("http://localhost/z/programming?xyz"));
}

代码示例来源:origin: kaif-open/kaif

@Test
public void newDebates() throws Exception {
 Zone z = zoneInfo.getZone();
 when(zoneService.loadZone(z)).thenReturn(zoneInfo);
 Article a = article(z, "python is serious");
 Debate d1 = debate(a, "agree, good.", null);
 Debate d2 = debate(a, "it's too simple.", null);
 when(articleService.listLatestZoneDebates(z, null)).thenReturn(//
   asList(d1, d2));
 when(articleService.listArticlesByDebatesWithCache(asList(d1.getDebateId(),
   d2.getDebateId()))).thenReturn(asList(a));
 mockMvc.perform(get("/z/programming/new-debate"))
   .andExpect(content().string(containsString("python is serious")))
   .andExpect(content().string(containsString("agree, good.")))
   .andExpect(content().string(containsString("it&#39;s too simple")))
   .andExpect(containsDebateFormTemplate())
   .andExpect(containsText("<meta name=\"robots\" content=\"noindex, follow\">"));
}

代码示例来源:origin: kaif-open/kaif

@Test
public void articleDebates_deleted() throws Exception {
 Zone z = zoneInfo.getZone();
 FlakeId articleId = FlakeId.fromString("aaa");
 Article deleted = article(z, "erlang discussion").withDeleted();
 List<Debate> debates = asList(//
   debate(deleted, "JAVA is better", null));
 when(zoneService.loadZone(z)).thenReturn(zoneInfo);
 when(articleService.loadArticle(articleId)).thenReturn(deleted);
 when(articleService.listBestDebates(articleId, null)).thenReturn(DebateTree.fromDepthFirst(
   debates));
 mockMvc.perform(get("/z/programming/debates/aaa"))
   .andExpect(view().name("article/debates"))
   .andExpect(containsText("<meta name=\"robots\" content=\"noindex, nofollow\">"))
   .andExpect(containsText("文章已刪除"));
}

代码示例来源:origin: kaif-open/kaif

@Test
 public void listZoneHonorRoll() throws Exception {
  when(zoneService.loadZone(Zone.valueOf("programming"))).thenReturn(zoneInfo);
  Account c1 = accountCitizen("champ_1");
  Account c2 = accountCitizen("champ_2");
  HonorRoll honor1 = honorRoll(zoneInfo.getZone(), c1);
  HonorRoll honor2 = honorRoll(zoneInfo.getZone(), c2);
  when(honorRollService.listHonorRollsByZone(zoneInfo.getZone())).thenReturn(asList(honor1,
    honor2));
  mockMvc.perform(get("/z/programming/honor"))
    .andExpect(containsText("champ_1"))
    .andExpect(containsText("champ_2"));
 }
}

代码示例来源:origin: kaif-open/kaif

@Test
public void notExistZone_404() throws Exception {
 when(zoneService.loadZone(Zone.valueOf("not-exist"))).thenThrow(new EmptyResultDataAccessException(
   "fake",
   1));
 mockMvc.perform(get("/z/not-exist"))
   .andExpect(status().isNotFound())
   .andExpect(view().name("error"))
   .andExpect(content().string(containsString("404")));
}

代码示例来源:origin: kaif-open/kaif

@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")));
}

代码示例来源:origin: kaif-open/kaif

@Test
public void articleDebates() throws Exception {
 Zone z = zoneInfo.getZone();
 FlakeId articleId = FlakeId.fromString("aaa");
 Article article = article(z, "erlang discussion");
 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.listBestDebates(articleId, null)).thenReturn(DebateTree.fromDepthFirst(
   debates));
 when(zoneService.listAdministratorsWithCache(z)).thenReturn(asList("admin1", "admin2"));
 mockMvc.perform(get("/z/programming/debates/aaa"))
   .andExpect(view().name("article/debates"))
   .andExpect(content().string(containsString("/css/z-theme-default.css")))
   .andExpect(content().string(containsString("programming-alias")))
   .andExpect(content().string(containsString("erlang discussion")))
   .andExpect(content().string(containsString("ERLANG is bad")))
   .andExpect(content().string(containsString("JAVA is better")))
   .andExpect(containsText("data-zone-admins=\"admin1,admin2\""))
   .andExpect(containsDebateFormTemplate());
}

代码示例来源:origin: kaif-open/kaif

@Test
public void rssFeed() throws Exception {
 Zone z = zoneInfo.getZone();
 when(zoneService.loadZone(z)).thenReturn(zoneInfo);
 Article article1 = article(z, "javascript discussion");
 Article article2 = article(z, FlakeId.fromString("phpone"), "php-lang discussion");
 when(articleService.listRssHotZoneArticlesWithCache(z)).thenReturn(//
   asList(article1, article2));
 //java.time's RFC1123's dd allow 1 digit, not compatible with rss view
 String pubDateStr = RFC1123_FORMATTER.format(article2.getCreateTime());
 mockMvc.perform(get("/z/programming/hot.rss"))
   .andExpect(xpath("/rss/channel/title").string("programming kaif.io"))
   .andExpect(xpath("/rss/channel/description").string("programming-alias 熱門"))
   .andExpect(xpath("/rss/channel/pubDate").string(pubDateStr))
   .andExpect(xpath("/rss/channel/item[1]/title").string("javascript discussion"))
   .andExpect(xpath("/rss/channel/item[2]/guid").string("phpone"));
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com