[
https://issues.apache.org/jira/browse/JSPWIKI-167?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Florian Holeczek closed JSPWIKI-167.
------------------------------------
> Confusing PageRenamerTest interaction with WikiContext
> ------------------------------------------------------
>
> Key: JSPWIKI-167
> URL: https://issues.apache.org/jira/browse/JSPWIKI-167
> Project: JSPWiki
> Issue Type: Bug
> Components: Core & storage
> Affects Versions: 2.6.1
> Environment: All
> Reporter: Andrew Jaquith
> Assignee: Andrew Jaquith
> Priority: Minor
> Fix For: 2.6.1
>
> Original Estimate: 0.5h
> Remaining Estimate: 0.5h
>
> In testing some 3.0-related brach code, I noticed something very odd in the
> way PageRenamerTest, PageRenamer, and WikiContext interact.
> The symptoms: PageRenamer.testReferrerNoWikiName() kept failing.
> The test lines that are strange are these (lines 171-186):
> {code}
> m_engine.saveText("Test","foo");
> m_engine.saveText("TestPage2", "[Test] [Test#anchor] test Test [test]
> [link|test] [link|test]");
> WikiPage p = m_engine.getPage("TestPage");
> WikiContext context = new WikiContext(m_engine, p);
> m_engine.renamePage(context, "Test", "TestPage", true);
> {code}
> This seems straightforward enough -- when we save a page that has references
> in it, all of the pages that refer to it should update their references.
> But there are some weird things going on. I can't figure out why 'p' is
> getting assigned page 'TestPage,'... it's a page that doesn't exist.
> Interestingly, when using a debugger to see what 'context' contains, its page
> property is set to page "Main". That's because 'TestPage' doesn't exist, and
> the default is to substitute the "Main" page. This is important! Hold on for
> why...
> Now then, moving over to PageRenamer, we have a private method
> updateReferrerOnRename with the following signature:
> {code}
> private void updateReferrerOnRename(WikiContext context, String oldName,
> String newName, boolean changeReferrer, String referrerName)
> {code}
> The "context" parameter is the same context supplied to renamePage() above.
> Thus, the context that's passed, in this particular test case, will have the
> page "Main" associated with it.
> Further down in updateReferrerOnRename() is this snippet:
> {code}
> if (context.getPage() != null)
> {
> (lots of magic happens where the references are updated and the page is
> re-saved...)
> }
> {code}
> Now then, here's the thing that's bothering me. The 'context' variable
> doesn't have anything to do with either the page that's being renamed or to
> the pages that refer to the renamed page. Moreover, if the context's
> getPage() happens to return null, then renaming the page won't update
> references to it, even though the page will actually be renamed! This is
> bizarre.
> This particular case is strange because of the line:
> {code}
> WikiPage p = m_engine.getPage("TestPage")
> {code}
> If we'd specified the original page ("Test"), then everything would've
> magically worked ok. And in the current JSPWiki scheme of things, even
> specifying a non-existent page ("TestPage") works ok, because the WikiContext
> will magically default to page "Main". But this, it seems to me, is more
> accidental than deliberate.
> What if WikiContexts aren't guaranteed to return a WikiPage from getPage()?
> It is one of those hypothetical (3.0 branch) cases that caused my test case
> to fail.
> Am I missing something here? I must be...
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira