[richfaces-svn-commits] JBoss Rich Faces SVN: r11467 - in trunk/test-applications/seleniumTest/richfaces/src: main/webapp/pages/tree and 1 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Mon Dec 1 13:03:05 EST 2008


Author: dsvyatobatsko
Date: 2008-12-01 13:03:04 -0500 (Mon, 01 Dec 2008)
New Revision: 11467

Added:
   trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/dragAndDropTest.xhtml
Modified:
   trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/tree/TreeTestBean.java
   trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeTest.java
Log:
https://jira.jboss.org/jira/browse/RF-4832

Modified: trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/tree/TreeTestBean.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/tree/TreeTestBean.java	2008-12-01 17:08:05 UTC (rev 11466)
+++ trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/tree/TreeTestBean.java	2008-12-01 18:03:04 UTC (rev 11467)
@@ -33,10 +33,13 @@
 import org.apache.commons.digester.Digester;
 import org.apache.commons.digester.xmlrules.DigesterLoader;
 import org.richfaces.component.UITree;
+import org.richfaces.component.UITreeNode;
 import org.richfaces.component.state.TreeStateAdvisor;
+import org.richfaces.event.DropEvent;
 import org.richfaces.event.NodeSelectedEvent;
 import org.richfaces.model.TreeNode;
 import org.richfaces.model.TreeNodeImpl;
+import org.richfaces.model.TreeRowKey;
 import org.xml.sax.SAXException;
 
 /**
@@ -184,6 +187,29 @@
         this.nodeTitle = nodeTitle;
     }
 
+    public void dropListener(DropEvent dropEvent) {
+        //we have only one tree: destination tree coincides with source one
+        UITree tree = ((UITreeNode) dropEvent.getSource()).getUITree();
+
+        TreeRowKey<Object> dropNodeKey = (TreeRowKey<Object>) dropEvent.getDropValue();
+        TreeNode<Object> dropNode = tree.getTreeNode(dropNodeKey);
+
+        TreeRowKey<Object> draggedNodeKey = (TreeRowKey<Object>) dropEvent.getDragValue();
+        TreeNode<Object> draggedNode = tree.getTreeNode(draggedNodeKey);
+
+        //mark destination node as wanting rerendering
+        tree.addRequestKey(dropNodeKey);
+        Object state = null;
+        if(null != draggedNodeKey) {
+            // 1. mark its parent as wanting rerendering
+            tree.addRequestKey(tree.getTreeNodeRowKey(draggedNode.getParent()));
+            // 2. remove node from tree
+            state = tree.removeNode(draggedNodeKey);
+            // 3. add the node at the new place
+            tree.addNode(dropNodeKey, draggedNode, System.currentTimeMillis(), state);
+        }
+    }
+
     private String switchType = "ajax";
 
     /**
@@ -300,6 +326,12 @@
         setRichModel(true);
     }
 
+    public void initDragAndDropTest() {
+        if(advisor == null) {
+            setAdvisor(new TestAdvisor());
+        }
+    }
+
     private TreeStateAdvisor advisor;
 
     /**

Added: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/dragAndDropTest.xhtml
===================================================================
(Binary files differ)


Property changes on: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/dragAndDropTest.xhtml
___________________________________________________________________
Name: svn:mime-type
   + application/xhtml+xml

Modified: trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeTest.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeTest.java	2008-12-01 17:08:05 UTC (rev 11466)
+++ trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeTest.java	2008-12-01 18:03:04 UTC (rev 11467)
@@ -24,6 +24,8 @@
     private final static String INIT_CLIENT_MODE = "#{treeBean.initClientMode}";
     private final static String INIT_ADVISOR_TEST = "#{treeBean.initStateAdvisorTest}";
     private final static String TEAR_DOWN_METHOD = "#{treeBean.tearDown}";
+    private final static String INIT_DRAG_AND_DROP_TEST = "#{treeBean.initDragAndDropTest}";
+    private final static String DRAG_AND_DROP_TEST_URL = "pages/tree/dragAndDropTest.xhtml";
 
     static {
         params.put("parameter1", "value1");
@@ -473,6 +475,34 @@
         Assert.assertTrue(isVisible("//*[@id='"+ compId + ":childs']/div[2]/div"), "It looks as if there are unexpanded nodes here");
     }
 
+    @Test
+    public void testDragAndDrop(Template template) {
+        renderPage(DRAG_AND_DROP_TEST_URL, template, INIT_DRAG_AND_DROP_TEST);
+        writeStatus("Check drag-and-drop ability");
+
+        String compId = getParentId() + "_form:tree";
+        String britneyAlbumXpath = "//*[@id='"+ compId + ":childs']/div[1]/table/tbody/tr/td[3]";
+        String britney1stSongXpath = "//*[@id='"+ compId + ":childs']/div[1]/div/table/tbody/tr/td[3]";
+
+        String aguileraAlbumXpath = "//*[@id='"+ compId + ":childs']/div[2]/table/tbody/tr/td[3]";
+        String aguilera1stSongXpath = "//*[@id='"+ compId + ":childs']/div[2]/div/table/tbody/tr/td[3]";
+
+        int britneySons = getNodesCount("//*[@id='"+ compId + ":childs']/div[1]/div");
+        int aguileraSongs = getNodesCount("//*[@id='"+ compId + ":childs']/div[2]/div");
+
+        writeStatus("Try to have brithey's song dragged");
+        selenium.dragAndDropToObject(britney1stSongXpath, aguileraAlbumXpath);
+        waitForAjaxCompletion();
+        assertChildNodesCount(--britneySons, "//*[@id='"+ compId + ":childs']/div[1]/div", "Song is not dragged");
+        assertChildNodesCount(++aguileraSongs, "//*[@id='"+ compId + ":childs']/div[2]/div", "Song is not dropped");
+
+        writeStatus("Now try to drop song back");
+        selenium.dragAndDropToObject(aguilera1stSongXpath, britneyAlbumXpath);
+        waitForAjaxCompletion();
+        assertChildNodesCount(++britneySons, "//*[@id='"+ compId + ":childs']/div[1]/div", "Song is not dragged back");
+        assertChildNodesCount(--aguileraSongs, "//*[@id='"+ compId + ":childs']/div[2]/div", "Song is not dropped back");
+    }
+
     @Override
     public void sendAjax() {
         AutoTester tester = getAutoTester(this);
@@ -504,4 +534,19 @@
         }
     }
 
+    /**
+     * Asserts that given div <code>containingDiv</code> contains <code>childrenCount</code> nodes
+     * @param nodesCount expected nodes count
+     * @param xpath xpath location of nodes containing div
+     * @param errorMsg error msg
+     */
+    private void assertChildNodesCount(int nodesCount, String xpath, String errorMsg) {
+        int count = getNodesCount(xpath);
+        Assert.assertEquals(count, nodesCount, errorMsg);
+    }
+
+    private int getNodesCount(String xpath) {
+        return selenium.getXpathCount(xpath + "/table").intValue();
+    }
+
 }




More information about the richfaces-svn-commits mailing list