[richfaces-svn-commits] JBoss Rich Faces SVN: r270 - in trunk/richfaces/datascroller/src/test/java/org/richfaces: component and 2 other directories.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Wed Apr 4 09:38:44 EDT 2007
Author: A.Skokov
Date: 2007-04-04 09:38:43 -0400 (Wed, 04 Apr 2007)
New Revision: 270
Added:
trunk/richfaces/datascroller/src/test/java/org/richfaces/component/DatascrollerComponentTest.java
trunk/richfaces/datascroller/src/test/java/org/richfaces/component/html/
trunk/richfaces/datascroller/src/test/java/org/richfaces/component/html/HtmlDatascrollerTest.java
trunk/richfaces/datascroller/src/test/java/org/richfaces/taglib/
trunk/richfaces/datascroller/src/test/java/org/richfaces/taglib/DatascrollerTagTest.java
Removed:
trunk/richfaces/datascroller/src/test/java/org/richfaces/component/JSFComponentTest.java
Log:
Added: trunk/richfaces/datascroller/src/test/java/org/richfaces/component/DatascrollerComponentTest.java
===================================================================
--- trunk/richfaces/datascroller/src/test/java/org/richfaces/component/DatascrollerComponentTest.java (rev 0)
+++ trunk/richfaces/datascroller/src/test/java/org/richfaces/component/DatascrollerComponentTest.java 2007-04-04 13:38:43 UTC (rev 270)
@@ -0,0 +1,155 @@
+/**
+ * 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.HtmlDatascroller;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIData;
+import javax.faces.component.html.HtmlDataTable;
+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 Datascroller component.
+ */
+public class DatascrollerComponentTest extends AbstractAjax4JsfTestCase {
+ private static Set javaScripts = new HashSet();
+
+ static {
+ javaScripts.add("org.ajax4jsf.framework.ajax.AjaxScript");
+ javaScripts.add("prototype.js");
+ }
+
+ private HtmlDatascroller scroller;
+ private UIComponent form;
+ private UIData data;
+
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public DatascrollerComponentTest(String testName) {
+ super(testName);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ form = new HtmlForm();
+ form.setId("form");
+ facesContext.getViewRoot().getChildren().add(form);
+
+ data = (UIData)application.createComponent(HtmlDataTable.COMPONENT_TYPE);
+ data.setId("data");
+ data.setRows(5);
+ form.getChildren().add(data);
+
+ scroller = (HtmlDatascroller)application.createComponent(HtmlDatascroller.COMPONENT_TYPE);
+ scroller.setId("dataScroller");
+ scroller.setFor(data.getId());
+
+ form.getChildren().add(scroller);
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ scroller = null;
+ form = null;
+ data = null;
+ }
+
+ /**
+ * Test component rendering
+ *
+ * @throws Exception
+ */
+ public void testRender() throws Exception {
+ HtmlPage page = renderView();
+ Assert.assertNotNull(page);
+ System.out.println(page.asXml());
+
+ HtmlElement div = page.getHtmlElementById(form.getId() + ":" + scroller.getId());
+ Assert.assertNotNull(div);
+ Assert.assertEquals("div", div.getNodeName());
+
+ String classAttr = div.getAttributeValue("class");
+ Assert.assertTrue(classAttr.contains("dr-dscr"));
+ Assert.assertTrue(classAttr.contains("rich-datascr"));
+ }
+
+ /**
+ * 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/datascroller.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);
+ }
+ }
+
+ }
+}
Deleted: trunk/richfaces/datascroller/src/test/java/org/richfaces/component/JSFComponentTest.java
===================================================================
--- trunk/richfaces/datascroller/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-04 13:38:01 UTC (rev 269)
+++ trunk/richfaces/datascroller/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-04 13:38:43 UTC (rev 270)
@@ -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/datascroller/src/test/java/org/richfaces/component/html/HtmlDatascrollerTest.java
===================================================================
--- trunk/richfaces/datascroller/src/test/java/org/richfaces/component/html/HtmlDatascrollerTest.java (rev 0)
+++ trunk/richfaces/datascroller/src/test/java/org/richfaces/component/html/HtmlDatascrollerTest.java 2007-04-04 13:38:43 UTC (rev 270)
@@ -0,0 +1,55 @@
+/**
+ * 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 HtmlDatascroller.
+ */
+public class HtmlDatascrollerTest extends AbstractAjax4JsfTestCase {
+ public HtmlDatascrollerTest(String name) {
+ super(name);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Test save/restore state
+ *
+ * @throws Exception
+ */
+ public void testSaveStateFacesContext() throws Exception {
+ HtmlDatascroller ds = new HtmlDatascroller();
+ ds.setStyleClass("styleClass");
+ Object state = ds.saveState(facesContext);
+ HtmlDatascroller newDs = new HtmlDatascroller();
+ newDs.restoreState(facesContext, state);
+ assertEquals("styleClass", newDs.getStyleClass());
+ }
+}
Added: trunk/richfaces/datascroller/src/test/java/org/richfaces/taglib/DatascrollerTagTest.java
===================================================================
--- trunk/richfaces/datascroller/src/test/java/org/richfaces/taglib/DatascrollerTagTest.java (rev 0)
+++ trunk/richfaces/datascroller/src/test/java/org/richfaces/taglib/DatascrollerTagTest.java 2007-04-04 13:38:43 UTC (rev 270)
@@ -0,0 +1,90 @@
+/**
+ * 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.HtmlDatascroller;
+
+import javax.faces.webapp.UIComponentTag;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.Tag;
+
+
+public class DatascrollerTagTest extends AbstractAjax4JsfTestCase {
+
+ DatascrollerTag tag;
+
+ public DatascrollerTagTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ tag = new DatascrollerTag();
+ 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.DatascrollerTag#setProperties(javax.faces.component.UIComponent)}.
+ * @throws JspException
+ */
+ public void testSetPropertiesUIComponent() throws JspException {
+ HtmlDatascroller ds = new HtmlDatascroller();
+
+ tag.setStyleClass("styleClass");
+ tag.setProperties(ds);
+ assertEquals("styleClass", ds.getStyleClass());
+ }
+}
More information about the richfaces-svn-commits
mailing list