Author: dashorst
Date: Mon Nov 27 06:46:39 2006
New Revision: 479642
URL: http://svn.apache.org/viewvc?view=rev&rev=479642
Log:
Added test for detach cycle of components during ajax processing. This test
currently fails!
Added:
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPage.html
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPage.java
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPageAjaxResult.html
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPageExpectedResult.html
Modified:
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/ComponentTest.java
Modified:
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/ComponentTest.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/ComponentTest.java?view=diff&rev=479642&r1=479641&r2=479642
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/ComponentTest.java
(original)
+++
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/ComponentTest.java
Mon Nov 27 06:46:39 2006
@@ -16,17 +16,18 @@
*/
package wicket;
-import wicket.WicketTestCase;
+import wicket.ajax.AjaxEventBehavior;
/**
* Test for ajax handler.
- *
+ *
* @author Juergen Donnerstag
*/
public class ComponentTest extends WicketTestCase
{
/**
* Construct.
+ *
* @param name
*/
public ComponentTest(String name)
@@ -39,6 +40,64 @@
*/
public void testRenderHomePage_1() throws Exception
{
- executeTest(TestPage_1.class, "TestPageExpectedResult_1.html");
+ executeTest(TestPage_1.class, "TestPageExpectedResult_1.html");
+ }
+
+ /**
+ * Tests the number of detach calls on a Page, Component, Behavior and
Model
+ * during a normal request.
+ *
+ * @throws Exception
+ */
+ public void testDetachPage() throws Exception
+ {
+ executeTest(TestDetachPage.class,
"TestDetachPageExpectedResult.html");
+ TestDetachPage page =
(TestDetachPage)application.getLastRenderedPage();
+ assertEquals(1, page.getNrComponentDetachModelCalls());
+ assertEquals(1, page.getNrComponentDetachModelsCalls());
+ assertEquals(1, page.getNrComponentInternalDetachCalls());
+ assertEquals(1, page.getNrComponentOnDetachCalls());
+ assertEquals(1, page.getNrPageDetachModelCalls());
+ assertEquals(1, page.getNrPageDetachModelsCalls());
+ assertEquals(1, page.getNrPageInternalDetachCalls());
+ assertEquals(1, page.getNrPageOnDetachCalls());
+ assertEquals(1, page.getNrModelDetachCalls());
+ assertEquals(1, page.getNrAjaxBehaviorDetachModelCalls());
+ }
+
+ /**
+ * Tests the number of detach calls on a Page, Component, Behavior and
Model
+ * during an Ajax request.
+ *
+ * @throws Exception
+ */
+ public void testDetachPageAjaxRequest() throws Exception
+ {
+ executeTest(TestDetachPage.class,
"TestDetachPageExpectedResult.html");
+ TestDetachPage page =
(TestDetachPage)application.getLastRenderedPage();
+
+ assertEquals(1, page.getNrComponentDetachModelCalls());
+ assertEquals(1, page.getNrComponentDetachModelsCalls());
+ assertEquals(1, page.getNrComponentInternalDetachCalls());
+ assertEquals(1, page.getNrComponentOnDetachCalls());
+ assertEquals(1, page.getNrPageDetachModelCalls());
+ assertEquals(1, page.getNrPageDetachModelsCalls());
+ assertEquals(1, page.getNrPageInternalDetachCalls());
+ assertEquals(1, page.getNrPageOnDetachCalls());
+ assertEquals(1, page.getNrModelDetachCalls());
+ assertEquals(1, page.getNrAjaxBehaviorDetachModelCalls());
+
+ AjaxEventBehavior behavior = page.getAjaxBehavior();
+ executedBehavior(TestDetachPage.class, behavior,
"TestDetachPageAjaxResult.html");
+ assertEquals(2, page.getNrComponentDetachModelCalls());
+ assertEquals(2, page.getNrComponentDetachModelsCalls());
+ assertEquals(2, page.getNrComponentInternalDetachCalls());
+ assertEquals(2, page.getNrComponentOnDetachCalls());
+ assertEquals(2, page.getNrPageDetachModelCalls());
+ assertEquals(2, page.getNrPageDetachModelsCalls());
+ assertEquals(2, page.getNrPageInternalDetachCalls());
+ assertEquals(2, page.getNrPageOnDetachCalls());
+ assertEquals(2, page.getNrModelDetachCalls());
+ assertEquals(2, page.getNrAjaxBehaviorDetachModelCalls());
}
}
Added:
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPage.html
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPage.html?view=auto&rev=479642
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPage.html
(added)
+++
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPage.html
Mon Nov 27 06:46:39 2006
@@ -0,0 +1,5 @@
+<html xmlns:wicket>
+<body>
+ <span wicket:id="comp"></span>
+</body>
+</html>
Added:
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPage.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPage.java?view=auto&rev=479642
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPage.java
(added)
+++
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPage.java
Mon Nov 27 06:46:39 2006
@@ -0,0 +1,215 @@
+/*
+ * 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 wicket;
+
+import wicket.ajax.AjaxEventBehavior;
+import wicket.ajax.AjaxRequestTarget;
+import wicket.behavior.IBehavior;
+import wicket.markup.html.WebPage;
+import wicket.markup.html.basic.Label;
+import wicket.model.IModel;
+
+/**
+ * Test page for detach logic.
+ *
+ * @author dashorst
+ */
+public class TestDetachPage extends WebPage
+{
+ /** For serialization. */
+ private static final long serialVersionUID = 1L;
+
+ private int nrPageInternalDetachCalls = 0;
+ private int nrPageOnDetachCalls = 0;
+ private int nrPageDetachModelCalls = 0;
+ private int nrPageDetachModelsCalls = 0;
+
+ private int nrComponentInternalDetachCalls = 0;
+ private int nrComponentOnDetachCalls = 0;
+ private int nrComponentDetachModelCalls = 0;
+ private int nrComponentDetachModelsCalls = 0;
+
+ private int nrAjaxBehaviorDetachModelCalls = 0;
+
+ private int nrModelDetachCalls = 0;
+
+ private AjaxEventBehavior ajaxEventBehavior;
+
+ /**
+ * Model for testing detach logic.
+ *
+ * @author dashorst
+ */
+ private class DetachModel implements IModel
+ {
+ /** for serialization. */
+ private static final long serialVersionUID = 1L;
+
+ public IModel getNestedModel()
+ {
+ return null;
+ }
+
+ public Object getObject(Component component)
+ {
+ return "body";
+ }
+
+ public void setObject(Component component, Object object)
+ {
+ }
+
+ public void detach()
+ {
+ nrModelDetachCalls++;
+ }
+ }
+
+ /**
+ * Construct.
+ */
+ public TestDetachPage()
+ {
+ final Label label = new Label("comp", new DetachModel())
+ {
+ /** For serialization */
+ private static final long serialVersionUID = 1L;
+
+ public void internalDetach()
+ {
+ nrComponentInternalDetachCalls++;
+ super.internalDetach();
+ }
+
+ protected void onDetach()
+ {
+ nrComponentOnDetachCalls++;
+ super.onDetach();
+ }
+
+ protected void detachModel()
+ {
+ nrComponentDetachModelCalls++;
+ super.detachModel();
+ }
+
+ public void detachModels()
+ {
+ nrComponentDetachModelsCalls++;
+ super.detachModels();
+ }
+ };
+ label.setOutputMarkupId(true);
+ ajaxEventBehavior = new AjaxEventBehavior("onclick")
+ {
+ /** for serialization.
*/
+ private static final
long serialVersionUID = 1L;
+
+ public void
detachModel(Component component)
+ {
+
nrAjaxBehaviorDetachModelCalls++;
+
super.detachModel(component);
+ }
+
+ protected void
onEvent(AjaxRequestTarget target)
+ {
+
target.addComponent(label);
+ }
+ };
+ label.add(ajaxEventBehavior);
+ add(label);
+ }
+
+ public void internalDetach()
+ {
+ nrPageInternalDetachCalls++;
+ super.internalDetach();
+ }
+
+ protected void onDetach()
+ {
+ nrPageOnDetachCalls++;
+ super.onDetach();
+ }
+
+ protected void detachModel()
+ {
+ nrPageDetachModelCalls++;
+ super.detachModel();
+ }
+
+ public void detachModels()
+ {
+ nrPageDetachModelsCalls++;
+ super.detachModels();
+ }
+
+ public int getNrComponentDetachModelCalls()
+ {
+ return nrComponentDetachModelCalls;
+ }
+
+ public int getNrComponentDetachModelsCalls()
+ {
+ return nrComponentDetachModelsCalls;
+ }
+
+ public int getNrComponentInternalDetachCalls()
+ {
+ return nrComponentInternalDetachCalls;
+ }
+
+ public int getNrComponentOnDetachCalls()
+ {
+ return nrComponentOnDetachCalls;
+ }
+
+ public int getNrPageDetachModelCalls()
+ {
+ return nrPageDetachModelCalls;
+ }
+
+ public int getNrPageDetachModelsCalls()
+ {
+ return nrPageDetachModelsCalls;
+ }
+
+ public int getNrPageInternalDetachCalls()
+ {
+ return nrPageInternalDetachCalls;
+ }
+
+ public int getNrPageOnDetachCalls()
+ {
+ return nrPageOnDetachCalls;
+ }
+
+ public int getNrModelDetachCalls()
+ {
+ return nrModelDetachCalls;
+ }
+
+ public int getNrAjaxBehaviorDetachModelCalls()
+ {
+ return nrAjaxBehaviorDetachModelCalls;
+ }
+
+ public AjaxEventBehavior getAjaxBehavior()
+ {
+ return ajaxEventBehavior;
+ }
+}
Added:
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPageAjaxResult.html
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPageAjaxResult.html?view=auto&rev=479642
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPageAjaxResult.html
(added)
+++
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPageAjaxResult.html
Mon Nov 27 06:46:39 2006
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><ajax-response><component id="comp0"
><![CDATA[<span wicket:id="comp" onclick="var
wcall=wicketAjaxGet('/WicketTester/WicketTester?wicket:interface=:0:comp::IBehaviorListener&wicket:behaviorId=0',
function() { }, function() { });"
id="comp0">body</span>]]></component></ajax-response>
\ No newline at end of file
Added:
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPageExpectedResult.html
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPageExpectedResult.html?view=auto&rev=479642
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPageExpectedResult.html
(added)
+++
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/TestDetachPageExpectedResult.html
Mon Nov 27 06:46:39 2006
@@ -0,0 +1,12 @@
+<html xmlns:wicket>
+<head><script type="text/javascript"
src="/WicketTester/WicketTester/resources/wicket.ajax.AbstractDefaultAjaxBehavior/wicket-ajax.js"></script>
+<script type="text/javascript"
id="wicket-ajax-debug-enable"><!--/*--><![CDATA[/*><!--*/
+wicketAjaxDebugEnable=true;
+/*-->]]>*/</script>
+
+<script type="text/javascript"
src="/WicketTester/WicketTester/resources/wicket.ajax.AbstractDefaultAjaxBehavior/wicket-ajax-debug-drag.js"></script>
+<script type="text/javascript"
src="/WicketTester/WicketTester/resources/wicket.ajax.AbstractDefaultAjaxBehavior/wicket-ajax-debug.js"></script>
+</head><body>
+ <span wicket:id="comp" onclick="var
wcall=wicketAjaxGet('/WicketTester/WicketTester?wicket:interface=:0:comp::IBehaviorListener&wicket:behaviorId=0',
function() { }, function() { });" id="comp0">body</span>
+</body>
+</html>