[richfaces-svn-commits] JBoss Rich Faces SVN: r289 - trunk/richfaces/tabPanel/src/test/java/org/richfaces/component.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Thu Apr 5 10:46:01 EDT 2007
Author: A.Skokov
Date: 2007-04-05 10:46:01 -0400 (Thu, 05 Apr 2007)
New Revision: 289
Added:
trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/TabPanelComponentTest.java
Removed:
trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/JSFComponentTest.java
Log:
test for TabPanel component added
Deleted: trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/JSFComponentTest.java
===================================================================
--- trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-05 14:45:16 UTC (rev 288)
+++ trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-05 14:46:01 UTC (rev 289)
@@ -1,53 +0,0 @@
-/**
- * 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 junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import javax.faces.component.UIComponent;
-
-/**
- * Unit test for simple Component.
- */
-public class JSFComponentTest
- extends TestCase
-{
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public JSFComponentTest( String testName )
- {
- super( testName );
- }
-
-
- /**
- * Rigourous Test :-)
- */
- public void testComponent()
- {
- assertTrue( true );
- }
-}
Added: trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/TabPanelComponentTest.java
===================================================================
--- trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/TabPanelComponentTest.java (rev 0)
+++ trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/TabPanelComponentTest.java 2007-04-05 14:46:01 UTC (rev 289)
@@ -0,0 +1,222 @@
+/**
+ * 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 com.gargoylesoftware.htmlunit.html.HtmlScript;
+import junit.framework.Assert;
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.apache.commons.lang.StringUtils;
+import org.richfaces.component.html.HtmlTab;
+import org.richfaces.component.html.HtmlTabPanel;
+
+import javax.faces.component.UIForm;
+import javax.faces.component.html.HtmlForm;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Unit test for TabPanel component.
+ */
+public class TabPanelComponentTest extends AbstractAjax4JsfTestCase {
+ private static Set javaScripts = new HashSet();
+
+ static {
+ javaScripts.add("org.ajax4jsf.framework.ajax.AjaxScript");
+ javaScripts.add("prototype.js");
+ javaScripts.add("org.ajax4jsf.framework.ajax.ImageCacheScript");
+ javaScripts.add("org/richfaces/renderkit/html/scripts/browser_info.js");
+ javaScripts.add("org/ajax4jsf/renderkit/html/scripts/form.js");
+ javaScripts.add("org/richfaces/renderkit/html/scripts/tabPanel.js");
+ }
+
+ private HtmlTabPanel tabPanel;
+ private HtmlTab tab1;
+ private HtmlTab tab2;
+ private UIForm form;
+
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public TabPanelComponentTest(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);
+
+ tabPanel = (HtmlTabPanel)application.createComponent(HtmlTabPanel.COMPONENT_TYPE);
+ tabPanel.setId("tabPanel");
+ form.getChildren().add(tabPanel);
+
+ tab1 = (HtmlTab)application.createComponent(HtmlTab.COMPONENT_TYPE);
+ tab1.setId("tab1");
+ tabPanel.getChildren().add(tab1);
+
+ tab2 = (HtmlTab)application.createComponent(HtmlTab.COMPONENT_TYPE);
+ tab2.setId("tab2");
+ tabPanel.getChildren().add(tab2);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ tabPanel = null;
+ tab1 = null;
+ tab2 = null;
+ form = null;
+ }
+
+ /**
+ * Test component default values
+ *
+ * @throws Exception
+ */
+ public void testDefaultValues() throws Exception {
+ Assert.assertEquals("server", tabPanel.getSwitchType());
+ Assert.assertEquals("left", tabPanel.getHeaderAlignment());
+ Assert.assertEquals("1px", tabPanel.getHeaderSpacing());
+
+ Assert.assertEquals(tab1.getId(), tab1.getName());
+ Assert.assertEquals(tab2.getId(), tab2.getName());
+ }
+ /**
+ * 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() + ":" + tabPanel.getId());
+ Assert.assertNotNull(table);
+ Assert.assertEquals("table", table.getNodeName());
+
+ String classAttr = table.getAttributeValue("class");
+ Assert.assertTrue(classAttr.contains("rich-tabpanel"));
+
+ HtmlElement cell1 = page.getHtmlElementById(form.getId() + ":" + tab1.getId() + "_cell");
+ Assert.assertNotNull(cell1);
+ Assert.assertEquals("td", cell1.getNodeName());
+
+ String classAttr1 = cell1.getAttributeValue("class");
+ Assert.assertTrue(classAttr1.contains("dr-tbpnl-tbcell-act"));
+ Assert.assertTrue(classAttr1.contains("rich-tabhdr-cell-active"));
+
+ HtmlElement label1 = page.getHtmlElementById(form.getId() + ":" + tab1.getId() + "_lbl");
+ Assert.assertNotNull(label1);
+ Assert.assertEquals("td", label1.getNodeName());
+
+ assertEquals("RichFaces.overTab(this);", label1.getAttributeValue("onmouseover"));
+ assertEquals("RichFaces.outTab(this);", label1.getAttributeValue("onmouseout"));
+
+ String classAttrL1 = label1.getAttributeValue("class");
+ Assert.assertTrue(classAttrL1.contains("dr-tbpnl-tb"));
+ Assert.assertTrue(classAttrL1.contains("rich-tab-header"));
+ Assert.assertTrue(classAttrL1.contains("dr-tbpnl-tb-act"));
+ Assert.assertTrue(classAttrL1.contains("rich-tab-active"));
+
+ HtmlElement cell2 = page.getHtmlElementById(form.getId() + ":" + tab2.getId() + "_cell");
+ Assert.assertNotNull(cell2);
+ Assert.assertEquals("td", cell2.getNodeName());
+
+ String classAttr2 = cell2.getAttributeValue("class");
+ Assert.assertTrue(classAttr2.contains("dr-tbpnl-tbcell-inact"));
+ Assert.assertTrue(classAttr2.contains("rich-tabhdr-cell-inactive"));
+
+ HtmlElement label2 = page.getHtmlElementById(form.getId() + ":" + tab2.getId() + "_lbl");
+ Assert.assertNotNull(label2);
+ Assert.assertEquals("td", label2.getNodeName());
+
+ assertEquals("RichFaces.overTab(this);", label1.getAttributeValue("onmouseover"));
+ assertEquals("RichFaces.outTab(this);", label1.getAttributeValue("onmouseout"));
+
+ String classAttrL2 = label2.getAttributeValue("class");
+ Assert.assertTrue(classAttrL2.contains("dr-tbpnl-tb"));
+ Assert.assertTrue(classAttrL2.contains("rich-tab-header"));
+ Assert.assertTrue(classAttrL2.contains("dr-tbpnl-tb-inact"));
+ Assert.assertTrue(classAttrL2.contains("rich-tab-inactive"));
+
+ HtmlElement tab = page.getHtmlElementById(form.getId() + ":" + tab1.getId());
+ Assert.assertNotNull(tab);
+ Assert.assertEquals("td", tab.getNodeName());
+ }
+
+ /**
+ * 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/tabPanel.xcss"));
+ }
+
+ /**
+ * Test script rendering
+ *
+ * @throws Exception
+ */
+ public void testRenderScript() throws Exception {
+ HtmlPage page = renderView();
+ Assert.assertNotNull(page);
+ List scripts = page.getDocumentElement().getHtmlElementsByTagName("script");
+ for (Iterator it = scripts.iterator(); it.hasNext();) {
+ HtmlScript item = (HtmlScript) it.next();
+ String srcAttr = item.getSrcAttribute();
+
+ if (StringUtils.isNotBlank(srcAttr)) {
+ boolean found = false;
+ for (Iterator srcIt = javaScripts.iterator(); srcIt.hasNext();) {
+ String src = (String) srcIt.next();
+
+ found = srcAttr.contains(src);
+ if (found) {
+ break;
+ }
+ }
+
+ assertTrue(found);
+ }
+ }
+ }
+}
More information about the richfaces-svn-commits
mailing list