Author: abelevich
Date: 2008-02-21 11:16:41 -0500 (Thu, 21 Feb 2008)
New Revision: 6260
Added:
trunk/sandbox/ui/inplaceSelect/src/test/java/org/richfaces/component/InplaceSelectComponentTest.java
trunk/sandbox/ui/inplaceSelect/src/test/java/org/richfaces/renderkit/
trunk/sandbox/ui/inplaceSelect/src/test/java/org/richfaces/renderkit/InplaceSelectRenderTest.java
Removed:
trunk/sandbox/ui/inplaceSelect/src/test/java/org/richfaces/component/JSFComponentTest.java
Log:
Added:
trunk/sandbox/ui/inplaceSelect/src/test/java/org/richfaces/component/InplaceSelectComponentTest.java
===================================================================
---
trunk/sandbox/ui/inplaceSelect/src/test/java/org/richfaces/component/InplaceSelectComponentTest.java
(rev 0)
+++
trunk/sandbox/ui/inplaceSelect/src/test/java/org/richfaces/component/InplaceSelectComponentTest.java 2008-02-21
16:16:41 UTC (rev 6260)
@@ -0,0 +1,137 @@
+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.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlScript;
+
+public class InplaceSelectComponentTest extends AbstractAjax4JsfTestCase {
+
+ UIForm form;
+ UIInplaceSelect iselect;
+ List selectItems = new ArrayList();
+
+ private static Set javaScripts = new HashSet();
+
+ static {
+
+
+ javaScripts.add("a4j_3_2_0-SNAPSHOTorg.ajax4jsf.javascript.PrototypeScript");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/comboboxUtils.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/combolist.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/inplaceinput.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/inplaceselectlist.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTscripts/inplaceselect.js");
+ javaScripts.add("a4j_3_2_0-SNAPSHOTorg/richfaces/renderkit/html/scripts/utils.js");
+ }
+
+
+ public InplaceSelectComponentTest(String name) {
+ super(name);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ form = new HtmlForm();
+ form.setId("form");
+ facesContext.getViewRoot().getChildren().add(form);
+ iselect =
(UIInplaceSelect)application.createComponent("org.richfaces.InplaceSelect");
+
+ selectItems.add(new SelectItem("Kansas City"));
+ selectItems.add(new SelectItem("Las Vegas"));
+ selectItems.add(new SelectItem("Oklahoma City"));
+ selectItems.add(new SelectItem("New Jersey"));
+ selectItems.add(new SelectItem("Detroit"));
+
+ UISelectItem item1 = new UISelectItem();
+ item1.setValue(new SelectItem("Toronto"));
+
+ UISelectItem item2 = new UISelectItem();
+ item2.setValue(new SelectItem("Cleveland"));
+
+ UISelectItem item3 = new UISelectItem();
+ item3.setValue(new SelectItem("Indianapolis"));
+
+ UISelectItem item4 = new UISelectItem();
+ item4.setValue(new SelectItem("New York"));
+
+ iselect.getChildren().add(item1);
+ iselect.getChildren().add(item2);
+ iselect.getChildren().add(item3);
+ iselect.getChildren().add(item4);
+
+ UISelectItems items = new UISelectItems();
+ items.setValue(selectItems);
+ iselect.getChildren().add(items);
+ iselect.setValue("New York");
+
+ form.getChildren().add(iselect);
+ }
+
+ public void testRenderer() throws Exception {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ }
+
+ public void testComboBoxStyles() throws Exception {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ List links = page.getDocumentElement().getHtmlElementsByTagName("link");
+ if(links.size()==0){fail();}
+ for (int i = 0; i < links.size(); i++) {
+ HtmlElement link = (HtmlElement) links.get(i);
+ assertTrue(link.getAttributeValue("href").contains(
+ "css/inplaceselect.xcss"));
+ }
+ }
+
+ 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();
+ assertTrue(scriptBodyString.contains("Richfaces.InplaceSelectList"));
+ assertTrue(scriptBodyString.contains("Richfaces.InplaceSelect"));
+ assertTrue(scriptBodyString.contains("Richfaces.InplaceSelect.CLASSES"));
+
+ }
+ 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 {
+ super.tearDown();
+ form = null;
+ iselect = null;
+ }
+}
Deleted:
trunk/sandbox/ui/inplaceSelect/src/test/java/org/richfaces/component/JSFComponentTest.java
===================================================================
---
trunk/sandbox/ui/inplaceSelect/src/test/java/org/richfaces/component/JSFComponentTest.java 2008-02-21
16:16:27 UTC (rev 6259)
+++
trunk/sandbox/ui/inplaceSelect/src/test/java/org/richfaces/component/JSFComponentTest.java 2008-02-21
16:16:41 UTC (rev 6260)
@@ -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/sandbox/ui/inplaceSelect/src/test/java/org/richfaces/renderkit/InplaceSelectRenderTest.java
===================================================================
---
trunk/sandbox/ui/inplaceSelect/src/test/java/org/richfaces/renderkit/InplaceSelectRenderTest.java
(rev 0)
+++
trunk/sandbox/ui/inplaceSelect/src/test/java/org/richfaces/renderkit/InplaceSelectRenderTest.java 2008-02-21
16:16:41 UTC (rev 6260)
@@ -0,0 +1,82 @@
+package org.richfaces.renderkit;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.faces.component.UIForm;
+import javax.faces.component.UISelectItem;
+import javax.faces.component.UISelectItems;
+import javax.faces.model.SelectItem;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.UIInplaceSelect;
+import org.richfaces.renderkit.html.InplaceSelectRenderer;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+public class InplaceSelectRenderTest extends AbstractAjax4JsfTestCase {
+
+ private UIInplaceSelect iselect;
+ private InplaceSelectRenderer renderer;
+ List selectItems = new ArrayList();
+
+ public InplaceSelectRenderTest(String name) {
+ super(name);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ renderer = new InplaceSelectRenderer();
+ iselect =
(UIInplaceSelect)application.createComponent("org.richfaces.InplaceSelect");
+ iselect.setValue("New York");
+ selectItems.add(new SelectItem("Kansas City"));
+ selectItems.add(new SelectItem("Las Vegas"));
+ selectItems.add(new SelectItem("Oklahoma City"));
+ selectItems.add(new SelectItem("New Jersey"));
+ selectItems.add(new SelectItem("Detroit"));
+
+ UISelectItem item1 = new UISelectItem();
+ item1.setValue(new SelectItem("Toronto"));
+
+ UISelectItem item2 = new UISelectItem();
+ item2.setValue(new SelectItem("Cleveland"));
+
+ UISelectItem item3 = new UISelectItem();
+ item3.setValue(new SelectItem("Indianapolis"));
+
+ UISelectItem item4 = new UISelectItem();
+ item4.setValue(new SelectItem("New York"));
+
+ iselect.getChildren().add(item1);
+ iselect.getChildren().add(item2);
+ iselect.getChildren().add(item3);
+ iselect.getChildren().add(item4);
+
+ UISelectItems items = new UISelectItems();
+ items.setValue(selectItems);
+ iselect.getChildren().add(items);
+ iselect.setValue("New York");
+
+ facesContext.getViewRoot().getChildren().add(iselect);
+ }
+
+ public void testRender(){
+
+ try {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ HtmlElement elem = page.getHtmlElementById(iselect.getClientId(facesContext));
+ assertNotNull(elem);
+ assertEquals(elem.getTagName(), "span");
+ renderer.doEncodeEnd(writer, facesContext, iselect);
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+
+}
Show replies by date