[richfaces-svn-commits] JBoss Rich Faces SVN: r282 - trunk/richfaces/toolBar/src/test/java/org/richfaces/component.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Apr 5 09:38:09 EDT 2007


Author: A.Skokov
Date: 2007-04-05 09:38:08 -0400 (Thu, 05 Apr 2007)
New Revision: 282

Added:
   trunk/richfaces/toolBar/src/test/java/org/richfaces/component/ToolBarComponentTest.java
Log:
test for ToolBar component added

Added: trunk/richfaces/toolBar/src/test/java/org/richfaces/component/ToolBarComponentTest.java
===================================================================
--- trunk/richfaces/toolBar/src/test/java/org/richfaces/component/ToolBarComponentTest.java	                        (rev 0)
+++ trunk/richfaces/toolBar/src/test/java/org/richfaces/component/ToolBarComponentTest.java	2007-04-05 13:38:08 UTC (rev 282)
@@ -0,0 +1,135 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007  Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+package org.richfaces.component;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import junit.framework.Assert;
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.html.HtmlToolBar;
+import org.richfaces.component.html.HtmlToolBarGroup;
+
+import javax.faces.component.UIForm;
+import javax.faces.component.html.HtmlCommandButton;
+import javax.faces.component.html.HtmlForm;
+import java.util.List;
+
+/**
+ * Unit test for ToolBar component.
+ */
+public class ToolBarComponentTest extends AbstractAjax4JsfTestCase {
+
+    private HtmlToolBar toolBar;
+    private HtmlToolBarGroup toolBarGroup;
+    private HtmlCommandButton button1;
+    private HtmlCommandButton button2;
+    private UIForm form;
+
+    /**
+     * Create the test case
+     *
+     * @param testName name of the test case
+     */
+    public ToolBarComponentTest(String testName) {
+        super(testName);
+    }
+
+    /* (non-Javadoc)
+     * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+     */
+    public void setUp() throws Exception {
+        super.setUp();
+
+        form = new HtmlForm();
+        form.setId("form");
+        facesContext.getViewRoot().getChildren().add(form);
+
+        toolBar = (HtmlToolBar)application.createComponent(HtmlToolBar.COMPONENT_TYPE);
+        toolBar.setId("toolBar");
+        form.getChildren().add(toolBar);
+
+        button1 = (HtmlCommandButton)application.createComponent(HtmlCommandButton.COMPONENT_TYPE);
+        button1.setValue("Change 1");
+        toolBar.getChildren().add(button1);
+
+        toolBarGroup = (HtmlToolBarGroup)application.createComponent(HtmlToolBarGroup.COMPONENT_TYPE);
+        button2 = (HtmlCommandButton)application.createComponent(HtmlCommandButton.COMPONENT_TYPE);
+        button2.setValue("Change 2");
+        toolBarGroup.getChildren().add(button2);
+
+        toolBar.getChildren().add(toolBarGroup);
+    }
+
+    /* (non-Javadoc)
+     * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+     */
+    public void tearDown() throws Exception {
+        super.tearDown();
+        toolBar = null;
+        toolBarGroup = null;
+        form = null;
+    }
+
+    /**
+     * Test component default values
+     *
+     * @throws Exception
+     */
+    public void testDefaultValues() throws Exception {
+        Assert.assertEquals("100%", toolBar.getWidth());
+        Assert.assertEquals("none", toolBar.getItemSeparator());
+        Assert.assertEquals("none", toolBarGroup.getItemSeparator());
+        Assert.assertEquals("left", toolBarGroup.getLocation());
+    }
+    /**
+     * Test component rendering
+     *
+     * @throws Exception
+     */
+    public void testRender() throws Exception {
+        HtmlPage page = renderView();
+        Assert.assertNotNull(page);
+        System.out.println(page.asXml());
+
+        HtmlElement table = page.getHtmlElementById(form.getId() + ":" + toolBar.getId());
+        Assert.assertNotNull(table);
+        Assert.assertEquals("table", table.getNodeName());
+
+        String classAttr = table.getAttributeValue("class");
+        Assert.assertTrue(classAttr.contains("dr-toolbar-ext"));
+        Assert.assertTrue(classAttr.contains("rich-toolbar"));
+    }
+
+    /**
+     * Test style rendering
+     *
+     * @throws Exception
+     */
+    public void testRenderStyle() throws Exception {
+        HtmlPage page = renderView();
+        Assert.assertNotNull(page);
+        List links = page.getDocumentElement().getHtmlElementsByTagName("link");
+        Assert.assertEquals(1, links.size());
+        HtmlElement link = (HtmlElement) links.get(0);
+        Assert.assertTrue(link.getAttributeValue("href").contains("org/richfaces/renderkit/html/css/toolBar.xcss"));
+    }
+}




More information about the richfaces-svn-commits mailing list