Actually, Page.detach() is not callable from a JUnit test that uses
WicketTester in 1.3.0beta3. It throws an exception:

org.apache.wicket.WicketRuntimeException: No RequestCycle is currently set!
at org.apache.wicket.Component.getRequest(Component.java:1443)
at org.apache.wicket.Page.onDetach(Page.java:1406)
at org.apache.wicket.markup.html.WebPage.onDetach(WebPage.java:360)
at org.apache.wicket.Component.detach(Component.java:899)


In 1.2.6, you could call Page.detachModels() and the test would run fine.

-Dan

Here's my test:

---------------------
import junit.framework.TestCase;
/*
//1.2.6
import wicket.Component;
import wicket.Page;
import wicket.model.LoadableDetachableModel;
import wicket.util.tester.WicketTester;
*/

//1.3
import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.util.tester.WicketTester;

public class WicketDetachTest extends TestCase {
    public WicketDetachTest()     {     }

    public void testDetach()    {
        WicketTester tester = new WicketTester();
        Page page = tester.startPage(Wicket12Page.class);

        tester.debugComponentTrees();

        Component c = tester.getComponentFromLastRenderedPage
("listView:0:labelWithDetachableModel");
        LoadableDetachableModel childModel =
(LoadableDetachableModel)c.getModel();

        // Child currently attached due to rendering
        assertTrue(childModel.isAttached()); // Attached

        // Detach children
        //page.detachModels();  // 1.2.6 - Does not detach child models in
1.3
        page.detach(); // 1.3 <---- FAILS - not in request cycle

        assertFalse(childModel.isAttached()); // Not attached

        // Cause attachment
        c.getModelObject();
        assertTrue(childModel.isAttached()); // Attached
    }
}


On 10/2/07, Kent Tong <[EMAIL PROTECTED]> wrote:
>
>
>
> Dan Syrstad-2 wrote:
> >
> > Nope. I tried detach() too and that doesn't work - the test still fails.
> I
> > had to write my own method which was basically was a copy of the old
> > Page.detachModels() code.
> >
> > The thing is that  In beta3, Page now just acts like a Component as far
> as
> > detachModels() is concerned and Component.detachModels()/detach() does
> > notdetach all of the child models.
> > Component.detach(), in fact, calls detachChildren() which is an empty
> > method.
> >
>
> detachChildren() is overriden by MarkupContainer which does detach its
> children
> (see below). So there must be something wrong with your unit test.
>
>         void detachChildren()
>         {
>                 // Loop through child components
>                 final Iterator iter = iterator();
>                 while (iter.hasNext())
>                 {
>                         // Get next child
>                         final Component child = (Component)iter.next();
>
>                         // Call end request on the child
>                         child.detach();
>                 }
>                 super.detachChildren();
>         }
> --
> View this message in context:
> http://www.nabble.com/Page.detachModels%28%29-not-working-like-it-used-to-tf4549247.html#a13000103
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to