Author: frankbille
Date: Wed Jun  4 00:17:55 2008
New Revision: 663013

URL: http://svn.apache.org/viewvc?rev=663013&view=rev
Log:
WICKET-1473: BaseWicketTester.isComponentOnAjaxResponse() test is too strong

Added:
    
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/MockPageWithLinkAndLabel.html
   (with props)
    
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/MockPageWithLinkAndLabel.java
   (with props)
Modified:
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
    
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java?rev=663013&r1=663012&r2=663013&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
 Wed Jun  4 00:17:55 2008
@@ -1057,7 +1057,7 @@
 
                // Look for that the component is on the response, using the 
markup id
                boolean isComponentInAjaxResponse = 
ajaxResponse.matches("(?s).*<component id=\"" +
-                       markupId + "\" ?>.*");
+                       markupId + "\"[^>]*?>.*");
                failMessage = "Component wasn't found in the AJAX response";
                return isTrue(failMessage, isComponentInAjaxResponse);
        }

Added: 
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/MockPageWithLinkAndLabel.html
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/MockPageWithLinkAndLabel.html?rev=663013&view=auto
==============================================================================
--- 
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/MockPageWithLinkAndLabel.html
 (added)
+++ 
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/MockPageWithLinkAndLabel.html
 Wed Jun  4 00:17:55 2008
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
+<html xmlns="http://www.w3.org/1999/xhtml"; 
xmlns:wicket="http://www.wicketframework.org";>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>Insert title here</title>
+</head>
+<body>
+<a wicket:id="link"><span wicket:id="label"></span></a>
+</body>
+</html>

Propchange: 
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/MockPageWithLinkAndLabel.html
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/MockPageWithLinkAndLabel.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/MockPageWithLinkAndLabel.java?rev=663013&view=auto
==============================================================================
--- 
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/MockPageWithLinkAndLabel.java
 (added)
+++ 
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/MockPageWithLinkAndLabel.java
 Wed Jun  4 00:17:55 2008
@@ -0,0 +1,43 @@
+/*
+ * 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.markup.html.WebPage;
+
+/**
+ * Mock page containing a link with a label inside
+ */
+public class MockPageWithLinkAndLabel extends WebPage<Void>
+{
+
+       /**
+        * Link wicket id
+        */
+       public static final String LINK_ID = "link";
+
+       /**
+        * Label wicket id
+        */
+       public static final String LABEL_ID = "label";
+
+       /**
+        * Label component path
+        */
+       public static final String LABEL_PATH = "link:label";
+
+
+}

Propchange: 
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/MockPageWithLinkAndLabel.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java?rev=663013&r1=663012&r2=663013&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
 (original)
+++ 
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
 Wed Jun  4 00:17:55 2008
@@ -33,6 +33,7 @@
 import org.apache.wicket.markup.html.form.Button;
 import org.apache.wicket.markup.html.form.TextField;
 import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.model.IModel;
 import org.apache.wicket.request.target.coding.IRequestTargetUrlCodingStrategy;
 import org.apache.wicket.util.tester.MockPageParameterPage.MockInnerClassPage;
 import 
org.apache.wicket.util.tester.MockPageWithFormAndAjaxFormSubmitBehavior.Pojo;
@@ -340,11 +341,81 @@
                // 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(MockPageWithLink.LINK_ID);
+
+               tester.dumpPage();
+       }
+
+       /**
+        * Test that testing if a component is on the ajax response can handle 
if the response is
+        * encoded.
+        */
+       public void testAssertComponentOnAjaxResponse_encoding()
+       {
+               final IModel<String> labelModel = new IModel<String>()
+               {
+                       private static final long serialVersionUID = 1L;
+
+                       private String value;
+
+                       public String getObject()
+                       {
+                               return value;
+                       }
+
+                       public void setObject(String object)
+                       {
+                               value = object;
+                       }
+
+                       public void detach()
+                       {
+                       }
+               };
+
+               labelModel.setObject("Label 1");
+               final Label<String> label = new 
Label<String>(MockPageWithLinkAndLabel.LABEL_ID, labelModel);
+               label.setOutputMarkupId(true);
+
+               final Page<?> page = new MockPageWithLinkAndLabel();
+               AjaxLink<?> ajaxLink = new 
AjaxLink<Void>(MockPageWithLinkAndLabel.LINK_ID)
+               {
+                       private static final long serialVersionUID = 1L;
+
+                       @Override
+                       public void onClick(AjaxRequestTarget target)
+                       {
+                               labelModel.setObject("Label which needs 
encoding: [] ][");
+                               target.addComponent(label);
+                       }
+               };
+               ajaxLink.setOutputMarkupId(true);
+
+               page.add(ajaxLink);
+               ajaxLink.add(label);
+
+               tester.startPage(new ITestPageSource()
+               {
+                       private static final long serialVersionUID = 1L;
+
+                       public Page<?> getTestPage()
+                       {
+                               return page;
+                       }
+               });
+
+
+               // Click the link
+               tester.clickLink(MockPageWithLinkAndLabel.LINK_ID);
+
+               tester.assertComponent(MockPageWithLinkAndLabel.LABEL_PATH, 
Label.class);
+
+               tester.dumpPage();
 
                // This must not fail
-               tester.assertComponentOnAjaxResponse(component);
+               
tester.assertComponentOnAjaxResponse(MockPageWithLinkAndLabel.LABEL_PATH);
+
        }
 
        /**


Reply via email to