Author: mgrigorov
Date: Mon Oct 10 12:24:04 2011
New Revision: 1180916
URL: http://svn.apache.org/viewvc?rev=1180916&view=rev
Log:
WICKET-4112 WicketTester#startComponentInPage and WicketTester#assertModelValue
have inconsistent behavior.
Added:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/tester/ComponentInPage.java
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java?rev=1180916&r1=1180915&r2=1180916&view=diff
==============================================================================
---
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
(original)
+++
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
Mon Oct 10 12:24:04 2011
@@ -193,9 +193,7 @@ public class BaseWicketTester
// Simulates the cookies maintained by the browser
private final List<Cookie> browserCookies = Generics.newArrayList();
- // The root component used for the start. Usually the Page, but can
also be a Panel
- // see https://issues.apache.org/jira/browse/WICKET-1214
- private Component startComponent;
+ private ComponentInPage componentInPage;
// User may provide request header value any time. They get applied
(and reset) upon next
// invocation of processRequest()
@@ -715,7 +713,7 @@ public class BaseWicketTester
public Page startPage(final IPageProvider pageProvider)
{
// should be null for Pages
- startComponent = null;
+ componentInPage = null;
// prepare request
request = new MockHttpServletRequest(application, httpSession,
servletContext);
@@ -822,13 +820,13 @@ public class BaseWicketTester
String response = lastResponse.getDocument();
// null, if a Page was rendered last
- if (startComponent == null)
+ if (componentInPage == null)
{
return response;
}
// remove the markup for the auto-generated page. leave just
component's markup body
- String componentId = startComponent.getId();
+ String componentId = componentInPage.component.getId();
String before = "wicket:id=\"" + componentId + "\">";
Matcher matcher = pattern.matcher(response);
if (matcher.matches())
@@ -1115,7 +1113,7 @@ public class BaseWicketTester
Args.notNull(pageClass, "pageClass");
// must be null for Pages
- startComponent = null;
+ componentInPage = null;
// prepare the request
request.setUrl(application.getRootRequestMapper().mapHandler(
@@ -1250,7 +1248,10 @@ public class BaseWicketTester
try
{
Constructor<C> c =
componentClass.getConstructor(String.class);
- comp = c.newInstance("testObject");
+ comp = c.newInstance(ComponentInPage.ID);
+ componentInPage = new ComponentInPage();
+ componentInPage.component = comp;
+ componentInPage.isInstantiated = true;
}
catch (Exception e)
{
@@ -1333,12 +1334,22 @@ public class BaseWicketTester
// Add the child component
page.add(component);
+ // Preserve 'componentInPage' because #startPage() needs to
null-fy it
+ ComponentInPage oldComponentInPage = componentInPage;
+
// Process the page
startPage(page);
// Remember the "root" component processes and return it
- startComponent = component;
-
+ if (oldComponentInPage != null)
+ {
+ componentInPage = oldComponentInPage;
+ }
+ else
+ {
+ componentInPage = new ComponentInPage();
+ componentInPage.component = component;
+ }
return component;
}
@@ -1450,9 +1461,9 @@ public class BaseWicketTester
public Component getComponentFromLastRenderedPage(String path,
final boolean wantVisibleInHierarchy)
{
- if (startComponent != null)
+ if (componentInPage != null && componentInPage.isInstantiated)
{
- path = startComponent.getId() + ":" + path;
+ path = componentInPage.component.getId() + ":" + path;
}
Component component = getLastRenderedPage().get(path);
@@ -2532,11 +2543,11 @@ public class BaseWicketTester
public PageRenderer get(RenderPageRequestHandler handler)
{
Page newPage =
(Page)handler.getPageProvider().getPageInstance();
- if (startComponent != null && lastPage != null &&
+ if (componentInPage != null && lastPage != null &&
lastPage.getPageClass() !=
newPage.getPageClass())
{
// WICKET-3913: reset startComponent if a new
page type is rendered
- startComponent = null;
+ componentInPage = null;
}
lastRenderedPage = lastPage = newPage;
return delegate.get(handler);
Added:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/tester/ComponentInPage.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/tester/ComponentInPage.java?rev=1180916&view=auto
==============================================================================
---
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/tester/ComponentInPage.java
(added)
+++
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/tester/ComponentInPage.java
Mon Oct 10 12:24:04 2011
@@ -0,0 +1,45 @@
+/*
+ * 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.markup.IMarkupFragment;
+
+/**
+ * Holds the component which is passed to {@link BaseWicketTester}'s
+ * {@link BaseWicketTester#startComponentInPage()} methods and meta data about
it.
+ */
+class ComponentInPage
+{
+ /**
+ * The component id that is used when Wicket instantiates the
tested/started component.
+ */
+ static final String ID = "testObject";
+
+ /**
+ * The component that is being started.
+ */
+ // see https://issues.apache.org/jira/browse/WICKET-1214
+ Component component;
+
+ /**
+ * A flag indicating whether the {@link #component} has been
instantiated by Wicket.
+ *
+ * @see {@link BaseWicketTester#startComponentInPage(Class,
IMarkupFragment)}.
+ */
+ boolean isInstantiated = false;
+}
Modified:
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java?rev=1180916&r1=1180915&r2=1180916&view=diff
==============================================================================
---
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
(original)
+++
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
Mon Oct 10 12:24:04 2011
@@ -980,7 +980,7 @@ public class WicketTesterTest extends Wi
setResponsePage(DummyHomePage.class);
}
});
- tester.clickLink("link");
+ tester.clickLink("testPanel:link");
tester.assertRenderedPage(DummyHomePage.class);
tester.assertComponent("testPage", TestLink.class);