forked from apache/wicket
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WICKET-5960 Page header isn't renderen for pages where URL has change…
…d during render This adds a disabled test case for the linked issue.
- Loading branch information
Showing
3 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderPage.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head></head> | ||
<body></body> | ||
</html> |
62 changes: 62 additions & 0 deletions
62
wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.apache.wicket.request.cycle; | ||
|
||
import java.io.Serializable; | ||
|
||
import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior; | ||
import org.apache.wicket.markup.head.IHeaderResponse; | ||
import org.apache.wicket.markup.head.StringHeaderItem; | ||
import org.apache.wicket.markup.html.WebPage; | ||
import org.apache.wicket.request.mapper.parameter.PageParameters; | ||
import org.apache.wicket.util.time.Duration; | ||
|
||
@SuppressWarnings("javadoc") | ||
public class RerenderPage extends WebPage | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
public static abstract class Supplier<T> implements Serializable | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
public abstract T get(); | ||
} | ||
|
||
private Integer newValue = 1; | ||
|
||
private Supplier<Integer> handler = null; | ||
|
||
public RerenderPage(PageParameters pars) | ||
{ | ||
super(pars); | ||
this.newValue = pars.get("value").toInteger(); | ||
|
||
// make page statefull | ||
add(new AjaxSelfUpdatingTimerBehavior(Duration.ONE_DAY)); | ||
} | ||
|
||
@Override | ||
protected void onConfigure() | ||
{ | ||
super.onConfigure(); | ||
if (handler != null) | ||
setNewValue(handler.get()); | ||
} | ||
|
||
private void setNewValue(Integer newValue) | ||
{ | ||
this.newValue = newValue; | ||
getPageParameters().set("value", newValue); | ||
} | ||
|
||
public void setNewValueHandler(Supplier<Integer> s) | ||
{ | ||
this.handler = s; | ||
} | ||
|
||
@Override | ||
public void renderHead(IHeaderResponse response) | ||
{ | ||
super.renderHead(response); | ||
response.render(new StringHeaderItem("<!-- I should be present " + newValue + " -->")); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderPageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.apache.wicket.request.cycle; | ||
|
||
import org.apache.wicket.core.request.mapper.MountedMapper; | ||
import org.apache.wicket.request.cycle.RerenderPage.Supplier; | ||
import org.apache.wicket.request.mapper.parameter.PageParameters; | ||
import org.apache.wicket.util.tester.WicketTestCase; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Test cases for re-rendering pages. | ||
*/ | ||
public class RerenderPageTest extends WicketTestCase | ||
{ | ||
/** | ||
* A testcase for WICKET-5960. | ||
* | ||
* Due to the changes in WICKET-5309, a page is re-rendered when any of the URL segments is | ||
* modified during the request. The re-render causes the {@code <head>} section to be empty | ||
* because it was already rendered in the first try. | ||
*/ | ||
@Test | ||
@Ignore("Committed reproduction case, but added disabled to not fail the build") | ||
public void wicket5960() | ||
{ | ||
// mount the page so we have URL segments | ||
tester.getApplication().mount(new MountedMapper("/rerender/${value}", RerenderPage.class)); | ||
|
||
// start the page with a value of 1 | ||
PageParameters pars = new PageParameters(); | ||
pars.add("value", 1); | ||
|
||
// render the page | ||
RerenderPage page = tester.startPage(RerenderPage.class, pars); | ||
tester.assertRenderedPage(RerenderPage.class); | ||
tester.assertContains("<!-- I should be present 1 -->"); | ||
|
||
// add a supplier to modify the URL during render | ||
page.setNewValueHandler(new Supplier<Integer>() | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
public Integer get() | ||
{ | ||
return 2; | ||
} | ||
}); | ||
|
||
// rerender the page | ||
tester.startPage(page); | ||
tester.assertRenderedPage(RerenderPage.class); | ||
|
||
// due to the mentioned issue, no headers are rendered at all. | ||
tester.assertContains("<!-- I should be present 2 -->"); | ||
} | ||
} |