Author: abelevich
Date: 2008-01-16 13:58:28 -0500 (Wed, 16 Jan 2008)
New Revision: 5438
Added:
trunk/sandbox/ui/combobox/src/test/java/org/richfaces/sandbox/ui/component/ComboBoxComponentTest.java
trunk/sandbox/ui/combobox/src/test/java/org/richfaces/sandbox/ui/renderkit/
trunk/sandbox/ui/combobox/src/test/java/org/richfaces/sandbox/ui/renderkit/ComboBoxRendererTest.java
Log:
JUNITS
Added:
trunk/sandbox/ui/combobox/src/test/java/org/richfaces/sandbox/ui/component/ComboBoxComponentTest.java
===================================================================
---
trunk/sandbox/ui/combobox/src/test/java/org/richfaces/sandbox/ui/component/ComboBoxComponentTest.java
(rev 0)
+++
trunk/sandbox/ui/combobox/src/test/java/org/richfaces/sandbox/ui/component/ComboBoxComponentTest.java 2008-01-16
18:58:28 UTC (rev 5438)
@@ -0,0 +1,160 @@
+/**
+ * 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.sandbox.ui.component;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+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 org.richfaces.component.UIComboBox;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlScript;
+
+public class ComboBoxComponentTest extends AbstractAjax4JsfTestCase {
+
+ UIComboBox comboBox;
+ UIForm form;
+ String suggestions =
"Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,Florida,Massachusetts,Michigan,Georgia,Hawaii,Idaho,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine,Minnesota,Mississippi,Missouri,Montana,Nebraska";
+ 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/combobox.js");
+ }
+
+ public ComboBoxComponentTest( String testName ) {
+ super( testName );
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ form = new HtmlForm();
+ form.setId("form");
+ facesContext.getViewRoot().getChildren().add(form);
+
+ comboBox =
(UIComboBox)application.createComponent("org.richfaces.ComboBox");
+ comboBox.setSuggestionValues(Arrays.asList(suggestions.split(",")));
+
+ 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"));
+
+ comboBox.getChildren().add(item1);
+ comboBox.getChildren().add(item2);
+ comboBox.getChildren().add(item3);
+ comboBox.getChildren().add(item4);
+
+ UISelectItems items = new UISelectItems();
+ items.setValue(selectItems);
+ form.getChildren().add(comboBox);
+ }
+
+ public void testRender() 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/combobox.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();
+ if (scriptBodyString.contains("Richfaces.ComboBox")) {
+ assertTrue(scriptBodyString.contains("Richfaces.ComboBox.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 {
+ // TODO Auto-generated method stub
+ form = null;
+ comboBox = null;
+ super.tearDown();
+ }
+
+ public void testComponent() {
+ assertTrue( true );
+ }
+}
Added:
trunk/sandbox/ui/combobox/src/test/java/org/richfaces/sandbox/ui/renderkit/ComboBoxRendererTest.java
===================================================================
---
trunk/sandbox/ui/combobox/src/test/java/org/richfaces/sandbox/ui/renderkit/ComboBoxRendererTest.java
(rev 0)
+++
trunk/sandbox/ui/combobox/src/test/java/org/richfaces/sandbox/ui/renderkit/ComboBoxRendererTest.java 2008-01-16
18:58:28 UTC (rev 5438)
@@ -0,0 +1,117 @@
+/**
+ *
+ */
+package org.richfaces.sandbox.ui.renderkit;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UISelectItem;
+import javax.faces.component.UISelectItems;
+import javax.faces.component.UISelectOne;
+import javax.faces.model.SelectItem;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.UIComboBox;
+import org.richfaces.renderkit.html.ComboBoxRenderer;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlSelect;
+
+/**
+ * @author Anton Belevich
+ *
+ */
+public class ComboBoxRendererTest extends AbstractAjax4JsfTestCase {
+
+ private UIComponent form;
+ private UIComboBox comboBox;
+ private ComboBoxRenderer renderer;
+ String suggestions =
"Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,Florida,Massachusetts,Michigan,Georgia,Hawaii,Idaho,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine,Minnesota,Mississippi,Missouri,Montana,Nebraska";
+ List selectItems = new ArrayList();
+
+
+ private static Set javaScripts = new HashSet();
+
+ static {
+ javaScripts.add("org/richfaces/renderkit/html/scripts/combobox.js");
+ javaScripts.add("org/richfaces/renderkit/html/scripts/comboboxUtils.js");
+ javaScripts.add("prototype.js");
+ }
+
+
+ public void setUp() throws Exception {
+ super.setUp();
+ renderer = new ComboBoxRenderer();
+ comboBox =
(UIComboBox)application.createComponent("org.richfaces.ComboBox");
+ comboBox.setSuggestionValues(Arrays.asList(suggestions.split(",")));
+
+ 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"));
+
+ comboBox.getChildren().add(item1);
+ comboBox.getChildren().add(item2);
+ comboBox.getChildren().add(item3);
+ comboBox.getChildren().add(item4);
+
+ UISelectItems items = new UISelectItems();
+ items.setValue(selectItems);
+ facesContext.getViewRoot().getChildren().add(comboBox);
+
+ }
+
+ public void itemsTextAsJSArrayTest() {
+ String script = renderer.getItemsTextAsJSArray(facesContext, comboBox);
+ assertNotNull(script);
+ }
+
+ public void testRender(){
+
+ try {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ HtmlElement elem = page.getHtmlElementById(comboBox.getClientId(facesContext));
+ assertNotNull(elem);
+ assertEquals(elem.getTagName(), "div");
+ renderer.doEncodeEnd(writer, facesContext, comboBox);
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ renderer = null;
+ }
+
+
+
+ public ComboBoxRendererTest(String name) {
+ super(name);
+ }
+}