You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2010/07/17 09:44:05 UTC

svn commit: r965024 - in /click/trunk/click: extras/test/org/apache/click/extras/control/ framework/test/org/apache/click/control/

Author: sabob
Date: Sat Jul 17 07:44:05 2010
New Revision: 965024

URL: http://svn.apache.org/viewvc?rev=965024&view=rev
Log:
added tests to prepare for CLK-712

Added:
    click/trunk/click/extras/test/org/apache/click/extras/control/PickListTest.java
Modified:
    click/trunk/click/extras/test/org/apache/click/extras/control/TabbedFormTest.java
    click/trunk/click/framework/test/org/apache/click/control/FieldSetTest.java
    click/trunk/click/framework/test/org/apache/click/control/FormTest.java

Added: click/trunk/click/extras/test/org/apache/click/extras/control/PickListTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/test/org/apache/click/extras/control/PickListTest.java?rev=965024&view=auto
==============================================================================
--- click/trunk/click/extras/test/org/apache/click/extras/control/PickListTest.java (added)
+++ click/trunk/click/extras/test/org/apache/click/extras/control/PickListTest.java Sat Jul 17 07:44:05 2010
@@ -0,0 +1,68 @@
+/*
+ * 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.click.extras.control;
+
+import junit.framework.TestCase;
+import org.apache.click.MockContainer;
+import org.apache.click.MockContext;
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * Provides tests for the PickList control.
+ */
+public class PickListTest extends TestCase {
+
+    /**
+     * Check that PickList style attribute is only rendered once.
+     *
+     * CLK-712: In Click 2.2.0 the class attribute was removed before rendering the
+     * pickList attributes, after which the class attribute was added again.
+     * This could cause concurrent modification exceptions if the PickList is rendered
+     * by multiple threads.
+     */
+    public void testClassAttributeRenderin() {
+        // PickList uses Velocity to render its template. In this test we start a
+        // MockContainer which also configures Velocity
+        MockContainer container = new MockContainer("web");
+        container.start();
+
+        // MockContext is created when a container tests a page. There
+        // is no page to test so we manually create a MockContext
+        // and reuse the Mock Servlet objects created in the container.
+        MockContext.initContext(container.getServletConfig(),
+            container.getRequest(), container.getResponse(), container.getClickServlet());
+
+        PickList pickList = new PickList("pickList");
+
+        pickList.addStyleClass("white");
+
+        String pickListStr = pickList.toString();
+
+        // Perform checks within the first 60 characters
+        pickListStr = pickListStr.substring(0, 60);
+
+        // Check that class attribute was rendered
+        assertEquals(1, StringUtils.countMatches(pickListStr, "class=\"white picklist\""));
+
+        // Check that class attribute was rendered once
+        assertEquals(1, StringUtils.countMatches(pickListStr, "class="));
+
+        container.stop();
+    }
+}

Modified: click/trunk/click/extras/test/org/apache/click/extras/control/TabbedFormTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/test/org/apache/click/extras/control/TabbedFormTest.java?rev=965024&r1=965023&r2=965024&view=diff
==============================================================================
--- click/trunk/click/extras/test/org/apache/click/extras/control/TabbedFormTest.java (original)
+++ click/trunk/click/extras/test/org/apache/click/extras/control/TabbedFormTest.java Sat Jul 17 07:44:05 2010
@@ -25,12 +25,14 @@ import org.apache.click.MockContext;
 public class TabbedFormTest extends TestCase {
 
     public void testGetHeadElements() {
+        // TabbedForm uses Velocity to render its template. In this test we start a
+        // MockContainer which also configures Velocity
         MockContainer container = new MockContainer("web");
         container.start();
 
         // MockContext is created when a container tests a page. There
-        // are no pages to test here so we manually create a MockContext,
-        // but reuse the Mock Servlet objects created in the container.
+        // is no page to test so we manually create a MockContext
+        // and reuse the Mock Servlet objects created in the container.
         MockContext.initContext(container.getServletConfig(),
             container.getRequest(), container.getResponse(), container.getClickServlet());
 

Modified: click/trunk/click/framework/test/org/apache/click/control/FieldSetTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/FieldSetTest.java?rev=965024&r1=965023&r2=965024&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/FieldSetTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/control/FieldSetTest.java Sat Jul 17 07:44:05 2010
@@ -21,6 +21,7 @@ package org.apache.click.control;
 import junit.framework.TestCase;
 import org.apache.click.Control;
 import org.apache.click.MockContext;
+import org.apache.commons.lang.StringUtils;
 
 /**
  * Test FieldSet behavior.
@@ -475,6 +476,37 @@ public class FieldSetTest extends TestCa
     }
 
     /**
+     * Check that Label style attribute is not rendered on the parent TD element.
+     *
+     * CLK-712: In Click 2.2.0 the label style attribute was removed before rendering the
+     * label attributes, after which the label style attribute was added again.
+     * This could cause concurrent modification exceptions if the FieldSet is rendered
+     * by multiple threads.
+     */
+    public void testLabelStyle() {
+        Form form = new Form("form");
+        FieldSet fieldset = new FieldSet("fieldset");
+        form.add(fieldset);
+
+        Label label = new Label("label");
+        fieldset.add(label);
+
+        // Parent hint should be rendered as the TD style
+        label.setParentStyleHint("color: white;");
+
+        // Label style should not be rendered
+        label.setStyle("color", "black");
+
+        String fieldsetStr = fieldset.toString();
+
+        // Check that parentStyleHint style was rendered
+        assertEquals(1, StringUtils.countMatches(fieldsetStr, "style=\"color: white;\""));
+
+        // Check that the label style was not rendered
+        assertEquals(1, StringUtils.countMatches(fieldsetStr, "style="));
+    }
+
+    /**
      * A custom Div container.
      */
     static class Div extends AbstractContainer {

Modified: click/trunk/click/framework/test/org/apache/click/control/FormTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/FormTest.java?rev=965024&r1=965023&r2=965024&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/FormTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/control/FormTest.java Sat Jul 17 07:44:05 2010
@@ -23,6 +23,7 @@ import junit.framework.TestCase;
 import org.apache.click.MockContext;
 import org.apache.click.Page;
 import org.apache.click.servlet.MockRequest;
+import org.apache.commons.lang.StringUtils;
 
 /**
  * Test Form behavior.
@@ -819,6 +820,35 @@ public class FormTest extends TestCase {
     }
 
     /**
+     * Check that Label style attribute is not rendered on the parent TD element.
+     *
+     * CLK-712: In Click 2.2.0 the label style attribute was removed before rendering the
+     * label attributes, after which the label style attribute was added again.
+     * This could cause concurrent modification exceptions if the Form is rendered
+     * by multiple threads.
+     */
+    public void testLabelStyle() {
+        Form form = new Form("form");
+
+        Label label = new Label("label");
+        form.add(label);
+
+        // Parent hint should be rendered as the TD style
+        label.setParentStyleHint("color: white;");
+
+        // Label style should not be rendered
+        label.setStyle("color", "black");
+
+        String formStr = form.toString();
+
+        // Check that parentStyleHint style was rendered
+        assertEquals(1, StringUtils.countMatches(formStr, "style=\"color: white;\""));
+
+        // Check that the label style was not rendered
+        assertEquals(1, StringUtils.countMatches(formStr, "style="));
+    }
+
+    /**
      * Populate the given Form with hidden fields.
      *
      * @param count the number of hidden fields to add