APIWikiModel extends WikiModel { @Override @Nullable public String getRawWikiContent(final ParsedPageName parsedPagename, final Map<String, String> templateParameters) throws WikiModelContentException { String result = super.getRawWikiContent(parsedPagename, templateParameters); if (result != null) { return result; } final boolean isTemplate = parsedPagename.namespace.isType(NamespaceCode.TEMPLATE_NAMESPACE_KEY); final boolean isModule = parsedPagename.namespace.isType(NamespaceCode.MODULE_NAMESPACE_KEY); if (isTemplate || isModule) { return getTemplateOrModule(parsedPagename.fullPagename(), templateParameters); } else { logger.warn("'"+parsedPagename+"' is not a template or module - returning null"); return null; } } APIWikiModel(User user, WikiDB wikiDB, String imageBaseURL, String linkBaseURL, File imageDirectory);  APIWikiModel(User user, WikiDB wikiDB, Locale locale, String imageBaseURL, String linkBaseURL, File imageDirectory); @Override @Nullable String getRawWikiContent(final ParsedPageName parsedPagename, final Map<String, String> templateParameters); void appendInternalImageLink(String hrefImageLink, String srcImageLink, ImageFormat imageFormat); void parseInternalImageLink(String imageNamespace, String rawImageLink);  }
@Test public void getRawWikiContentWithMagicWordReturnsContent() throws Exception { ParsedPageName magicParsedPage = new ParsedPageName(new Namespace().getMain(), "foo", MagicWordE.MAGIC_PAGE_NAME, null, true); String content = subject.getRawWikiContent(magicParsedPage, null); assertThat(content).isEqualTo("PAGENAME"); }
@Test(expected = WikiModelContentException.class) public void getRawWikiContentForTemplateRaisesWikiModelExceptionWhenSQLExceptionIsEncountered() throws Exception { when(wikiDB.selectTopic(templatePageName.fullPagename())).thenThrow(new SQLException()); subject.getRawWikiContent(templatePageName, null); }
@Test public void getRawWikiContentForTemplateRaisesWikiModelExceptionWithCorrectMessageWhenSQLExceptionIsEncountered() throws Exception { when(wikiDB.selectTopic(templatePageName.fullPagename())).thenThrow(new SQLException()); try { subject.getRawWikiContent(templatePageName, null); fail("expected exception"); } catch (WikiModelContentException e) { assertThat(e.getMessage()).isEqualTo("<span class=\"error\">Exception: SQLException</span>"); } }
@Test(expected = WikiModelContentException.class) public void getRawWikiContentForModuleRaisesWikiModelExceptionWhenSQLExceptionIsEncountered() throws Exception { when(wikiDB.selectTopic(modulePageName.fullPagename())).thenThrow(new SQLException()); subject.getRawWikiContent(modulePageName, null); }
@Test public void testWikiDBReturnsCachedContent() throws Exception { TopicData topicData = new TopicData("name", "content"); when(wikiDB.selectTopic(modulePageName.fullPagename())).thenReturn(topicData); assertThat(subject.getRawWikiContent(modulePageName, null)).isEqualTo(topicData.getContent()); }
@Test public void testWikiDBReturnsNullContent() throws Exception { TopicData topicData = new TopicData("name", null); when(wikiDB.selectTopic(modulePageName.fullPagename())).thenReturn(topicData); assertThat(subject.getRawWikiContent(modulePageName, null)).isNull(); }
@Test public void testWikiDBReturnsNullContentAndUserFetchesData() throws Exception { when(wikiDB.selectTopic(modulePageName.fullPagename())).thenReturn(null); Page page = new Page(); Revision revision = new Revision(); revision.setContent("testContent"); page.setCurrentRevision(revision); when(user.queryContent(modulePageName.fullPagename())).thenReturn(Arrays.asList(page)); assertThat(subject.getRawWikiContent(modulePageName, null)).isEqualTo("testContent"); }
@Test public void testWikiDBReturnsNullTopicData() throws Exception { when(wikiDB.selectTopic(modulePageName.fullPagename())).thenReturn(null); assertThat(subject.getRawWikiContent(modulePageName, null)).isNull(); }
@Test public void getRawWikiContentReturnsNullIfNotTemplateNorModuleNorMagicWord() throws Exception { String content = subject.getRawWikiContent(new ParsedPageName(ns.getMain(), "whatever", true), null); assertThat(content).isNull(); }