Author: A.Skokov
Date: 2007-04-02 12:45:04 -0400 (Mon, 02 Apr 2007)
New Revision: 237
Added:
trunk/richfaces/suggestionbox/src/test/
trunk/richfaces/suggestionbox/src/test/java/
trunk/richfaces/suggestionbox/src/test/java/org/
trunk/richfaces/suggestionbox/src/test/java/org/richfaces/
trunk/richfaces/suggestionbox/src/test/java/org/richfaces/component/
trunk/richfaces/suggestionbox/src/test/java/org/richfaces/component/SuggestionBoxComponentTest.java
trunk/richfaces/suggestionbox/src/test/java/org/richfaces/component/html/
trunk/richfaces/suggestionbox/src/test/java/org/richfaces/component/html/HtmlSuggestionBoxTest.java
trunk/richfaces/suggestionbox/src/test/java/org/richfaces/taglib/
trunk/richfaces/suggestionbox/src/test/java/org/richfaces/taglib/SuggestionBoxTagTest.java
trunk/richfaces/suggestionbox/src/test/resources/
trunk/richfaces/suggestionbox/src/test/resources/WEB-INF/
trunk/richfaces/suggestionbox/src/test/resources/WEB-INF/web.xml
Log:
test added
Added:
trunk/richfaces/suggestionbox/src/test/java/org/richfaces/component/SuggestionBoxComponentTest.java
===================================================================
---
trunk/richfaces/suggestionbox/src/test/java/org/richfaces/component/SuggestionBoxComponentTest.java
(rev 0)
+++
trunk/richfaces/suggestionbox/src/test/java/org/richfaces/component/SuggestionBoxComponentTest.java 2007-04-02
16:45:04 UTC (rev 237)
@@ -0,0 +1,143 @@
+/**
+ * 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 junit.framework.Assert;
+import org.ajax4jsf.framework.ajax.AjaxViewHandler;
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.apache.shale.test.mock.MockViewHandler;
+import org.richfaces.component.html.HtmlSuggestionBox;
+import org.richfaces.renderkit.html.SuggestionBoxRenderer;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.html.HtmlInputText;
+import javax.faces.context.FacesContext;
+import java.util.List;
+
+/**
+ * Unit test for simple Component.
+ */
+public class SuggestionBoxComponentTest extends AbstractAjax4JsfTestCase {
+
+
+ HtmlSuggestionBox htmlSuggestionBox;
+ UIForm form;
+
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public SuggestionBoxComponentTest( String testName ) {
+ super( testName );
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ application.setViewHandler(new AjaxViewHandler(new MyMockViewHandler()));
+
+ UIComponent form = createComponent(UIForm.COMPONENT_TYPE, UIForm.class.getName(),
null, null , null);
+ UIComponent input = createComponent(HtmlInputText.COMPONENT_TYPE,
HtmlInputText.class.getName(), null, null , null);
+
+ form.setId("form");
+ input.setId("text");
+ facesContext.getViewRoot().getChildren().add(form);
+
+ form.getChildren().add(input);
+
+ htmlSuggestionBox = new HtmlSuggestionBox();
+ htmlSuggestionBox.setId("suggestionBox");
+ htmlSuggestionBox.setFor(input.getId());
+ htmlSuggestionBox.setRendererType("suggestionBoxRenderer");
+ renderKit.addRenderer(HtmlSuggestionBox.COMPONENT_FAMILY,
"suggestionBoxRenderer", new SuggestionBoxRenderer());
+
+ form.getChildren().add(htmlSuggestionBox);
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ htmlSuggestionBox = null;
+ form = null;
+ }
+ /**
+ * Rigourous Test :-)
+ * @throws Exception
+ */
+ public void testRender() throws Exception {
+ HtmlPage page = renderView();
+ Assert.assertNotNull(page);
+ System.out.println(page.asXml());
+ HtmlElement div = page.getHtmlElementById("form:suggestionBox");
+ Assert.assertNotNull(div);
+ Assert.assertEquals("div", div.getNodeName());
+ }
+
+ /**
+ * Rigourous Test :-)
+ * @throws Exception
+ */
+ public void testRenderStyle() throws Exception {
+ HtmlPage page = renderView();
+ Assert.assertNotNull(page);
+ List elementsByTagName =
page.getDocumentElement().getHtmlElementsByTagName("link");
+ Assert.assertEquals(1, elementsByTagName.size());
+ HtmlElement link = (HtmlElement) elementsByTagName.get(0);
+
Assert.assertTrue(link.getAttributeValue("href").contains("org/richfaces/renderkit/html/css/suggestionbox.xcss"));
+ }
+
+ /**
+ * Rigourous Test :-)
+ * @throws Exception
+ */
+ public void testRenderAttributes() throws Exception {
+ /*
+ Object[][] attributes
={{"style","xxx","style","xxx"},{"onclick","alert()","onclick","alert()"},{"styleClass","yyy","class","dr-pnl
rich-panel yyy"}};
+ for (int i = 0; i < attributes.length; i++) {
+ Object[] attr = attributes[i];
+ htmlSuggestionBox.getAttributes().put(attr[0], attr[1]);
+ }
+ HtmlPage page = renderView();
+ Assert.assertNotNull(page);
+ System.out.println(page.asXml());
+ HtmlElement div = page.getHtmlElementById("form:suggestionBox");
+ Assert.assertNotNull(div);
+ for (int i = 0; i < attributes.length; i++) {
+ Object[] attr = attributes[i];
+ Assert.assertEquals(attr[3],div.getAttributeValue((String) attr[2]));
+ }
+ */
+ }
+
+ class MyMockViewHandler extends MockViewHandler {
+ public UIViewRoot restoreView(FacesContext context, String viewId) {
+ return null;
+ }
+
+ public void writeState(FacesContext context) {
+
+ }
+ }
+}
Added:
trunk/richfaces/suggestionbox/src/test/java/org/richfaces/component/html/HtmlSuggestionBoxTest.java
===================================================================
---
trunk/richfaces/suggestionbox/src/test/java/org/richfaces/component/html/HtmlSuggestionBoxTest.java
(rev 0)
+++
trunk/richfaces/suggestionbox/src/test/java/org/richfaces/component/html/HtmlSuggestionBoxTest.java 2007-04-02
16:45:04 UTC (rev 237)
@@ -0,0 +1,52 @@
+/**
+ * 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 HtmlSuggestionBox.
+ */
+public class HtmlSuggestionBoxTest extends AbstractAjax4JsfTestCase {
+ public HtmlSuggestionBoxTest(String name) {
+ super(name);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testSaveStateFacesContext() {
+ HtmlSuggestionBox htmlSuggestionBox = new HtmlSuggestionBox();
+ htmlSuggestionBox.setStyleClass("styleClass");
+ htmlSuggestionBox.setSelectedClass("selectedClass");
+ Object state = htmlSuggestionBox.saveState(facesContext);
+ HtmlSuggestionBox newHtmlSuggestionBox = new HtmlSuggestionBox();
+ newHtmlSuggestionBox.restoreState(facesContext, state);
+ assertEquals("styleClass", newHtmlSuggestionBox.getStyleClass());
+ assertEquals("selectedClass",
newHtmlSuggestionBox.getSelectedClass());
+ }
+}
Added:
trunk/richfaces/suggestionbox/src/test/java/org/richfaces/taglib/SuggestionBoxTagTest.java
===================================================================
---
trunk/richfaces/suggestionbox/src/test/java/org/richfaces/taglib/SuggestionBoxTagTest.java
(rev 0)
+++
trunk/richfaces/suggestionbox/src/test/java/org/richfaces/taglib/SuggestionBoxTagTest.java 2007-04-02
16:45:04 UTC (rev 237)
@@ -0,0 +1,91 @@
+/**
+ * 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.HtmlSuggestionBox;
+
+import javax.faces.webapp.UIComponentTag;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.Tag;
+
+public class SuggestionBoxTagTest extends AbstractAjax4JsfTestCase {
+
+ SuggestionBoxTag tag;
+
+ public SuggestionBoxTagTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ tag = new SuggestionBoxTag();
+ 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.SuggestionBoxTag#setProperties(javax.faces.component.UIComponent)}.
+ * @throws JspException
+ */
+ public void testSetPropertiesUIComponent() throws JspException {
+ HtmlSuggestionBox htmlSuggestionBox = new HtmlSuggestionBox();
+
+ tag.setStyleClass("styleClass");
+ tag.setSelectedClass("selectedClass");
+ tag.setProperties(htmlSuggestionBox);
+ assertEquals("styleClass", htmlSuggestionBox.getStyleClass());
+ assertEquals("selectedClass", htmlSuggestionBox.getSelectedClass());
+ }
+}
Added: trunk/richfaces/suggestionbox/src/test/resources/WEB-INF/web.xml
===================================================================
--- trunk/richfaces/suggestionbox/src/test/resources/WEB-INF/web.xml
(rev 0)
+++ trunk/richfaces/suggestionbox/src/test/resources/WEB-INF/web.xml 2007-04-02 16:45:04
UTC (rev 237)
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+ <display-name>testcase</display-name>
+ <context-param>
+ <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
+ <param-value>server</param-value>
+ </context-param>
+ <context-param>
+ <param-name>javax.faces.CONFIG_FILES</param-name>
+ <param-value>/WEB-INF/faces-config.xml</param-value>
+ </context-param>
+
+ <filter>
+ <description>Convert HTML to XML</description>
+ <display-name>Filter</display-name>
+ <filter-name>A4J</filter-name>
+ <filter-class>org.ajax4jsf.Filter</filter-class>
+ <init-param>
+ <param-name>publicid</param-name>
+ <param-value>-//W3C//DTD XHTML 1.0 Transitional//EN</param-value>
+ </init-param>
+ <init-param>
+ <param-name>systemid</param-name>
+
<
param-value>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd<...
+ </init-param>
+ <init-param>
+ <param-name>namespace</param-name>
+ <
param-value>http://www.w3.org/1999/xhtml</param-value>
+ </init-param>
+ <init-param>
+ <param-name>forceparser</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ <init-param>
+ <param-name>rewriteid</param-name>
+ <param-value>false</param-value>
+ </init-param>
+ <init-param>
+ <param-name>mime-type</param-name>
+ <param-value>text/xml</param-value>
+ </init-param>
+ <init-param>
+ <param-name>log4j-init-file</param-name>
+ <param-value>WEB-INF/log4j.xml</param-value>
+ </init-param>
+ <init-param>
+ <param-name>enable-cache</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>A4J</filter-name>
+ <url-pattern>*.jsf</url-pattern>
+ </filter-mapping>
+ <filter-mapping>
+ <filter-name>A4J</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+ <listener>
+ <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
+ </listener>
+ <servlet>
+ <servlet-name>Faces Servlet</servlet-name>
+ <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>Faces Servlet</servlet-name>
+ <url-pattern>*.jsf</url-pattern>
+ </servlet-mapping>
+</web-app>