incubator-jspwiki-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Jaquith (JIRA)" <>
Subject [jira] Commented: (JSPWIKI-167) Confusing PageRenamerTest interaction with WikiContext
Date Mon, 28 Jan 2008 15:17:34 GMT


Andrew Jaquith commented on JSPWIKI-167:

Having looked at the ReferenceManager code, it's fairly straightforward (although because
it's chained as a filter, it's not very efficient).

Changing my WikiActionBeanFactory (3.0) code so that the WikiContext's page is always set
solved the issue. But I'm still not happy about this dependency... it certainly isn't documented.
I'll do a little more digging and see if I can figure out what's going on. Maybe annotate
the docs and put in a FIXME somewhere.

As a total aside:

I am not sure that WikiContext NEEDS to always return a page, at least in the core code (I
can't speak for the JSPs). What was remarkable about my tests (and I ran all of them) was
how FEW of them choked due to not setting the wiki page when creating a WikiContext in WikiActionBeanFactory.
I still have about 25 unrelated test failures to chase down elsewhere in my 3.0 branch before
it tests clean. After that, I'm going to relax the "setPage on context creation" again and
see what it breaks. :)

In the meantime, I'm going to close this bug.

> Confusing PageRenamerTest interaction with WikiContext
> ------------------------------------------------------
>                 Key: JSPWIKI-167
>                 URL:
>             Project: JSPWiki
>          Issue Type: Bug
>          Components: Core & storage
>    Affects Versions: 2.6.1
>         Environment: All
>            Reporter: Andrew Jaquith
>            Assignee: Janne Jalkanen
>            Priority: Minor
>   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.
You can reply to this email to add a comment to the issue online.

View raw message