You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by fr...@apache.org on 2006/11/08 00:35:15 UTC
svn commit: r472330 - in /incubator/wicket/trunk/wicket/src:
main/java/wicket/util/tester/ test/java/wicket/util/tester/
Author: frankbille
Date: Tue Nov 7 15:35:14 2006
New Revision: 472330
URL: http://svn.apache.org/viewvc?view=rev&rev=472330
Log:
WICKET-38 - A proposol of a fix to this issue.
Added:
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockResourceLinkPage.html (with props)
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockResourceLinkPage.java (with props)
Modified:
incubator/wicket/trunk/wicket/src/main/java/wicket/util/tester/WicketTester.java
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/WicketTesterTest.java
Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/util/tester/WicketTester.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/util/tester/WicketTester.java?view=diff&rev=472330&r1=472329&r2=472330
==============================================================================
--- incubator/wicket/trunk/wicket/src/main/java/wicket/util/tester/WicketTester.java (original)
+++ incubator/wicket/trunk/wicket/src/main/java/wicket/util/tester/WicketTester.java Tue Nov 7 15:35:14 2006
@@ -37,6 +37,7 @@
import wicket.Page;
import wicket.PageParameters;
import wicket.RequestCycle;
+import wicket.Resource;
import wicket.WicketRuntimeException;
import wicket.ajax.AjaxEventBehavior;
import wicket.ajax.AjaxRequestTarget;
@@ -58,6 +59,7 @@
import wicket.markup.html.link.IPageLink;
import wicket.markup.html.link.Link;
import wicket.markup.html.link.PageLink;
+import wicket.markup.html.link.ResourceLink;
import wicket.markup.html.list.ListView;
import wicket.markup.html.panel.Panel;
import wicket.protocol.http.MockWebApplication;
@@ -766,6 +768,34 @@
// process the request target
requestCycle.getRequestTarget().respond(requestCycle);
}
+ // ResourceLink
+ else if (linkComponent instanceof ResourceLink)
+ {
+ // Let's see if we should invoke the onclick or not
+ Resource resource = null;
+
+ try
+ {
+ Field resourceField = ResourceLink.class.getDeclaredField("resource");
+ resourceField.setAccessible(true);
+ resource = (Resource)resourceField.get(linkComponent);
+ }
+ catch(Exception e)
+ {
+ Assert.fail(e.getMessage());
+ }
+
+ // If the link holds the resource itself we should
+ if (resource != null)
+ {
+ newRequestToComponent(linkComponent);
+ }
+ // Else we should not (Should we do anything else?)
+ else
+ {
+ // Do nothing
+ }
+ }
// if the link is a normal link
else if (linkComponent instanceof Link)
{
@@ -794,7 +824,7 @@
}
}
-
+
newRequestToComponent(link);
}
else
Added: incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockResourceLinkPage.html
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockResourceLinkPage.html?view=auto&rev=472330
==============================================================================
--- incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockResourceLinkPage.html (added)
+++ incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockResourceLinkPage.html Tue Nov 7 15:35:14 2006
@@ -0,0 +1 @@
+<a wicket:id="link">Link</a>
\ No newline at end of file
Propchange: incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockResourceLinkPage.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockResourceLinkPage.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockResourceLinkPage.java?view=auto&rev=472330
==============================================================================
--- incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockResourceLinkPage.java (added)
+++ incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockResourceLinkPage.java Tue Nov 7 15:35:14 2006
@@ -0,0 +1,41 @@
+/*
+ * $Id: org.eclipse.jdt.ui.prefs 5004 2006-03-17 20:47:08 -0800 (Fri, 17 Mar 2006) eelco12 $
+ * $Revision: 5004 $
+ * $Date: 2006-03-17 20:47:08 -0800 (Fri, 17 Mar 2006) $
+ *
+ * ==============================================================================
+ * Licensed 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.util.tester;
+
+import wicket.ResourceReference;
+import wicket.markup.html.WebPage;
+import wicket.markup.html.link.ResourceLink;
+
+/**
+ * Mock page for testing WicketTesters ability to test ResourceLinks
+ *
+ * @author frankbille
+ */
+public class MockResourceLinkPage extends WebPage
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Construct.
+ */
+ public MockResourceLinkPage()
+ {
+ new ResourceLink(this, "link", new ResourceReference(MockResourceLinkPage.class, "MockResourceLinkPage.html"));
+ }
+}
Propchange: incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockResourceLinkPage.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/WicketTesterTest.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/WicketTesterTest.java?view=diff&rev=472330&r1=472329&r2=472330
==============================================================================
--- incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/WicketTesterTest.java (original)
+++ incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/WicketTesterTest.java Tue Nov 7 15:35:14 2006
@@ -39,7 +39,6 @@
import wicket.util.tester.apps_1.ViewBook;
-
/**
*
* @author Juergen Donnerstag
@@ -47,7 +46,7 @@
public class WicketTesterTest extends TestCase
{
private boolean eventExecuted;
-
+
@Override
protected void setUp() throws Exception
{
@@ -171,7 +170,7 @@
tester.clickLink("link");
tester.assertRenderedPage(CreateBook.class);
}
-
+
/**
*
*/
@@ -179,7 +178,7 @@
{
// Start the tester
WicketTester tester = new WicketTester();
-
+
final Page page = new MockPageWithLink();
AjaxLink ajaxLink = new AjaxLink(page, MockPageWithLink.LINK_ID)
{
@@ -189,7 +188,8 @@
public void onClick(AjaxRequestTarget target)
{
// Replace the link with a normal Link
- Link link = new Link(page, MockPageWithLink.LINK_ID) {
+ Link link = new Link(page, MockPageWithLink.LINK_ID)
+ {
private static final long serialVersionUID = 1L;
@Override
@@ -199,13 +199,14 @@
}
};
link.setOutputMarkupId(true);
-
+
target.addComponent(link);
}
};
ajaxLink.setOutputMarkupId(true);
-
- tester.startPage(new ITestPageSource() {
+
+ tester.startPage(new ITestPageSource()
+ {
private static final long serialVersionUID = 1L;
public Page getTestPage()
@@ -213,17 +214,17 @@
return page;
}
});
-
-
+
+
// Click the link
tester.clickLink(MockPageWithLink.LINK_ID);
// The link must be a Link :)
tester.assertComponent(MockPageWithLink.LINK_ID, Link.class);
-
+
// Get the new link component
Component component = tester.getComponentFromLastRenderedPage(MockPageWithLink.LINK_ID);
-
+
// This must not fail
tester.assertComponentOnAjaxResponse(component);
}
@@ -267,7 +268,7 @@
assertTrue(eventExecuted);
}
-
+
/**
*
*/
@@ -286,5 +287,18 @@
// label should now have "1" in it because that's what comes
// from the page parameter.
tester.assertLabel("label", "1");
+ }
+
+ /**
+ * Test that clickLink on a ResourceLink with a ResourceReference on it
+ * works.
+ */
+ public void testClickResourceLink()
+ {
+ WicketTester tester = new WicketTester();
+
+ tester.startPage(MockResourceLinkPage.class);
+
+ tester.clickLink("link");
}
}