[richfaces-svn-commits] JBoss Rich Faces SVN: r312 - in trunk/richfaces/inputnumber-spinner/src: test/java/org/richfaces/component and 1 other directory.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Fri Apr 6 12:17:28 EDT 2007
Author: pkotikov
Date: 2007-04-06 12:17:28 -0400 (Fri, 06 Apr 2007)
New Revision: 312
Added:
trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component/InputNumberSpinnerComponentTest.java
Removed:
trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component/JSFComponentTest.java
Modified:
trunk/richfaces/inputnumber-spinner/src/main/java/org/richfaces/component/UIInputNumberSpinner.java
Log:
https://xplanner.exadel.com:1443/do/view/task?oid=92998
https://xplanner.exadel.com:1443/do/view/task?oid=92999
Modified: trunk/richfaces/inputnumber-spinner/src/main/java/org/richfaces/component/UIInputNumberSpinner.java
===================================================================
--- trunk/richfaces/inputnumber-spinner/src/main/java/org/richfaces/component/UIInputNumberSpinner.java 2007-04-06 15:21:18 UTC (rev 311)
+++ trunk/richfaces/inputnumber-spinner/src/main/java/org/richfaces/component/UIInputNumberSpinner.java 2007-04-06 16:17:28 UTC (rev 312)
@@ -29,6 +29,6 @@
*/
public abstract class UIInputNumberSpinner extends UIRangedNumberInput {
- public static final String COMPONENT_TYPE = "org.richfaces.InputNumberSpinner";
+ public static final String COMPONENT_TYPE = "org.richfaces.inputNumberSpinner";
}
Copied: trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component/InputNumberSpinnerComponentTest.java (from rev 252, trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component/JSFComponentTest.java)
===================================================================
--- trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component/InputNumberSpinnerComponentTest.java (rev 0)
+++ trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component/InputNumberSpinnerComponentTest.java 2007-04-06 16:17:28 UTC (rev 312)
@@ -0,0 +1,220 @@
+/**
+ * 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 java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.faces.component.UICommand;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.html.HtmlCommandLink;
+import javax.faces.component.html.HtmlForm;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.apache.commons.lang.StringUtils;
+
+import com.gargoylesoftware.htmlunit.KeyValuePair;
+import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlInput;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlScript;
+
+/**
+ * Unit test for simple Component.
+ */
+ at SuppressWarnings("unchecked")
+public class InputNumberSpinnerComponentTest extends AbstractAjax4JsfTestCase {
+
+ private UIForm form = null;
+ private UIComponent spinner = null;
+ private UICommand command = null;
+ private static Set javaScripts = new HashSet();
+
+ static {
+ javaScripts.add("prototype.js");
+ javaScripts.add("org.ajax4jsf.framework.ajax.AjaxScript");
+ javaScripts.add("org/richfaces/renderkit/html/script/SpinnerScript.js");
+ javaScripts.add("org/richfaces/renderkit/html/scripts/browser_info.js");
+ javaScripts.add("org/richfaces/renderkit/html/scripts/events.js");
+ }
+
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+
+ public InputNumberSpinnerComponentTest(String testName) {
+ super(testName);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ form = new HtmlForm();
+ facesContext.getViewRoot().getChildren().add(form);
+
+ command = new HtmlCommandLink();
+ command.setId("command");
+ form.getChildren().add(command);
+
+ spinner = application.createComponent(UIInputNumberSpinner.COMPONENT_TYPE);
+ spinner.setId("spinner");
+ form.getChildren().add(spinner);
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ this.form = null;
+ this.spinner = null;
+ this.command = null;
+ }
+
+ /**
+ * Test component renders correctly
+ *
+ * @throws Exception
+ */
+ public void testComponent() throws Exception {
+ HtmlPage renderedView = renderView();
+
+ HtmlElement htmlSpinner = renderedView.getHtmlElementById(spinner.getClientId(facesContext));
+
+ assertNotNull(htmlSpinner);
+
+ assertTrue(htmlSpinner.getAttributeValue("class").contains("dr-spnr-c rich-spinner-c"));
+
+ HtmlElement htmlSpinnerEdit = (HtmlElement) renderedView.getHtmlElementById(spinner.getClientId(facesContext) + "Edit");
+ assertNotNull(htmlSpinnerEdit);
+ assertTrue(htmlSpinnerEdit.getAttributeValue("class").contains("dr-spnr-e rich-spinner-input-container"));
+
+ HtmlInput htmlSpinnerInput = (HtmlInput)htmlSpinnerEdit.getLastChild();
+ assertNotNull(htmlSpinnerInput);
+ assertTrue(htmlSpinnerInput.getAttributeValue("class").contains("dr-spnr-i rich-spinner-input"));
+
+ HtmlElement buttonsContainer = (HtmlElement) renderedView.getHtmlElementById(spinner.getClientId(facesContext) + "Buttons");
+ assertNotNull(buttonsContainer);
+ Collection<HtmlInput> inputs = buttonsContainer.getHtmlElementsByTagName("input");
+ for (Iterator iter = inputs.iterator(); iter.hasNext();){
+ HtmlInput child = (HtmlInput)iter.next();
+ assertTrue(child.getTypeAttribute().equals("image"));
+ assertTrue(child.getAttributeValue("class").contains("dr-spnr-bn rich-spinner-button"));
+ }
+ }
+
+ public void testRenderStyle() throws Exception {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ List links = page.getDocumentElement().getHtmlElementsByTagName("link");
+ assertEquals(1, links.size());
+ HtmlElement link = (HtmlElement) links.get(0);
+ assertTrue(link.getAttributeValue("href").contains("org/richfaces/renderkit/html/css/spinner.xcss"));
+ }
+
+ public void testRenderScript() 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 (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 testUpdate() throws Exception {
+ //tests if component handles value bindings correctly
+ HtmlPage renderedView = renderView();
+
+ String maxValue = ((UIInputNumberSpinner)spinner).getMaxValue();
+
+ HtmlElement inputContainer = (HtmlElement) renderedView.getHtmlElementById(spinner.getClientId(facesContext)+"Edit");
+ HtmlInput htmlSliderInput = (HtmlInput) inputContainer.getLastChild();
+ htmlSliderInput.setValueAttribute(maxValue);
+
+ HtmlAnchor htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(command.getClientId(facesContext));
+ htmlLink.click();
+
+ List lastParameters = this.webConnection.getLastParameters();
+ for (Iterator iterator = lastParameters.iterator(); iterator.hasNext();) {
+ KeyValuePair keyValue = (KeyValuePair) iterator.next();
+
+ externalContext.addRequestParameterMap((String) keyValue.getKey(), (String) keyValue.getValue());
+ }
+
+ UIViewRoot root = facesContext.getViewRoot();
+ root.processDecodes(facesContext);
+ root.processValidators(facesContext);
+ root.processUpdates(facesContext);
+ root.processApplication(facesContext);
+
+ renderedView = renderView();
+ inputContainer = (HtmlElement) renderedView.getHtmlElementById(spinner.getClientId(facesContext)+"Edit");
+ htmlSliderInput = (HtmlInput) inputContainer.getLastChild();
+ assertTrue( maxValue.equals(((UIInputNumberSpinner)spinner).getValue()) );
+ }
+
+ public void testDecode() throws Exception{
+ //Tests if component accepts request parameters and stores them in submittedValue().
+ //If component is immediate, validation (possibly with conversion) should occur on that phase.
+ HtmlPage renderedView = renderView();
+ HtmlAnchor htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(command.getClientId(facesContext));
+ htmlLink.click();
+ externalContext.addRequestParameterMap(spinner.getClientId(facesContext),((UIInputNumberSpinner)spinner).getMaxValue());
+ UIViewRoot root = facesContext.getViewRoot();
+ root.processDecodes(facesContext);
+ UIInputNumberSpinner uiSpinner = (UIInputNumberSpinner) spinner;
+ if (uiSpinner.isImmediate()){
+ uiSpinner.validate(facesContext);
+ assertTrue(uiSpinner.isValid());
+ }
+ assertTrue(externalContext.getRequestParameterMap().get(spinner.getClientId(facesContext)).equals(uiSpinner.getMaxValue()));
+
+ }
+
+ public void testValidate(){
+ // tests if component is able to handle submittedValue() correctly (convert & validate)
+ UIInputNumberSpinner uispinner = (UIInputNumberSpinner) spinner;
+ uispinner.validate(facesContext);
+ assertTrue(uispinner.isValid());
+ }
+
+}
Deleted: trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component/JSFComponentTest.java
===================================================================
--- trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-06 15:21:18 UTC (rev 311)
+++ trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-06 16:17:28 UTC (rev 312)
@@ -1,53 +0,0 @@
-/**
- * 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 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 );
- }
-}
More information about the richfaces-svn-commits
mailing list