Updated Branches: refs/heads/wicket-6.x 98b30c803 -> 71eaf5161
WICKET-5426 reset stateless flag on render, since stateful components might be added *and* removed Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/71eaf516 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/71eaf516 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/71eaf516 Branch: refs/heads/wicket-6.x Commit: 71eaf51613fefbf0417e96cebc7459b3f7a2c273 Parents: 98b30c8 Author: svenmeier <[email protected]> Authored: Thu Dec 19 15:11:08 2013 +0100 Committer: svenmeier <[email protected]> Committed: Thu Dec 19 15:11:08 2013 +0100 ---------------------------------------------------------------------- .../src/main/java/org/apache/wicket/Page.java | 8 +- .../WicketTesterLazyIsPageStatelessBase.java | 93 ++++++++++++++++ ...ketTesterLazyIsPageStatelessOnePassTest.java | 40 +++++++ ...LazyIsPageStatelessRedirectToBufferTest.java | 40 +++++++ ...LazyIsPageStatelessRedirectToRenderTest.java | 40 +++++++ .../WicketTesterLazyIsPageStatelessTest.java | 108 ------------------- 6 files changed, 216 insertions(+), 113 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/71eaf516/wicket-core/src/main/java/org/apache/wicket/Page.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/Page.java b/wicket-core/src/main/java/org/apache/wicket/Page.java index 87d32bc..295d9a9 100644 --- a/wicket-core/src/main/java/org/apache/wicket/Page.java +++ b/wicket-core/src/main/java/org/apache/wicket/Page.java @@ -802,11 +802,9 @@ public abstract class Page extends MarkupContainer implements IRedirectListener, // Make sure it is really empty renderedComponents = null; - // if the page is stateless, reset the flag so that it is tested again - if (Boolean.TRUE.equals(stateless)) - { - stateless = null; - } + // rendering might remove or add stateful components, so clear flag to + // force reevaluation + stateless = null; super.onBeforeRender(); http://git-wip-us.apache.org/repos/asf/wicket/blob/71eaf516/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessBase.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessBase.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessBase.java new file mode 100644 index 0000000..0f9be5e --- /dev/null +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessBase.java @@ -0,0 +1,93 @@ +/* + * 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.util.tester; + +import org.apache.wicket.Component; +import org.apache.wicket.MarkupContainer; +import org.apache.wicket.WicketTestCase; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.AjaxLink; +import org.apache.wicket.behavior.Behavior; +import org.apache.wicket.markup.IMarkupResourceStreamProvider; +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.model.AbstractReadOnlyModel; +import org.apache.wicket.util.resource.IResourceStream; +import org.apache.wicket.util.resource.StringResourceStream; +import org.junit.Test; + +/** + * https://issues.apache.org/jira/browse/WICKET-5426 + */ +public abstract class WicketTesterLazyIsPageStatelessBase extends WicketTestCase +{ + /** + * The page must be stateless because the stateful component + * is hidden in #onConfigure + * + * @throws Exception + */ + @Test + public void isStateless() throws Exception + { + tester.startPage(MyPage.class); + + tester.assertLabel("isPageStateless", "true"); + assertTrue(tester.getLastRenderedPage().isPageStateless()); + } + + public static class MyPage extends WebPage implements IMarkupResourceStreamProvider + { + public MyPage() + { + add(new AjaxLink<Void>("link") + { + @Override + public void onClick(AjaxRequestTarget target) + { + } + }.add(new Behavior() + { + @Override + public void onConfigure(Component c) + { + c.setVisible(false); + } + })); + add(new Label("isPageStateless", new AbstractReadOnlyModel<Boolean>() + { + @Override + public Boolean getObject() + { + return MyPage.this.isPageStateless(); + } + })); + } + + @Override + public IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass) + { + return new StringResourceStream("<html>\n" + + "<body>\n" + + "\t<a wicket:id=\"link\" />\n" + + "\t<div wicket:id=\"isPageStateless\" />\n" + + "</body>\n" + + "</html>"); + } + } + +} http://git-wip-us.apache.org/repos/asf/wicket/blob/71eaf516/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessOnePassTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessOnePassTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessOnePassTest.java new file mode 100644 index 0000000..115be55 --- /dev/null +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessOnePassTest.java @@ -0,0 +1,40 @@ +/* + * 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.util.tester; + +import org.apache.wicket.mock.MockApplication; +import org.apache.wicket.protocol.http.WebApplication; +import org.apache.wicket.settings.def.RequestCycleSettings; + +/** + * https://issues.apache.org/jira/browse/WICKET-5426 + */ +public class WicketTesterLazyIsPageStatelessOnePassTest extends WicketTesterLazyIsPageStatelessBase +{ + @Override + protected WebApplication newApplication() + { + return new MockApplication() + { + @Override + public void init() { + super.init(); + getRequestCycleSettings().setRenderStrategy(RequestCycleSettings.RenderStrategy.ONE_PASS_RENDER); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/71eaf516/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessRedirectToBufferTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessRedirectToBufferTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessRedirectToBufferTest.java new file mode 100644 index 0000000..27ac62f --- /dev/null +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessRedirectToBufferTest.java @@ -0,0 +1,40 @@ +/* + * 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.util.tester; + +import org.apache.wicket.mock.MockApplication; +import org.apache.wicket.protocol.http.WebApplication; +import org.apache.wicket.settings.def.RequestCycleSettings; + +/** + * https://issues.apache.org/jira/browse/WICKET-5426 + */ +public class WicketTesterLazyIsPageStatelessRedirectToBufferTest extends WicketTesterLazyIsPageStatelessBase +{ + @Override + protected WebApplication newApplication() + { + return new MockApplication() + { + @Override + public void init() { + super.init(); + getRequestCycleSettings().setRenderStrategy(RequestCycleSettings.RenderStrategy.REDIRECT_TO_BUFFER); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/71eaf516/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessRedirectToRenderTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessRedirectToRenderTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessRedirectToRenderTest.java new file mode 100644 index 0000000..83b578d --- /dev/null +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessRedirectToRenderTest.java @@ -0,0 +1,40 @@ +/* + * 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.util.tester; + +import org.apache.wicket.mock.MockApplication; +import org.apache.wicket.protocol.http.WebApplication; +import org.apache.wicket.settings.def.RequestCycleSettings; + +/** + * https://issues.apache.org/jira/browse/WICKET-5426 + */ +public class WicketTesterLazyIsPageStatelessRedirectToRenderTest extends WicketTesterLazyIsPageStatelessBase +{ + @Override + protected WebApplication newApplication() + { + return new MockApplication() + { + @Override + public void init() { + super.init(); + getRequestCycleSettings().setRenderStrategy(RequestCycleSettings.RenderStrategy.REDIRECT_TO_RENDER); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/71eaf516/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessTest.java deleted file mode 100644 index ef18329..0000000 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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.util.tester; - -import org.apache.wicket.Component; -import org.apache.wicket.MarkupContainer; -import org.apache.wicket.WicketTestCase; -import org.apache.wicket.ajax.AjaxRequestTarget; -import org.apache.wicket.ajax.markup.html.AjaxLink; -import org.apache.wicket.behavior.Behavior; -import org.apache.wicket.markup.IMarkupResourceStreamProvider; -import org.apache.wicket.markup.html.WebPage; -import org.apache.wicket.markup.html.basic.Label; -import org.apache.wicket.mock.MockApplication; -import org.apache.wicket.model.AbstractReadOnlyModel; -import org.apache.wicket.protocol.http.WebApplication; -import org.apache.wicket.settings.IRequestCycleSettings; -import org.apache.wicket.util.resource.IResourceStream; -import org.apache.wicket.util.resource.StringResourceStream; -import org.junit.Test; - -/** - * https://issues.apache.org/jira/browse/WICKET-5424 - */ -public class WicketTesterLazyIsPageStatelessTest extends WicketTestCase -{ - @Override - protected WebApplication newApplication() - { - return new MockApplication() - { - @Override - public void init() { - super.init(); - getRequestCycleSettings().setRenderStrategy(IRequestCycleSettings.RenderStrategy.ONE_PASS_RENDER); - } - }; - } - - /** - * The page must be stateless because the stateful component - * is hidden in #onConfigure - * - * @throws Exception - */ - @Test - public void isStateless() throws Exception - { - tester.startPage(MyPage.class); - tester.assertLabel("isPageStateless", "true"); - assertTrue(tester.getLastRenderedPage().isPageStateless()); - } - - public static class MyPage extends WebPage implements IMarkupResourceStreamProvider - { - public MyPage() - { - add(new AjaxLink<Void>("link") - { - @Override - public void onClick(AjaxRequestTarget target) - { - } - }.add(new Behavior() - { - @Override - public void onConfigure(Component c) - { - c.setVisible(false); - } - })); - add(new Label("isPageStateless", new AbstractReadOnlyModel<Boolean>() - { - @Override - public Boolean getObject() - { - return MyPage.this.isPageStateless(); - } - })); - } - - @Override - public IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass) - { - return new StringResourceStream("<html>\n" + - "<body>\n" + - "\t<a wicket:id=\"link\" />\n" + - "\t<div wicket:id=\"isPageStateless\" />\n" + - "</body>\n" + - "</html>"); - } - } - -}
