You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2011/03/22 11:18:48 UTC

svn commit: r1084123 - in /myfaces/tobago/trunk/tobago-core/src: main/java/org/apache/myfaces/tobago/util/ test/java/org/apache/myfaces/tobago/internal/mock/faces/ test/java/org/apache/myfaces/tobago/util/

Author: lofwyr
Date: Tue Mar 22 10:18:48 2011
New Revision: 1084123

URL: http://svn.apache.org/viewvc?rev=1084123&view=rev
Log:
TOBAGO-983: ComponentUtils.findDescendant returns the wrong component
 - fix and unit test

Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
    myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/AbstractTobagoTestBase.java
    myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/util/ComponentUtilsUnitTest.java

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java?rev=1084123&r1=1084122&r2=1084123&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java Tue Mar 22 10:18:48 2011
@@ -232,11 +232,14 @@ public class ComponentUtils {
     }
   }
 
+  /**
+   * Searches the component tree beneath the component and return the first component matching the type.
+   */
   public static <T extends UIComponent> T findDescendant(UIComponent component, Class<T> type) {
 
     for (UIComponent child : (List<UIComponent>) component.getChildren()) {
       if (type.isAssignableFrom(child.getClass())) {
-        return (T) component;
+        return (T) child;
       }
       final T descendant = findDescendant(child, type);
       if (descendant != null) {

Modified: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/AbstractTobagoTestBase.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/AbstractTobagoTestBase.java?rev=1084123&r1=1084122&r2=1084123&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/AbstractTobagoTestBase.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/AbstractTobagoTestBase.java Tue Mar 22 10:18:48 2011
@@ -23,6 +23,7 @@ import org.apache.myfaces.test.mock.Mock
 import org.apache.myfaces.tobago.component.ComponentTypes;
 import org.apache.myfaces.tobago.component.UIIn;
 import org.apache.myfaces.tobago.component.UIOut;
+import org.apache.myfaces.tobago.component.UIPanel;
 import org.apache.myfaces.tobago.config.TobagoConfig;
 import org.apache.myfaces.tobago.context.ClientProperties;
 import org.apache.myfaces.tobago.context.ResourceManagerFactory;
@@ -81,6 +82,7 @@ public abstract class AbstractTobagoTest
     // XXX is there a better way? Get it from Tobagos generated faces-config.xml?
     application.addComponent(ComponentTypes.IN, UIIn.class.getName());
     application.addComponent(ComponentTypes.OUT, UIOut.class.getName());
+    application.addComponent(ComponentTypes.PANEL, UIPanel.class.getName());
     application.addComponent("javax.faces.ViewRoot", "org.apache.myfaces.tobago.component.UIViewRoot");
     application.addComponent("javax.faces.Command", "javax.faces.component.UICommand");
     application.addComponent("org.apache.myfaces.tobago.Command", "org.apache.myfaces.tobago.component.UICommand");

Modified: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/util/ComponentUtilsUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/util/ComponentUtilsUnitTest.java?rev=1084123&r1=1084122&r2=1084123&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/util/ComponentUtilsUnitTest.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/util/ComponentUtilsUnitTest.java Tue Mar 22 10:18:48 2011
@@ -17,10 +17,16 @@ package org.apache.myfaces.tobago.util;
  * limitations under the License.
  */
 
+import org.apache.myfaces.tobago.component.ComponentTypes;
+import org.apache.myfaces.tobago.component.RendererTypes;
+import org.apache.myfaces.tobago.component.UIIn;
+import org.apache.myfaces.tobago.internal.mock.faces.AbstractTobagoTestBase;
 import org.junit.Assert;
 import org.junit.Test;
 
-public class ComponentUtilsUnitTest {
+import javax.faces.component.UIComponent;
+
+public class ComponentUtilsUnitTest extends AbstractTobagoTestBase {
 
   @Test
   public void testSplitList() {
@@ -30,4 +36,14 @@ public class ComponentUtilsUnitTest {
     Assert.assertArrayEquals(new String[]{"ab", "cd"}, ComponentUtils.splitList("ab , cd"));
     Assert.assertArrayEquals(new String[]{"ab", "cd"}, ComponentUtils.splitList("ab,,cd"));
   }
+
+  @Test
+  public void testFindDescendant() {
+    final UIComponent p = CreateComponentUtils.createComponent(ComponentTypes.PANEL, RendererTypes.PANEL, "p");
+    final UIComponent i = CreateComponentUtils.createComponent(ComponentTypes.IN, RendererTypes.IN, "i");
+    p.getChildren().add(i);
+
+    final UIIn in = ComponentUtils.findDescendant(p, UIIn.class);
+    Assert.assertEquals(i, in);
+  }
 }