Author: mgrigorov Date: Sun Nov 14 18:44:57 2010 New Revision: 1035045 URL: http://svn.apache.org/viewvc?rev=1035045&view=rev Log: WICKET-3164 executeAjaxEvent in WicketTester works although Component is not enabled
Add checks for isVisibleInHierarchy() and isEnabledInHierarchy() for tester.clickLink() and .executeAjaxEvent() Modified: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java Modified: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java?rev=1035045&r1=1035044&r2=1035045&view=diff ============================================================================== --- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java (original) +++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java Sun Nov 14 18:44:57 2010 @@ -720,6 +720,18 @@ public class BaseWicketTester extends Mo { Component linkComponent = getComponentFromLastRenderedPage(path); + if (linkComponent.isVisibleInHierarchy() == false) + { + fail("The component is currently not visible in the hierarchy and thus you can not fire events on it." + + " Component: " + linkComponent); + } + + if (linkComponent.isEnabledInHierarchy() == false) + { + fail("The component is currently not enabled in the hierarchy and thus you can not be clicked." + + " Component: " + linkComponent); + } + // if the link is an AjaxLink, we process it differently // than a normal link if (linkComponent instanceof AjaxLink) @@ -1239,6 +1251,12 @@ public class BaseWicketTester extends Mo " Component: " + component + "; Event: " + event); } + if (component.isEnabledInHierarchy() == false) + { + fail("The component is currently not enabled in the hierarchy and thus you can not fire events on it." + + " Component: " + component + "; Event: " + event); + } + // Run through all the behavior and select the LAST ADDED behavior which // matches the event parameter. AjaxEventBehavior ajaxEventBehavior = null; Modified: wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java?rev=1035045&r1=1035044&r2=1035045&view=diff ============================================================================== --- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java (original) +++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java Sun Nov 14 18:44:57 2010 @@ -208,6 +208,52 @@ public class WicketTesterTest extends Te } /** + * WICKET-3164 + * + * @throws Exception + */ + public void testClickLink_ajaxLink_notEnabled() throws Exception + { + tester.startPage(LinkPage.class); + tester.assertRenderedPage(LinkPage.class); + + tester.getComponentFromLastRenderedPage("ajaxLinkWithSetResponsePageClass").setEnabled( + false); + try + { + tester.clickLink("ajaxLinkWithSetResponsePageClass"); + fail("Disabled link should not be clickable."); + } + catch (Exception _) + { + ; + } + } + + /** + * WICKET-3164 + * + * @throws Exception + */ + public void testExecuteAjaxEvent_componentNotEnabled() throws Exception + { + tester.startPage(LinkPage.class); + tester.assertRenderedPage(LinkPage.class); + + tester.getComponentFromLastRenderedPage("ajaxLinkWithSetResponsePageClass").setEnabled( + false); + try + { + tester.executeAjaxEvent("ajaxLinkWithSetResponsePageClass", "onclick"); + fail("Disabled link should not be clickable."); + } + catch (Exception _) + { + ; + } + } + + /** * @throws Exception */ public void testClickLink_ajaxLink_setResponsePage() throws Exception