Author: abelevich
Date: 2008-02-08 09:34:02 -0500 (Fri, 08 Feb 2008)
New Revision: 5946
Added:
trunk/ui/pickList/src/test/java/org/richfaces/component/PickListComponentTest.java
trunk/ui/pickList/src/test/java/org/richfaces/renderkit/
trunk/ui/pickList/src/test/java/org/richfaces/renderkit/PickListRendererTest.java
Removed:
trunk/ui/pickList/src/test/java/org/richfaces/component/JSFComponentTest.java
Log:
add Junits
Deleted: trunk/ui/pickList/src/test/java/org/richfaces/component/JSFComponentTest.java
===================================================================
---
trunk/ui/pickList/src/test/java/org/richfaces/component/JSFComponentTest.java 2008-02-08
12:37:41 UTC (rev 5945)
+++
trunk/ui/pickList/src/test/java/org/richfaces/component/JSFComponentTest.java 2008-02-08
14:34:02 UTC (rev 5946)
@@ -1,53 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * 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/ui/pickList/src/test/java/org/richfaces/component/PickListComponentTest.java
===================================================================
--- trunk/ui/pickList/src/test/java/org/richfaces/component/PickListComponentTest.java
(rev 0)
+++
trunk/ui/pickList/src/test/java/org/richfaces/component/PickListComponentTest.java 2008-02-08
14:34:02 UTC (rev 5946)
@@ -0,0 +1,153 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * 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.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.faces.component.UIForm;
+import javax.faces.component.UISelectItem;
+import javax.faces.component.UISelectItems;
+import javax.faces.component.html.HtmlForm;
+import javax.faces.model.SelectItem;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.apache.commons.lang.StringUtils;
+
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlScript;
+
+public class PickListComponentTest extends AbstractAjax4JsfTestCase{
+
+ UIForm form;
+
+ UIPickList pickList;
+
+ String [] selected = new String [] {"District of Columbia,Illinois,Maryland,New
Hampshire,New Jersey"};
+
+ private static Set javaScripts = new HashSet();
+
+ List selectItems = new ArrayList();
+
+ static {
+ javaScripts.add("a4j_3_2_0-SNAPSHOTorg.ajax4jsf.javascript.PrototypeScript");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/ShuttleUtils.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/SelectItem.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/PickListSI.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/LayoutManager.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/Control.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/ListBase.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/OrderingList.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/ListShuttle.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/PickList.js");
+ }
+
+ public PickListComponentTest(String name) {
+ super(name);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ form = new HtmlForm();
+ form.setId("form");
+ facesContext.getViewRoot().getChildren().add(form);
+
+ pickList =
(UIPickList)application.createComponent("org.richfaces.PickList");
+ pickList.setValue(selected);
+
+ selectItems.add(new SelectItem("District of Columbia"));
+ selectItems.add(new SelectItem("Illinois"));
+ selectItems.add(new SelectItem("Maryland"));
+ selectItems.add(new SelectItem("Nevada"));
+ selectItems.add(new SelectItem("New Hampshire"));
+ selectItems.add(new SelectItem("New Jersey"));
+
+ UISelectItem item1 = new UISelectItem();
+ item1.setValue(new SelectItem("Oregon"));
+
+ UISelectItem item2 = new UISelectItem();
+ item2.setValue(new SelectItem("Pennsylvania"));
+
+ UISelectItem item3 = new UISelectItem();
+ item3.setValue(new SelectItem("Rhode Island"));
+
+ UISelectItem item4 = new UISelectItem();
+ item4.setValue(new SelectItem("South Carolina"));
+
+ pickList.getChildren().add(item1);
+ pickList.getChildren().add(item2);
+ pickList.getChildren().add(item3);
+ pickList.getChildren().add(item4);
+
+ UISelectItems items = new UISelectItems();
+ items.setValue(selectItems);
+ form.getChildren().add(pickList);
+ }
+
+ public void testRender() throws Exception {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ }
+
+ public void testComboBoxScripts() throws Exception {
+ HtmlPage page = renderView();
+ 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 (item.getFirstChild() != null) {
+ String scriptBodyString = item.getFirstChild().toString();
+ assert(scriptBodyString.contains("Richfaces.PickList"));
+ }
+
+ 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);
+ }
+ }
+ }
+
+ public void tearDown() throws Exception {
+ // TODO Auto-generated method stub
+ form = null;
+ pickList = null;
+ super.tearDown();
+ }
+
+ public void testComponent() {
+ assertTrue( true );
+ }
+
+}
Added: trunk/ui/pickList/src/test/java/org/richfaces/renderkit/PickListRendererTest.java
===================================================================
--- trunk/ui/pickList/src/test/java/org/richfaces/renderkit/PickListRendererTest.java
(rev 0)
+++
trunk/ui/pickList/src/test/java/org/richfaces/renderkit/PickListRendererTest.java 2008-02-08
14:34:02 UTC (rev 5946)
@@ -0,0 +1,151 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * 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.renderkit;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.faces.component.UIForm;
+import javax.faces.component.UISelectItem;
+import javax.faces.component.UISelectItems;
+import javax.faces.component.html.HtmlForm;
+import javax.faces.model.SelectItem;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.UIPickList;
+import org.richfaces.renderkit.html.PickListRendererGen;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+/**
+ * @author Anton Belevich
+ *
+ */
+public class PickListRendererTest extends AbstractAjax4JsfTestCase {
+
+ private UIForm form;
+ private UIPickList pickList;
+ private UIPickList pickList2;
+ private String [] selected = new String [] {"District of
Columbia,Illinois,Maryland,New Hampshire,New Jersey"};
+ private List selectedList = new ArrayList();
+ private static Set javaScripts = new HashSet();
+ private PickListRendererGen renderer;
+
+ List selectItems = new ArrayList();
+
+
+ static {
+ javaScripts.add("a4j_3_2_0-SNAPSHOTorg.ajax4jsf.javascript.PrototypeScript");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/ShuttleUtils.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/SelectItem.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/PickListSI.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/LayoutManager.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/Control.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/ListBase.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/OrderingList.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/ListShuttle.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/PickList.js");
+ }
+
+ public PickListRendererTest(String name) {
+ super(name);
+ selectedList.add("District of Columbia");
+ selectedList.add("Illinois");
+ selectedList.add("Maryland");
+ selectedList.add("New Hampshire");
+ selectedList.add("New Jersey");
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ renderer = new PickListRendererGen();
+ form = new HtmlForm();
+ form.setId("form");
+ facesContext.getViewRoot().getChildren().add(form);
+
+ pickList =
(UIPickList)application.createComponent("org.richfaces.PickList");
+ pickList.setValue(selected);
+
+ selectItems.add(new SelectItem("District of Columbia"));
+ selectItems.add(new SelectItem("Illinois"));
+ selectItems.add(new SelectItem("Maryland"));
+ selectItems.add(new SelectItem("Nevada"));
+ selectItems.add(new SelectItem("New Hampshire"));
+ selectItems.add(new SelectItem("New Jersey"));
+
+ UISelectItem item1 = new UISelectItem();
+ item1.setValue(new SelectItem("Oregon"));
+
+ UISelectItem item2 = new UISelectItem();
+ item2.setValue(new SelectItem("Pennsylvania"));
+
+ UISelectItem item3 = new UISelectItem();
+ item3.setValue(new SelectItem("Rhode Island"));
+
+ UISelectItem item4 = new UISelectItem();
+ item4.setValue(new SelectItem("South Carolina"));
+
+ pickList.getChildren().add(item1);
+ pickList.getChildren().add(item2);
+ pickList.getChildren().add(item3);
+ pickList.getChildren().add(item4);
+
+ UISelectItems items = new UISelectItems();
+ items.setValue(selectItems);
+ form.getChildren().add(pickList);
+
+ pickList2 =
(UIPickList)application.createComponent("org.richfaces.PickList");
+ pickList2.setValue(selectedList);
+ pickList2.getChildren().add(item1);
+ pickList2.getChildren().add(item2);
+ pickList2.getChildren().add(item3);
+ pickList2.getChildren().add(item4);
+ form.getChildren().add(pickList2);
+ }
+
+ public void testRender(){
+
+ try {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ HtmlElement elem = page.getHtmlElementById(pickList.getClientId(facesContext));
+ assertNotNull(elem);
+ assertEquals(elem.getTagName(), "table");
+ renderer.doEncodeEnd(writer, facesContext, pickList);
+
+ HtmlElement elem2 = page.getHtmlElementById(pickList2.getClientId(facesContext));
+ assertNotNull(elem2);
+ assertEquals(elem.getTagName(), "table");
+ renderer.doEncodeEnd(writer, facesContext, pickList);
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+
+}