A.Alexander
A.Alexander

Reputation: 598

PageExpiredException in wicket's test

I've update wicket from 8.10 to 8.11 and I have many fails in unittests now. All failed tests fails with one error:

@Test
public void testPanel() {
    Panel panel = new MyPanel("id");

    getTester().startComponentInPage(panel); // fails with PageExpiredException: Page with id '0' has expired.
}

No stacktrace is available, the console shows the following log:

15:35:19.300 [main] WARN  RequestCycleExtra - ********************************
15:35:19.300 [main] WARN  RequestCycleExtra - Handling the following exception
org.apache.wicket.protocol.http.PageExpiredException: Page with id '0' has expired.
15:35:19.300 [main] WARN  RequestCycleExtra - ********************************

org.apache.wicket.protocol.http.PageExpiredException: Page with id '0' has expired.

Thus all tests where I test components in the isolation fails. Tests, where I run page with following code, is ok:

getTester().startPage(pageClass, getPageParameters());

In wicket 8.10 all tests passed fine.

What could be wrong? Is this a bug or I have missed something in the application config?

Update:

This bug is described here: https://issues.apache.org/jira/browse/WICKET-6856

Before each test the session is invalidated, and this is the cause of the exception:

@Before
public void prepare() {
    logout(); // If this line is commented the error is not appears
}

protected void logout() {
    Session.get().signOut();
    application.getSecuritySettings().getAuthenticationStrategy().remove();
}

Update 2:

Workaround is add Session.invalidateNow() in the logout code:

protected void logout() {
    Session.get().signOut();
    application.getSecuritySettings().getAuthenticationStrategy().remove();
    Session.get().invalidateNow(); // with this line the error is not appears
}

Upvotes: 1

Views: 140

Answers (1)

svenmeier
svenmeier

Reputation: 5681

As described in https://issues.apache.org/jira/browse/WICKET-6856 faulty tests are now failing in Wicket 8.11.0.

After #signOut() (which calls #invalidate()) the session is invalidated and a redirect for rendering of a stateful page will rightfully fail in a test.

You have to call #invalidateNow() as you've already noted in your update.

Upvotes: 1

Related Questions