[richfaces-svn-commits] JBoss Rich Faces SVN: r291 - in trunk/richfaces/menu-components/src/test: java/org/richfaces and 3 other directories.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Thu Apr 5 10:54:01 EDT 2007
Author: F.antonov
Date: 2007-04-05 10:54:01 -0400 (Thu, 05 Apr 2007)
New Revision: 291
Added:
trunk/richfaces/menu-components/src/test/java/org/richfaces/component/MenuItemComponentTest.java
trunk/richfaces/menu-components/src/test/java/org/richfaces/component/html/
trunk/richfaces/menu-components/src/test/java/org/richfaces/component/html/HtmlMenuItemTest.java
trunk/richfaces/menu-components/src/test/java/org/richfaces/taglib/
trunk/richfaces/menu-components/src/test/java/org/richfaces/taglib/MenuItemTagTest.java
Removed:
trunk/richfaces/menu-components/src/test/java/org/richfaces/component/JSFComponentTest.java
trunk/richfaces/menu-components/src/test/resources/
Log:
MenuItem test cases development.
Deleted: trunk/richfaces/menu-components/src/test/java/org/richfaces/component/JSFComponentTest.java
===================================================================
--- trunk/richfaces/menu-components/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-05 14:48:13 UTC (rev 290)
+++ trunk/richfaces/menu-components/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-05 14:54:01 UTC (rev 291)
@@ -1,94 +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;
-import javax.faces.component.html.HtmlOutputText;
-
-import org.richfaces.component.html.HtmlMenuItem;
-import org.richfaces.renderkit.html.MenuItemRenderer;
-
-import com.gargoylesoftware.htmlunit.html.HtmlPage;
-import com.gargoylesoftware.htmlunit.html.HtmlElement;
-
-import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
-
-/**
- * Unit test for simple Component.
- */
-public class JSFComponentTest
- extends AbstractAjax4JsfTestCase
-{
-
- HtmlMenuItem menuItem;
-
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public JSFComponentTest( String testName )
- {
- super( testName );
- }
-
- public void setUp() throws Exception {
- super.setUp();
- menuItem = new HtmlMenuItem();
- menuItem.setId("menuItem");
- menuItem.setRendererType("org.richfaces.MenuItemRenderer");
- facesContext.getViewRoot().getChildren().add(menuItem);
- renderKit.addRenderer(menuItem.COMPONENT_FAMILY, "org.richfaces.MenuItemRenderer", new MenuItemRenderer());
- }
-
- public void tearDown() throws Exception {
- super.tearDown();
- menuItem = null;
- }
-
- /**
- * Rigourous Test :-)
- */
- public void testRender() throws Exception
- {
- HtmlPage page = renderView();
- assertNotNull(page);
- System.out.println(page.asXml());
- HtmlElement div = page.getHtmlElementById("menuItem");
- assertNotNull(div);
- assertEquals("div", div.getNodeName());
- }
-
- public void testRenderHeader() throws Exception
- {
- UIComponent text = createComponent(HtmlOutputText.COMPONENT_TYPE, HtmlOutputText.class.getName(), null, null , null);
- menuItem.getFacets().put("iconDisabled", text);
- HtmlPage page = renderView();
- assertNotNull(page);
- System.out.println(page.asXml());
- HtmlElement span = page.getHtmlElementById("menuItem:icon");
- assertNotNull(span);
- }
-}
Copied: trunk/richfaces/menu-components/src/test/java/org/richfaces/component/MenuItemComponentTest.java (from rev 275, trunk/richfaces/menu-components/src/test/java/org/richfaces/component/JSFComponentTest.java)
===================================================================
--- trunk/richfaces/menu-components/src/test/java/org/richfaces/component/MenuItemComponentTest.java (rev 0)
+++ trunk/richfaces/menu-components/src/test/java/org/richfaces/component/MenuItemComponentTest.java 2007-04-05 14:54:01 UTC (rev 291)
@@ -0,0 +1,211 @@
+/**
+ * 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 java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
+import javax.faces.component.html.HtmlForm;
+import javax.faces.component.html.HtmlOutputText;
+//import org.apache.commons.lang.StringUtils;
+
+import org.richfaces.component.html.HtmlMenuItem;
+import org.richfaces.renderkit.html.MenuItemRenderer;
+
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlScript;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+
+import org.ajax4jsf.framework.renderer.ComponentVariables;
+import org.ajax4jsf.framework.renderer.ComponentsVariableResolver;
+
+
+/**
+ * Unit test for simple Component.
+ */
+public class MenuItemComponentTest
+ extends AbstractAjax4JsfTestCase
+{
+ private static Set javaScripts = new HashSet();
+
+/* static {
+ javaScripts.add("org.ajax4jsf.framework.ajax.AjaxScript()");
+ javaScripts.add("org.ajax4jsf.framework.resource.PrototypeScript()");
+ javaScripts.add("org.ajax4jsf.framework.util.command.CommandScript()");
+ }
+*/
+ private HtmlMenuItem menuItem;
+ private UIForm form;
+
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public MenuItemComponentTest( String testName )
+ {
+ super( testName );
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ form = new HtmlForm();
+ form.setId("form");
+ facesContext.getViewRoot().getChildren().add(form);
+
+ menuItem = (HtmlMenuItem) application.createComponent(HtmlMenuItem.COMPONENT_TYPE);
+ menuItem.setId("menuItem");
+ menuItem.setValue("Menu Item");
+
+ form.getChildren().add(menuItem);
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ menuItem = null;
+ form = null;
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testMenuItemRender() throws Exception
+ {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ System.out.println(page.asXml());
+ HtmlElement div = page.getHtmlElementById(form.getId() + ":" + menuItem.getId());
+ assertNotNull(div);
+ assertEquals("div", div.getNodeName());
+ }
+
+ public void testMenuItemIconFacet() throws Exception
+ {
+ UIComponent text = createComponent(HtmlOutputText.COMPONENT_TYPE, HtmlOutputText.class.getName(), null, null , null);
+ menuItem.getFacets().put("iconDisabled", text);
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ System.out.println(page.asXml());
+ HtmlElement span = page.getHtmlElementById(form.getId() + ":" + menuItem.getId() + ":icon");
+ assertEquals("span", span.getNodeName());
+ assertNotNull(span);
+ }
+
+ public void testDisabledMenuItem() throws Exception
+ {
+ menuItem.setDisabled(true);
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ System.out.println(page.asXml());
+
+ HtmlElement span = page.getHtmlElementById(form.getId() + ":" + menuItem.getId() + ":disabled");
+ assertNotNull(span);
+ assertEquals("span", span.getNodeName());
+ String classAttr = span.getAttributeValue("class");
+ Assert.assertTrue(classAttr.contains("dr-menu-label dr-menu-label-disabled rich-menu-item-label rich-menu-item-label-disabled"));
+
+ span = page.getHtmlElementById(form.getId() + ":" + menuItem.getId() + ":icon");
+ assertNotNull(span);
+ assertEquals("span", span.getNodeName());
+ classAttr = span.getAttributeValue("class");
+ Assert.assertTrue(classAttr.contains("dr-menu-icon dr-menu-icon-disabled rich-menu-item-icon rich-menu-item-icon-disabled"));
+
+ HtmlElement div = page.getHtmlElementById(form.getId() + ":" + menuItem.getId());
+ assertNotNull(div);
+ assertEquals("div", div.getNodeName());
+ classAttr = div.getAttributeValue("class");
+ Assert.assertTrue(classAttr.contains("dr-menu-item dr-menu-item-disabled rich-menu-item rich-menu-item-disabled"));
+ }
+
+ public void testEnabledMenuItem() throws Exception
+ {
+ assertEquals(false, menuItem.isDisabled());
+ menuItem.setIconClass("iconClass");
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ System.out.println(page.asXml());
+
+ HtmlElement anchor = page.getHtmlElementById(form.getId() + ":" + menuItem.getId() + ":anchor");
+ assertNotNull(anchor);
+ assertEquals("a", anchor.getNodeName());
+ String classAttr = anchor.getAttributeValue("class");
+ Assert.assertTrue(classAttr.contains("dr-menu-label rich-menu-item-label"));
+
+ HtmlElement span = page.getHtmlElementById(form.getId() + ":" + menuItem.getId() + ":icon");
+ assertNotNull(span);
+ assertEquals("span", span.getNodeName());
+ classAttr = span.getAttributeValue("class");
+ Assert.assertTrue(classAttr.contains("dr-menu-icon rich-menu-item-icon " + menuItem.getIconClass()));
+
+ HtmlElement div = page.getHtmlElementById(form.getId() + ":" + menuItem.getId());
+ assertNotNull(div);
+ assertEquals("div", div.getNodeName());
+ classAttr = div.getAttributeValue("class");
+ Assert.assertTrue(classAttr.contains("dr-menu-item dr-menu-item-enabled rich-menu-item rich-menu-item-enabled"));
+ }
+
+ public void testRenderStyle() throws Exception {
+ HtmlPage page = renderView();
+ Assert.assertNotNull(page);
+ List links = page.getDocumentElement().getHtmlElementsByTagName("link");
+ //Assert.assertEquals(1, links.size());
+ Assert.assertNotNull(links);
+ HtmlElement link = (HtmlElement) links.get(0);
+ Assert.assertTrue(link.getAttributeValue("href").contains("org/richfaces/renderkit/html/css/menucomponents.xcss"));
+ }
+
+/* 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);
+ }
+ }
+ }
+*/
+}
Added: trunk/richfaces/menu-components/src/test/java/org/richfaces/component/html/HtmlMenuItemTest.java
===================================================================
--- trunk/richfaces/menu-components/src/test/java/org/richfaces/component/html/HtmlMenuItemTest.java (rev 0)
+++ trunk/richfaces/menu-components/src/test/java/org/richfaces/component/html/HtmlMenuItemTest.java 2007-04-05 14:54:01 UTC (rev 291)
@@ -0,0 +1,63 @@
+/**
+ * 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.html;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+
+/**
+ * Unit test for HtmlSuggestionBox.
+ */
+public class HtmlMenuItemTest extends AbstractAjax4JsfTestCase {
+ public HtmlMenuItemTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Test save/restore state
+ *
+ * @throws Exception
+ */
+ public void testSaveStateFacesContext() throws Exception {
+ HtmlMenuItem menuItem = new HtmlMenuItem();
+ menuItem.setStyleClass("styleClass");
+ menuItem.setStyle("style");
+ Object state = menuItem.saveState(facesContext);
+ HtmlMenuItem newMenuItem = new HtmlMenuItem();
+ newMenuItem.restoreState(facesContext, state);
+ assertEquals("styleClass", newMenuItem.getStyleClass());
+ assertEquals("style", newMenuItem.getStyle());
+ }
+}
Added: trunk/richfaces/menu-components/src/test/java/org/richfaces/taglib/MenuItemTagTest.java
===================================================================
--- trunk/richfaces/menu-components/src/test/java/org/richfaces/taglib/MenuItemTagTest.java (rev 0)
+++ trunk/richfaces/menu-components/src/test/java/org/richfaces/taglib/MenuItemTagTest.java 2007-04-05 14:54:01 UTC (rev 291)
@@ -0,0 +1,91 @@
+/**
+ * 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.taglib;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.html.HtmlMenuItem;
+
+import javax.faces.webapp.UIComponentTag;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.Tag;
+
+public class MenuItemTagTest extends AbstractAjax4JsfTestCase {
+
+ MenuItemTag tag;
+
+ public MenuItemTagTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ tag = new MenuItemTag();
+ tag.setParent(new UIComponentTag(){
+
+ public String getComponentType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getRendererType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public int doStartTag() throws JspException {
+ // TODO Auto-generated method stub
+ return Tag.EVAL_BODY_INCLUDE;
+ }
+
+ public int doEndTag() throws JspException {
+ // TODO Auto-generated method stub
+ return Tag.EVAL_BODY_INCLUDE;
+ }
+
+ });
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ tag = null;
+ }
+
+ /**
+ * Test method for {@link org.richfaces.taglib.SuggestionBoxTag#setProperties(javax.faces.component.UIComponent)}.
+ * @throws JspException
+ */
+ public void testSetPropertiesUIComponent() throws JspException {
+ HtmlMenuItem menuItem = new HtmlMenuItem();
+
+ tag.setStyleClass("styleClass");
+ tag.setStyle("style");
+ tag.setProperties(menuItem);
+ assertEquals("styleClass", menuItem.getStyleClass());
+ assertEquals("style", menuItem.getStyle());
+ }
+}
More information about the richfaces-svn-commits
mailing list