Repository: wicket Updated Branches: refs/heads/master 137fa9e40 -> 5f4affeb6
WICKET-6349 Stateless form does not work when RecreateBookmarkablePagesAfterExpiry is false Use the test cases from Wicket 7.x to protect us from regressions Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/5f4affeb Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/5f4affeb Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/5f4affeb Branch: refs/heads/master Commit: 5f4affeb62bbd4ec6286394e0572ec20633c939f Parents: 137fa9e Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Fri Apr 7 22:49:48 2017 +0200 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Fri Apr 7 22:50:40 2017 +0200 ---------------------------------------------------------------------- ...telessAjaxFallbackLinkDoNotRecreatePage.html | 17 ++++ ...telessAjaxFallbackLinkDoNotRecreatePage.java | 96 ++++++++++++++++++++ ...telessAjaxFallbackLinkDoNotRecreateTest.java | 50 ++++++++++ 3 files changed, 163 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/5f4affeb/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreatePage.html ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreatePage.html b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreatePage.html new file mode 100644 index 0000000..5020532 --- /dev/null +++ b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreatePage.html @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org"> + <head> + <title>Stateless Wicket</title> + <link rel="stylesheet" type="text/css" href="style.css"/> + </head> + <body> + <h2>Stateless ajax fallback link</h2> + <div>This link uses ajax when it is available, and a regular + wicket roundtrip when ajax or javascript are not available and the + page should be stateless.</div> + + <b>Counter: </b> + <span id="c2" wicket:id="incrementLabel"></span> + <a href="#" id="c2-link" wicket:id="incrementLink">increment</a> + </body> +</html> http://git-wip-us.apache.org/repos/asf/wicket/blob/5f4affeb/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreatePage.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreatePage.java b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreatePage.java new file mode 100644 index 0000000..58b4e72 --- /dev/null +++ b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreatePage.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.ajax.markup.html; + +import java.util.Optional; + +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.link.Link; +import org.apache.wicket.model.AbstractReadOnlyModel; +import org.apache.wicket.request.mapper.parameter.PageParameters; +import org.apache.wicket.util.string.StringValue; + +public class StatelessAjaxFallbackLinkDoNotRecreatePage extends WebPage +{ + private static final long serialVersionUID = 1L; + + private static final String COUNTER_PARAM = "counter"; + + /** + * Constructor that is invoked when page is invoked without a session. + * + * @param parameters + * Page parameters + */ + public StatelessAjaxFallbackLinkDoNotRecreatePage(final PageParameters parameters) + { + super(parameters); + setStatelessHint(true); + + final Label incrementLabel = new Label("incrementLabel", new AbstractReadOnlyModel<Integer>() + { + private static final long serialVersionUID = 1L; + + @Override + public Integer getObject() + { + final String counter = getParameter(parameters, COUNTER_PARAM); + return counter != null ? Integer.parseInt(counter) : 0; + } + }); + final Link<?> incrementLink = new AjaxFallbackLink<Void>("incrementLink") + { + private static final long serialVersionUID = 1L; + + @Override + public void onClick(final Optional<AjaxRequestTarget> targetOptional) + { + Integer counter = (Integer) incrementLabel.getDefaultModelObject(); + updateParams(getPageParameters(), counter); + targetOptional.ifPresent(target -> target.add(incrementLabel, this)); + } + + @Override + protected boolean getStatelessHint() + { + return true; + } + }; + + add(incrementLink); + add(incrementLabel.setOutputMarkupId(true)); + } + + private String getParameter(final PageParameters parameters, final String key) + { + final StringValue value = parameters.get(key); + + if (value.isNull() || value.isEmpty()) + { + return null; + } + + return value.toString(); + } + + protected final void updateParams(final PageParameters pageParameters, final int counter) + { + pageParameters.set(COUNTER_PARAM, Integer.toString(counter + 1)); + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/5f4affeb/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreateTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreateTest.java b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreateTest.java new file mode 100644 index 0000000..bc087fc --- /dev/null +++ b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreateTest.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.ajax.markup.html; + +import org.apache.wicket.Page; +import org.apache.wicket.Session; +import org.apache.wicket.util.tester.WicketTestCase; +import org.junit.After; +import org.junit.Test; + +public class StatelessAjaxFallbackLinkDoNotRecreateTest extends WicketTestCase +{ + @After + public void after() + { + // things must stay stateless + assertTrue(Session.get().isTemporary()); + } + + /** + * https://issues.apache.org/jira/browse/WICKET-6349 + */ + @Test + public void statelessPagesAreAlwaysRecreated() + { + tester.getApplication().getPageSettings().setRecreateBookmarkablePagesAfterExpiry(false); + tester.startPage(StatelessAjaxFallbackLinkDoNotRecreatePage.class); + + final Page page = tester.getLastRenderedPage(); + assertTrue(page.isStateless()); + + tester.clickLink("incrementLink"); + + tester.assertRenderedPage(StatelessAjaxFallbackLinkDoNotRecreatePage.class); + } +}
