Author: abelevich
Date: 2008-11-27 07:08:08 -0500 (Thu, 27 Nov 2008)
New Revision: 11409
Modified:
trunk/ui/combobox/src/test/java/org/richfaces/renderkit/ComboBoxRendererTest.java
Log:
extend test
Modified:
trunk/ui/combobox/src/test/java/org/richfaces/renderkit/ComboBoxRendererTest.java
===================================================================
---
trunk/ui/combobox/src/test/java/org/richfaces/renderkit/ComboBoxRendererTest.java 2008-11-27
10:53:38 UTC (rev 11408)
+++
trunk/ui/combobox/src/test/java/org/richfaces/renderkit/ComboBoxRendererTest.java 2008-11-27
12:08:08 UTC (rev 11409)
@@ -22,18 +22,18 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.component.UISelectItem;
-import javax.faces.component.UISelectItems;
import javax.faces.model.SelectItem;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
import org.richfaces.component.UIComboBox;
-import org.richfaces.renderkit.html.ComboBoxRenderer;
+import org.w3c.dom.Node;
+import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
@@ -44,69 +44,84 @@
public class ComboBoxRendererTest extends AbstractAjax4JsfTestCase {
private UIComponent form;
- private UIComboBox comboBox;
- private ComboBoxRenderer renderer;
+ private UIComboBox comboBox1;
+ private UIComboBox comboBox2;
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();
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"));
+ super.setUp();
- UISelectItem item1 = new UISelectItem();
- item1.setValue(new SelectItem("Oregon"));
+ comboBox1 = (UIComboBox)
application.createComponent("org.richfaces.ComboBox");
+ comboBox1.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"));
+
+ comboBox1.getChildren().add(item1);
+ comboBox1.getChildren().add(item2);
+ comboBox1.getChildren().add(item3);
+ comboBox1.getChildren().add(item4);
+
+ // SuggestionValues is array
+ comboBox2 = (UIComboBox)
application.createComponent("org.richfaces.ComboBox");
+ comboBox2.setSuggestionValues(suggestions.split(","));
+ comboBox2.getChildren().add(item1);
+ comboBox2.getChildren().add(item2);
+ comboBox2.getChildren().add(item3);
+ comboBox2.getChildren().add(item4);
+
+ facesContext.getViewRoot().getChildren().add(comboBox1);
+ facesContext.getViewRoot().getChildren().add(comboBox2);
+ }
- 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);
-
- Map requestMap = facesContext.getExternalContext().getRequestParameterMap();
- String id = "comboBoxValue" + comboBox.getClientId(facesContext);
- requestMap.put(id, "Pennsylvania");
- }
-
-// public void itemsTextAsJSArrayTest() {
-// String script = renderer.getItemsTextAsJSArray(facesContext, comboBox);
-// assertNotNull(script);
-// }
-
public void testRender() throws Exception {
-
- HtmlPage page = renderView();
- assertNotNull(page);
- HtmlElement elem = page.getHtmlElementById(comboBox.getClientId(facesContext));
- assertNotNull(elem);
- assertEquals(elem.getTagName(), "div");
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ HtmlElement elem1 = page.getHtmlElementById(comboBox1.getClientId(facesContext));
+ assertNotNull(elem1);
+ assertEquals("div",elem1.getTagName());
+ checkList(page, comboBox1);
+ HtmlElement elem2 = page.getHtmlElementById(comboBox2.getClientId(facesContext));
+ assertNotNull(elem2);
+ assertEquals("div",elem2.getTagName());
+ checkList(page, comboBox2);
+ }
+
+ protected void checkList(HtmlPage page, UIComboBox combobox) throws Exception {
+ String listId = combobox.getClientId(facesContext) + "list";
+ HtmlElement list = page.getHtmlElementById(listId);
+ Iterator<HtmlElement> htmlElements = list.getAllHtmlChildElements();
+ String allItems = suggestions + "Oregon, Pennsylvania, Rhode Island, South
Carolina";
+ for (; htmlElements.hasNext();) {
+ HtmlElement span = htmlElements.next();
+ assertEquals("span", span.getTagName());
+ DomNode node = span.getFirstDomChild();
+ assertEquals(Node.TEXT_NODE, node.getNodeType());
+ assertTrue(allItems.contains(node.getNodeValue()));
+ }
}
public void tearDown() throws Exception {
- super.tearDown();
- renderer = null;
+ super.tearDown();
}
public ComboBoxRendererTest(String name) {
- super(name);
+ super(name);
}
}