JBoss Rich Faces SVN: r348 - trunk/richfaces-samples/richfaces-art-datatable.
by richfaces-svn-commits@lists.jboss.org
Author: SergeySmirnov
Date: 2007-04-10 13:35:06 -0400 (Tue, 10 Apr 2007)
New Revision: 348
Modified:
trunk/richfaces-samples/richfaces-art-datatable/
Log:
richfaces datatable article example appl
Property changes on: trunk/richfaces-samples/richfaces-art-datatable
___________________________________________________________________
Name: svn:ignore
+ target
.settings
.classpath
.exadelproject
.project
19 years
JBoss Rich Faces SVN: r347 - trunk/richfaces/spacer/src/test/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2007-04-10 12:11:11 -0400 (Tue, 10 Apr 2007)
New Revision: 347
Added:
trunk/richfaces/spacer/src/test/java/org/richfaces/component/SpacerComponentTest.java
Removed:
trunk/richfaces/spacer/src/test/java/org/richfaces/component/JSFComponentTest.java
Log:
Spacer test added
Deleted: trunk/richfaces/spacer/src/test/java/org/richfaces/component/JSFComponentTest.java
===================================================================
--- trunk/richfaces/spacer/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-10 16:10:38 UTC (rev 346)
+++ trunk/richfaces/spacer/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-10 16:11:11 UTC (rev 347)
@@ -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 );
- }
-}
Added: trunk/richfaces/spacer/src/test/java/org/richfaces/component/SpacerComponentTest.java
===================================================================
--- trunk/richfaces/spacer/src/test/java/org/richfaces/component/SpacerComponentTest.java (rev 0)
+++ trunk/richfaces/spacer/src/test/java/org/richfaces/component/SpacerComponentTest.java 2007-04-10 16:11:11 UTC (rev 347)
@@ -0,0 +1,169 @@
+/**
+ * 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 javax.faces.component.UICommand;
+import javax.faces.component.UIForm;
+import javax.faces.component.html.HtmlCommandLink;
+import javax.faces.component.html.HtmlForm;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.html.HtmlSpacer;
+
+import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
+import com.gargoylesoftware.htmlunit.html.HtmlImage;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+public class SpacerComponentTest extends AbstractAjax4JsfTestCase {
+ private UICommand command = null;
+
+ private UIForm form = null;
+
+ // private UIComponent tree = null;
+ private UISpacer spacer = null;
+
+ /**
+ * Create the test case
+ *
+ * @param testName
+ * name of the test case
+ */
+ public SpacerComponentTest(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);
+ spacer = (UISpacer) application
+ .createComponent(HtmlSpacer.COMPONENT_TYPE);
+ form.getChildren().add(spacer);
+
+ spacer.setId("spacer");
+ spacer.setWidth("30");
+ spacer.setHeight("10");
+ spacer.setStyle("background-color: lime");
+
+ // spacer.getAttributes().put("height", new Integer(10));
+
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ this.form = null;
+ this.command = null;
+ this.spacer = null;
+ }
+
+ /**
+ * Rigourous Test :-)
+ *
+ * @throws Exception
+ */
+ public void testComponent() throws Exception {
+ HtmlPage renderedView = renderView();
+ assertNotNull(renderedView);
+ // System.out.println(renderedView.getWebResponse().getContentAsString());
+
+ HtmlAnchor htmlLink = (HtmlAnchor) renderedView
+ .getHtmlElementById(command.getClientId(facesContext));
+ htmlLink.click();
+
+ HtmlImage htmlSpacer = (HtmlImage) renderedView
+ .getHtmlElementById(spacer.getClientId(facesContext));
+ assertNotNull(htmlSpacer);
+
+ String str = htmlSpacer.getAttributeValue("width");
+ assertEquals("30", str);
+ str = htmlSpacer.getAttributeValue("height");
+ assertEquals("10", str);
+ str = htmlSpacer.getAttributeValue("style");
+ assertEquals("background-color: lime", str);
+
+ str = htmlSpacer.getClassAttribute();
+ str = htmlSpacer.getAttributeValue("class");
+ assertTrue(str.contains("rich-spacer"));
+
+ str = htmlSpacer.getSrcAttribute();
+ assertEquals("/testContext/a4j.res/org/richfaces/renderkit/html/images/spacer.gif",
+ str);
+
+ System.out.println(renderedView.getWebResponse().getContentAsString());
+
+ /*
+ * 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()); }
+
+ // System.out.println(this.webConnection.getLastParameters());
+
+
+ UIViewRoot root = facesContext.getViewRoot();
+ root.processDecodes(facesContext);
+ root.processValidators(facesContext);
+ root.processUpdates(facesContext);
+ root.processApplication(facesContext);
+ */
+ // renderedView = renderView();
+ // System.out.println(renderedView.getWebResponse().getContentAsString());
+ }
+
+ public void testDecode() throws Exception {
+
+ try {
+ spacer.processDecodes(facesContext);
+ } catch (NullPointerException e) {
+ fail();
+ }
+ ;
+ }
+
+ public void testValidate() {
+
+ spacer.processValidators(facesContext);
+
+ }
+
+ public void testUpdate() {
+ spacer.processUpdates(facesContext);
+ }
+ /*
+ * testDecode: tests if component accepts request parameters and stores them
+ * in submittedValue(). If component is immediate, validation (possibly with
+ * conversion) should occur on that phase. testValidate: tests if component
+ * is able to handle submittedValue() correctly (convert & validate)
+ * testUpdate: tests if component handles value bindings correctly
+ */
+
+}
19 years
JBoss Rich Faces SVN: r346 - trunk/richfaces/paint2D/src/test/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2007-04-10 12:10:38 -0400 (Tue, 10 Apr 2007)
New Revision: 346
Added:
trunk/richfaces/paint2D/src/test/java/org/richfaces/component/Paint2DTest.java
Removed:
trunk/richfaces/paint2D/src/test/java/org/richfaces/component/JSFComponentTest.java
Log:
Paint2D test added
Deleted: trunk/richfaces/paint2D/src/test/java/org/richfaces/component/JSFComponentTest.java
===================================================================
--- trunk/richfaces/paint2D/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-10 15:26:14 UTC (rev 345)
+++ trunk/richfaces/paint2D/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-10 16:10:38 UTC (rev 346)
@@ -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 );
- }
-}
Added: trunk/richfaces/paint2D/src/test/java/org/richfaces/component/Paint2DTest.java
===================================================================
--- trunk/richfaces/paint2D/src/test/java/org/richfaces/component/Paint2DTest.java (rev 0)
+++ trunk/richfaces/paint2D/src/test/java/org/richfaces/component/Paint2DTest.java 2007-04-10 16:10:38 UTC (rev 346)
@@ -0,0 +1,186 @@
+/**
+ * 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.Iterator;
+import java.util.List;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.html.HtmlCommandLink;
+import javax.faces.component.html.HtmlForm;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+
+import com.gargoylesoftware.htmlunit.KeyValuePair;
+import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
+import com.gargoylesoftware.htmlunit.html.HtmlImage;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+/**
+ * Unit test for simple Component.
+ */
+public class Paint2DTest extends AbstractAjax4JsfTestCase {
+
+ private UIPaint2D p2d;
+
+ private UIComponent form;
+ private UIComponent command;
+
+
+ /**
+ * Create the test case
+ *
+ * @param testName
+ * name of the test case
+ */
+ public Paint2DTest(String testName) {
+ super(testName);
+ }
+
+ public void SetUp() throws Exception {
+
+ super.setUp();
+
+ form = new HtmlForm();
+ assertNotNull(form);
+ form.setId("form");
+ facesContext.getViewRoot().getChildren().add(form);
+
+ command = new HtmlCommandLink();
+ command.setId("command");
+ form.getChildren().add(command);
+
+ p2d = (UIPaint2D) application.createComponent(UIPaint2D.COMPONENT_TYPE);
+ assertNotNull(p2d);
+ p2d.setId("p2d");
+ p2d.setBgcolor("pink");
+ p2d.setHeight(300);
+ p2d.setWidth(200);
+ p2d.getAttributes().put("align", "left");
+ p2d.getAttributes().put("border", "5");
+ p2d.getAttributes().put("title", "title goes here");
+// p2d.setCacheable(true);
+ form.getChildren().add(p2d);
+// Object obj = p2d.saveState(facesContext);
+// p2d.restoreState(facesContext, obj);
+ }
+
+ public void tearDown() throws Exception {
+ form = null;
+ p2d = null;
+ }
+
+
+ public void testComponent() throws Exception {
+ SetUp();
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ System.out.println(page.asXml());
+
+ HtmlImage htmlP2D = (HtmlImage) page.getHtmlElementById(p2d.getClientId(facesContext));
+ assertEquals("img", htmlP2D.getNodeName());
+
+ String classAttr = htmlP2D.getAttributeValue("class");
+ assertTrue(classAttr.contains("rich-paint2D"));
+
+ String srcAttr = htmlP2D.getAttributeValue("src");
+ assertTrue(srcAttr.contains("org.richfaces.renderkit.html.Paint2DResource"));
+
+ String str = htmlP2D.getAttributeValue("width");
+ assertEquals(str, "200");
+
+ str = htmlP2D.getAttributeValue("height");
+ assertEquals(str, "300");
+
+ str = htmlP2D.getAttributeValue("bgcolor");
+ assertEquals(str, "pink");
+
+ str = htmlP2D.getAttributeValue("align");
+ assertEquals(str, "left");
+
+ str = htmlP2D.getAttributeValue("border");
+ assertEquals(str, "5");
+
+ str = htmlP2D.getAttributeValue("title");
+ assertEquals(str, "title goes here");
+ }
+
+ public void testUpdate() throws Exception {
+ //tests if component handles value bindings correctly
+ SetUp();
+ HtmlPage renderedView = renderView();
+
+ int width = ((UIPaint2D)p2d).getWidth();
+
+ HtmlImage htmlPaint2D = (HtmlImage) renderedView.getHtmlElementById(p2d.getClientId(facesContext));
+ htmlPaint2D.setAttributeValue("width", "200");
+
+ 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();
+ htmlPaint2D = (HtmlImage) renderedView.getHtmlElementById(p2d.getClientId(facesContext));
+ assertTrue( width ==(((UIPaint2D)p2d).getWidth()) );
+ }
+
+ 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.
+ SetUp();
+ HtmlPage renderedView = renderView();
+ HtmlAnchor htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(command.getClientId(facesContext));
+ htmlLink.click();
+ externalContext.addRequestParameterMap(p2d.getClientId(facesContext),((UIPaint2D)p2d).getBgcolor());
+ UIViewRoot root = facesContext.getViewRoot();
+ root.processDecodes(facesContext);
+ UIPaint2D uiP2d = (UIPaint2D) p2d;
+ assertTrue(externalContext.getRequestParameterMap().get(p2d.getClientId(facesContext)).equals(uiP2d.getBgcolor()));
+
+ }
+ /*
+
+ public void testValidate()throws Exception {
+
+ p2d.processValidators(facesContext);
+
+ }
+
+ public void testUpdate() throws Exception {
+ p2d.processUpdates(facesContext);
+ }
+ */
+}
19 years
JBoss Rich Faces SVN: r345 - trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: pkotikov
Date: 2007-04-10 11:26:14 -0400 (Tue, 10 Apr 2007)
New Revision: 345
Modified:
trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component/InputNumberSpinnerComponentTest.java
Log:
Update of tests.
Modified: trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component/InputNumberSpinnerComponentTest.java
===================================================================
--- trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component/InputNumberSpinnerComponentTest.java 2007-04-10 15:25:52 UTC (rev 344)
+++ trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component/InputNumberSpinnerComponentTest.java 2007-04-10 15:26:14 UTC (rev 345)
@@ -33,6 +33,10 @@
import javax.faces.component.UIViewRoot;
import javax.faces.component.html.HtmlCommandLink;
import javax.faces.component.html.HtmlForm;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyNotFoundException;
+import javax.faces.el.ValueBinding;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
import org.apache.commons.lang.StringUtils;
@@ -163,11 +167,11 @@
//tests if component handles value bindings correctly
HtmlPage renderedView = renderView();
- String maxValue = ((UIInputNumberSpinner)spinner).getMaxValue();
+ String value = "66";
HtmlElement inputContainer = (HtmlElement) renderedView.getHtmlElementById(spinner.getClientId(facesContext)+"Edit");
HtmlInput htmlSliderInput = (HtmlInput) inputContainer.getLastChild();
- htmlSliderInput.setValueAttribute(maxValue);
+ htmlSliderInput.setValueAttribute(value);
HtmlAnchor htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(command.getClientId(facesContext));
htmlLink.click();
@@ -188,32 +192,72 @@
renderedView = renderView();
inputContainer = (HtmlElement) renderedView.getHtmlElementById(spinner.getClientId(facesContext)+"Edit");
htmlSliderInput = (HtmlInput) inputContainer.getLastChild();
- assertTrue( maxValue.equals(((UIInputNumberSpinner)spinner).getValue()) );
+ htmlSliderInput.setValueAttribute(value); assertTrue( value.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.
+ final SpinnerBean bean = new SpinnerBean();
+ ((UIInputNumberSpinner)spinner).setValueBinding("value",
+ new ValueBinding() {
+ public Class getType(FacesContext context) throws EvaluationException, PropertyNotFoundException {
+ return String.class;
+ }
+ public Object getValue(FacesContext context) throws EvaluationException, PropertyNotFoundException {
+ return bean.getValue();
+ }
+ public boolean isReadOnly(FacesContext context) throws EvaluationException, PropertyNotFoundException {
+ return false;
+ }
+ public void setValue(FacesContext context, Object value) throws EvaluationException, PropertyNotFoundException {
+ bean.setValue((String)value);
+ }
+ });
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()));
+ externalContext.addRequestParameterMap(spinner.getClientId(facesContext),"66");
+ spinner.processDecodes(facesContext);
+ assertTrue(bean.getValue().equals("66"));
+ ((UIInputNumberSpinner)spinner).setImmediate(true);
+ renderedView = renderView();
+ htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(command.getClientId(facesContext));
+ htmlLink.click();
+ externalContext.addRequestParameterMap(spinner.getClientId(facesContext),"wrong value");
+ spinner.processDecodes(facesContext);
+ assertTrue(facesContext.getMessages().hasNext());
}
- public void testValidate(){
- // tests if component is able to handle submittedValue() correctly (convert & validate)
- UIInputNumberSpinner uispinner = (UIInputNumberSpinner) spinner;
- uispinner.validate(facesContext);
- assertTrue(uispinner.isValid());
+ public void testValidate() throws Exception{
+ HtmlPage renderedView = renderView();
+
+ HtmlAnchor htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(command.getClientId(facesContext));
+ htmlLink.click();
+ externalContext.addRequestParameterMap(spinner.getClientId(facesContext),"wrong value");
+ spinner.processDecodes(facesContext);
+ spinner.processValidators(facesContext);
+
+ assertTrue(facesContext.getMessages().hasNext());
+
}
+
+ private class SpinnerBean {
+
+ private String value;
+
+ SpinnerBean (){
+ this.value = "66";
+ }
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ }
}
19 years
JBoss Rich Faces SVN: r344 - trunk/richfaces/inputnumber-slider/src/test/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: pkotikov
Date: 2007-04-10 11:25:52 -0400 (Tue, 10 Apr 2007)
New Revision: 344
Modified:
trunk/richfaces/inputnumber-slider/src/test/java/org/richfaces/component/InputNumberSliderComponentTest.java
Log:
Update of tests.
Modified: trunk/richfaces/inputnumber-slider/src/test/java/org/richfaces/component/InputNumberSliderComponentTest.java
===================================================================
--- trunk/richfaces/inputnumber-slider/src/test/java/org/richfaces/component/InputNumberSliderComponentTest.java 2007-04-10 15:06:24 UTC (rev 343)
+++ trunk/richfaces/inputnumber-slider/src/test/java/org/richfaces/component/InputNumberSliderComponentTest.java 2007-04-10 15:25:52 UTC (rev 344)
@@ -32,6 +32,10 @@
import javax.faces.component.UIViewRoot;
import javax.faces.component.html.HtmlCommandLink;
import javax.faces.component.html.HtmlForm;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyNotFoundException;
+import javax.faces.el.ValueBinding;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
import org.apache.commons.lang.StringUtils;
@@ -113,12 +117,8 @@
assertNotNull(htmlSliderInput);
- if (slider.getAttributes().get("showInput").equals(Boolean.TRUE)) {
- assertTrue(htmlSliderInput.getClassAttribute().contains("dr-insldr-field rich-inslider-field"));
- assertTrue(htmlSliderInput.getTypeAttribute().equals("text"));
- } else {
- assertTrue(htmlSliderInput.getTypeAttribute().equals("hidden"));
- }
+ assertTrue(htmlSliderInput.getClassAttribute().contains("dr-insldr-field rich-inslider-field"));
+ assertTrue(htmlSliderInput.getTypeAttribute().equals("text"));
DomNode numContainer = htmlSliderInput.getParentNode().getPreviousSibling();
assertTrue(((HtmlElement)numContainer).getAttributeValue("class").contains("dr-insldr-right-num rich-inslider-right-num"));
@@ -132,9 +132,15 @@
HtmlElement track = (HtmlElement)tip.getParentNode().getNextSibling();
assertTrue(track.getAttributeValue("class").contains("dr-insldr-track rich-inslider-track"));
-
}
+ public void testHiddenInput() throws Exception {
+ slider.getAttributes().put("showInput",Boolean.FALSE);
+ HtmlPage renderedView = renderView();
+ HtmlInput htmlSliderInput = (HtmlInput) renderedView.getHtmlElementById(slider.getClientId(facesContext) + "Input");
+ assertTrue(htmlSliderInput.getTypeAttribute().equals("hidden"));
+ }
+
public void testRenderStyle() throws Exception {
HtmlPage page = renderView();
assertNotNull(page);
@@ -172,10 +178,10 @@
//tests if component handles value bindings correctly
HtmlPage renderedView = renderView();
- String maxValue = ((UIInputNumberSlider)slider).getMaxValue();
+ String value = "66";
- HtmlInput htmlSliderInput = (HtmlInput) renderedView.getHtmlElementById(slider.getClientId(facesContext) + "Input");
- htmlSliderInput.setValueAttribute(maxValue);
+ HtmlInput htmlSliderInput = (HtmlInput) renderedView.getHtmlElementById(slider.getClientId(facesContext) + "Input");
+ htmlSliderInput.setValueAttribute(value);
HtmlAnchor htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(command.getClientId(facesContext));
htmlLink.click();
@@ -195,29 +201,73 @@
renderedView = renderView();
htmlSliderInput = (HtmlInput) renderedView.getHtmlElementById(slider.getClientId(facesContext)+"Input");
- assertTrue( maxValue.equals(((UIInputNumberSlider)slider).getValue()) );
+ assertTrue( value.equals(((UIInputNumberSlider)slider).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.
+ final SliderBean bean = new SliderBean();
+ ((UIInputNumberSlider)slider).setValueBinding("value",
+ new ValueBinding() {
+ public Class getType(FacesContext context) throws EvaluationException, PropertyNotFoundException {
+ return String.class;
+ }
+ public Object getValue(FacesContext context) throws EvaluationException, PropertyNotFoundException {
+ return bean.getValue();
+ }
+ public boolean isReadOnly(FacesContext context) throws EvaluationException, PropertyNotFoundException {
+ return false;
+ }
+ public void setValue(FacesContext context, Object value) throws EvaluationException, PropertyNotFoundException {
+ bean.setValue((String)value);
+ }
+ });
HtmlPage renderedView = renderView();
HtmlAnchor htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(command.getClientId(facesContext));
htmlLink.click();
- externalContext.addRequestParameterMap(slider.getClientId(facesContext),((UIInputNumberSlider)slider).getMaxValue());
- UIViewRoot root = facesContext.getViewRoot();
- root.processDecodes(facesContext);
- UIInputNumberSlider uiSlider = (UIInputNumberSlider) slider;
- if (uiSlider.isImmediate()){
- uiSlider.validate(facesContext);
- assertTrue(uiSlider.isValid());
- }
- assertTrue(externalContext.getRequestParameterMap().get(slider.getClientId(facesContext)).equals(uiSlider.getMaxValue()));
+ externalContext.addRequestParameterMap(slider.getClientId(facesContext),"66");
+ slider.processDecodes(facesContext);
+ assertTrue(bean.getValue().equals("66"));
+ ((UIInputNumberSlider)slider).setImmediate(true);
+ renderedView = renderView();
+ htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(command.getClientId(facesContext));
+ htmlLink.click();
+ externalContext.addRequestParameterMap(slider.getClientId(facesContext),"wrong value");
+ slider.processDecodes(facesContext);
+ assertTrue(facesContext.getMessages().hasNext());
}
- public void testValidate(){
- // tests if component is able to handle submittedValue() correctly (convert & validate)
+ public void testValidate() throws Exception{
+ HtmlPage renderedView = renderView();
+
+ HtmlAnchor htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(command.getClientId(facesContext));
+ htmlLink.click();
+ externalContext.addRequestParameterMap(slider.getClientId(facesContext),"wrong value");
+ slider.processDecodes(facesContext);
+ slider.processValidators(facesContext);
+
+ assertTrue(facesContext.getMessages().hasNext());
+
}
-}
+ private class SliderBean {
+
+ private String value;
+
+ SliderBean (){
+ this.value = "66";
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ }
+
+}
\ No newline at end of file
19 years
JBoss Rich Faces SVN: r343 - trunk/richfaces/menu-components/src/test/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: F.antonov
Date: 2007-04-10 11:06:24 -0400 (Tue, 10 Apr 2007)
New Revision: 343
Modified:
trunk/richfaces/menu-components/src/test/java/org/richfaces/component/MenuGroupComponentTest.java
trunk/richfaces/menu-components/src/test/java/org/richfaces/component/MenuItemComponentTest.java
Log:
Menu components test cases development.
Modified: trunk/richfaces/menu-components/src/test/java/org/richfaces/component/MenuGroupComponentTest.java
===================================================================
--- trunk/richfaces/menu-components/src/test/java/org/richfaces/component/MenuGroupComponentTest.java 2007-04-10 14:06:41 UTC (rev 342)
+++ trunk/richfaces/menu-components/src/test/java/org/richfaces/component/MenuGroupComponentTest.java 2007-04-10 15:06:24 UTC (rev 343)
@@ -50,14 +50,13 @@
extends AbstractAjax4JsfTestCase
{
-/* private static Set javaScripts = new HashSet();
+ private static Set javaScripts = new HashSet();
static {
- javaScripts.add("org.ajax4jsf.framework.ajax.AjaxScript()");
- javaScripts.add("org.ajax4jsf.framework.resource.PrototypeScript()");
- javaScripts.add("org.ajax4jsf.framework.util.command.CommandScript()");
- }
-*/
+ javaScripts.add("prototype.js");
+ javaScripts.add("AjaxScript");
+ }
+
private UIMenuGroup menuGroup;
private UIForm form;
@@ -183,9 +182,14 @@
assertTrue(link.getAttributeValue("href").contains("org/richfaces/renderkit/html/css/menucomponents.xcss"));
}
-/* public void testRenderScript() throws Exception {
+ /**
+ * Scripts link test.
+ */
+ public void testRenderScript() throws Exception {
HtmlPage page = renderView();
assertNotNull(page);
+ System.out.println(page.asXml());
+
List scripts = page.getDocumentElement().getHtmlElementsByTagName("script");
for (Iterator it = scripts.iterator(); it.hasNext();) {
HtmlScript item = (HtmlScript) it.next();
@@ -206,5 +210,5 @@
}
}
}
-*/
+
}
Modified: trunk/richfaces/menu-components/src/test/java/org/richfaces/component/MenuItemComponentTest.java
===================================================================
--- trunk/richfaces/menu-components/src/test/java/org/richfaces/component/MenuItemComponentTest.java 2007-04-10 14:06:41 UTC (rev 342)
+++ trunk/richfaces/menu-components/src/test/java/org/richfaces/component/MenuItemComponentTest.java 2007-04-10 15:06:24 UTC (rev 343)
@@ -21,10 +21,12 @@
package org.richfaces.component;
+import java.io.IOException;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import junit.framework.Assert;
@@ -37,9 +39,15 @@
import javax.faces.component.UIForm;
import javax.faces.component.html.HtmlForm;
import javax.faces.component.html.HtmlOutputText;
+import javax.faces.context.FacesContext;
import javax.faces.convert.IntegerConverter;
+import javax.faces.el.ValueBinding;
+import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
import javax.faces.event.PhaseId;
+import javax.faces.render.Renderer;
import org.richfaces.component.html.HtmlMenuItem;
import org.richfaces.renderkit.html.MenuItemRenderer;
@@ -65,14 +73,14 @@
public class MenuItemComponentTest
extends AbstractAjax4JsfTestCase
{
-/* private static Set javaScripts = new HashSet();
+ private static Set javaScripts = new HashSet();
static {
- javaScripts.add("org.ajax4jsf.framework.ajax.AjaxScript()");
- javaScripts.add("org.ajax4jsf.framework.resource.PrototypeScript()");
- javaScripts.add("org.ajax4jsf.framework.util.command.CommandScript()");
+ javaScripts.add("prototype.js");
+ javaScripts.add("AjaxScript");
+ javaScripts.add("CommandScript");
}
-*/
+
private UIMenuItem menuItem;
private UIForm form;
@@ -142,13 +150,13 @@
menuItem.setDisabled(true);
HtmlPage page = renderView();
assertNotNull(page);
- //System.out.println(page.asXml());
+ System.out.println(page.asXml());
HtmlElement span = page.getHtmlElementById(menuItem.getClientId(facesContext) + ":disabled");
assertNotNull(span);
assertEquals("span", span.getNodeName());
String classAttr = span.getAttributeValue("class");
- assertTrue(classAttr.contains("dr-menu-label dr-menu-label-disabled rich-menu-item-label rich-menu-item-label-disabled"));
+ assertTrue(classAttr.contains("dr-menu-label dr-menu-label-disabled rich-menu-item-label rich-menu-item-label-disabled"));
span = page.getHtmlElementById(menuItem.getClientId(facesContext) + ":icon");
assertNotNull(span);
@@ -161,6 +169,10 @@
assertEquals("div", div.getNodeName());
classAttr = div.getAttributeValue("class");
assertTrue(classAttr.contains("dr-menu-item dr-menu-item-disabled rich-menu-item rich-menu-item-disabled"));
+ classAttr = div.getAttributeValue("onmouseout");
+ assertEquals(0, classAttr.length());
+ classAttr = div.getAttributeValue("onmouseover");
+ assertEquals(0, classAttr.length());
}
/**
@@ -207,9 +219,14 @@
assertTrue(link.getAttributeValue("href").contains("org/richfaces/renderkit/html/css/menucomponents.xcss"));
}
-/* public void testRenderScript() throws Exception {
- HtmlPage page = renderView();
+ /**
+ * Scripts link test.
+ */
+ public void testRenderScript() throws Exception {
+ HtmlPage page = renderView();
assertNotNull(page);
+ System.out.println(page.asXml());
+
List scripts = page.getDocumentElement().getHtmlElementsByTagName("script");
for (Iterator it = scripts.iterator(); it.hasNext();) {
HtmlScript item = (HtmlScript) it.next();
@@ -230,7 +247,7 @@
}
}
}
-*/
+
/**
* doDecode method trst.
*/
@@ -246,7 +263,6 @@
Buffer events = mockViewRoot.getEventsQueue(facesContext, PhaseId.APPLY_REQUEST_VALUES);
assertNotNull(events);
assertEquals(1, events.size());
-
}
}
19 years
JBoss Rich Faces SVN: r342 - trunk/richfaces/panelbar/src/test/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: F.antonov
Date: 2007-04-10 10:06:41 -0400 (Tue, 10 Apr 2007)
New Revision: 342
Added:
trunk/richfaces/panelbar/src/test/java/org/richfaces/component/PanelBarComponentTest.java
Removed:
trunk/richfaces/panelbar/src/test/java/org/richfaces/component/JSFComponentTest.java
Log:
PanelBar components test cases development.
Deleted: trunk/richfaces/panelbar/src/test/java/org/richfaces/component/JSFComponentTest.java
===================================================================
--- trunk/richfaces/panelbar/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-10 13:52:19 UTC (rev 341)
+++ trunk/richfaces/panelbar/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-10 14:06:41 UTC (rev 342)
@@ -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 );
- }
-}
Copied: trunk/richfaces/panelbar/src/test/java/org/richfaces/component/PanelBarComponentTest.java (from rev 332, trunk/richfaces/panelbar/src/test/java/org/richfaces/component/JSFComponentTest.java)
===================================================================
--- trunk/richfaces/panelbar/src/test/java/org/richfaces/component/PanelBarComponentTest.java (rev 0)
+++ trunk/richfaces/panelbar/src/test/java/org/richfaces/component/PanelBarComponentTest.java 2007-04-10 14:06:41 UTC (rev 342)
@@ -0,0 +1,258 @@
+/**
+ * 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.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
+import javax.faces.component.html.HtmlForm;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
+
+import org.ajax4jsf.framework.ajax.AjaxScript;
+import org.ajax4jsf.framework.ajax.ImageCacheScript;
+import org.ajax4jsf.framework.resource.PrototypeScript;
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.ajax4jsf.tests.MockViewRoot;
+import org.apache.commons.collections.Buffer;
+import org.apache.commons.lang.StringUtils;
+import org.richfaces.component.html.HtmlPanelBar;
+import org.richfaces.component.html.HtmlPanelBarItem;
+import org.richfaces.event.SwitchablePanelSwitchEvent;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlScript;
+
+/**
+ * Unit test for PanelBar components.
+ */
+public class PanelBarComponentTest
+ extends AbstractAjax4JsfTestCase
+{
+
+ private static Set javaScripts = new HashSet();
+
+ static {
+ javaScripts.add("browser_info.js");
+ javaScripts.add("panelbar.js");
+ javaScripts.add("AjaxScript");
+ javaScripts.add("prototype.js");
+ javaScripts.add("ImageCacheScript");
+ }
+
+ private UIPanelBar panelBar;
+ private UIPanelBarItem panelBarItem1;
+ private UIPanelBarItem panelBarItem2;
+ private UIForm form;
+
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public PanelBarComponentTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+
+ form = new HtmlForm();
+ form.setId("form");
+ facesContext.getViewRoot().getChildren().add(form);
+
+ panelBar = (UIPanelBar) application.createComponent(HtmlPanelBar.COMPONENT_TYPE);
+ panelBar.setId("panelBar");
+ //panelBar.setValue("Menu Item");
+
+ panelBarItem1 = (UIPanelBarItem) application.createComponent(HtmlPanelBarItem.COMPONENT_TYPE);
+ panelBarItem1.setId("panelBarItem1");
+ panelBarItem1.setLabel("Panel Bar Item 1");
+ panelBarItem2 = (UIPanelBarItem) application.createComponent(HtmlPanelBarItem.COMPONENT_TYPE);
+ panelBarItem2.setId("panelBarItem2");
+ panelBarItem2.setLabel("Panel Bar Item 2");
+
+ panelBar.getChildren().add(panelBarItem1);
+ panelBar.getChildren().add(panelBarItem2);
+ form.getChildren().add(panelBar);
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ panelBarItem1 = null;
+ panelBarItem2 = null;
+ panelBar = null;
+ form = null;
+ }
+
+ /**
+ * PanelBar components renderer test.
+ */
+ public void testPanelBarRender() throws Exception
+ {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ //System.out.println(page.asXml());
+ HtmlElement div = page.getHtmlElementById(panelBar.getClientId(facesContext));
+ assertNotNull(div);
+ assertEquals("div", div.getNodeName());
+
+ div = page.getHtmlElementById(panelBarItem1.getClientId(facesContext));
+ assertNotNull(div);
+ assertEquals("div", div.getNodeName());
+
+ div = page.getHtmlElementById(panelBarItem2.getClientId(facesContext));
+ assertNotNull(div);
+ assertEquals("div", div.getNodeName());
+
+ HtmlElement input = page.getHtmlElementById(panelBar.getClientId(facesContext) + "_panelBarInput");
+ assertNotNull(input);
+ assertEquals("input", input.getNodeName());
+ assertEquals(input.getAttributeValue("type"), "hidden");
+ }
+
+ /**
+ * PanelBar attributes test.
+ */
+ public void testPanelBarAttributes() throws Exception
+ {
+ panelBar.setValue("panelBarItem1");
+ panelBar.getAttributes().put("styleClass", "panelBarStyleClass");
+ panelBar.getAttributes().put("headerClassActive", "panelBarHeaderClassActive");
+ panelBar.getAttributes().put("style", "panelBarHeaderStyle");
+ panelBar.setWidth("500");
+
+ panelBarItem1.getAttributes().put("headerClassActive", "panelBarItem1HeaderClassActive");
+ panelBarItem1.getAttributes().put("headerClass", "panelBarItem1HeaderClass");
+
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ //System.out.println(page.asXml());
+
+ HtmlElement div = page.getHtmlElementById(panelBar.getClientId(facesContext));
+ assertNotNull(div);
+ assertEquals("div", div.getNodeName());
+ String classAttr = div.getAttributeValue("class");
+ assertTrue(classAttr.contains("dr-pnlbar rich-panelbar dr-pnlbar-b"));
+ assertTrue(classAttr.contains("panelBarStyleClass"));
+ classAttr = div.getAttributeValue("style");
+ assertTrue(classAttr.contains("width: 500px;"));
+
+ HtmlElement input = page.getHtmlElementById(panelBar.getClientId(facesContext) + "_panelBarInput");
+ assertNotNull(input);
+ assertEquals("input", input.getNodeName());
+ classAttr = input.getAttributeValue("value");
+ assertTrue(classAttr.contains(panelBarItem1.getClientId(facesContext)));
+
+ div = page.getHtmlElementById(panelBarItem1.getClientId(facesContext));
+ assertNotNull(div);
+ assertEquals("div", div.getNodeName());
+ classAttr = div.getAttributeValue("class");
+ assertTrue(classAttr.contains("dr-pnlbar rich-panelbar dr-pnlbar-ext"));
+ assertTrue(classAttr.contains("panelBarStyleClass"));
+ classAttr = div.getAttributeValue("style");
+ assertTrue(classAttr.contains("panelBarHeaderStyle"));
+ List children = div.getHtmlElementsByTagName("div");
+ assertEquals(3, children.size());
+
+ }
+
+ /**
+ * CSS link test.
+ */
+ public void testRenderStyle() throws Exception {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ List links = page.getDocumentElement().getHtmlElementsByTagName("link");
+ //Assert.assertEquals(1, links.size());
+ assertNotNull(links);
+ HtmlElement link = (HtmlElement) links.get(0);
+ assertTrue(link.getAttributeValue("href").contains("org/richfaces/renderkit/html/css/panelbar.xcss"));
+ }
+
+ /**
+ * Scripts link test.
+ */
+ public void testRenderScript() throws Exception {
+ HtmlPage page = renderView();
+ System.out.println(page.asXml());
+
+ 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);
+ }
+ }
+ }
+
+ /**
+ * doDecode method trst.
+ */
+ public void testPanelBarDoDecode() throws Exception {
+
+ panelBar.setImmediate(true);
+ panelBar.setSwitchType(UISwitchablePanel.AJAX_METHOD);
+
+ externalContext.getRequestParameterMap().put(panelBar.getClientId(facesContext), "Swich");
+ panelBar.decode(facesContext);
+
+ MockViewRoot mockViewRoot = (MockViewRoot) facesContext.getViewRoot();
+ Buffer events = mockViewRoot.getEventsQueue(facesContext, PhaseId.APPLY_REQUEST_VALUES);
+ assertNotNull(events);
+ assertEquals(1, events.size());
+
+ FacesEvent event = (FacesEvent) events.iterator().next();
+ assertTrue(event instanceof SwitchablePanelSwitchEvent);
+ SwitchablePanelSwitchEvent switchEvent = (SwitchablePanelSwitchEvent) event;
+ assertEquals(switchEvent.getValue(), "Swich");
+
+ }
+}
19 years
JBoss Rich Faces SVN: r341 - in trunk/richfaces/datascroller/src: test/java/org/richfaces/component and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: A.Skokov
Date: 2007-04-10 09:52:19 -0400 (Tue, 10 Apr 2007)
New Revision: 341
Modified:
trunk/richfaces/datascroller/src/main/java/org/richfaces/component/UIDatascroller.java
trunk/richfaces/datascroller/src/test/java/org/richfaces/component/DatascrollerComponentTest.java
Log:
small refactoring, test updated
Modified: trunk/richfaces/datascroller/src/main/java/org/richfaces/component/UIDatascroller.java
===================================================================
--- trunk/richfaces/datascroller/src/main/java/org/richfaces/component/UIDatascroller.java 2007-04-10 13:45:41 UTC (rev 340)
+++ trunk/richfaces/datascroller/src/main/java/org/richfaces/component/UIDatascroller.java 2007-04-10 13:52:19 UTC (rev 341)
@@ -21,46 +21,46 @@
package org.richfaces.component;
-import java.util.Iterator;
+import org.richfaces.event.DataScrollerAdapter;
import org.richfaces.event.DataScrollerEvent;
import org.richfaces.event.DataScrollerListener;
import org.richfaces.event.DataScrollerSource;
-import org.richfaces.event.DataScrollerAdapter;
-import javax.faces.event.*;
-import javax.faces.el.MethodBinding;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.component.UIData;
-import javax.faces.component.html.HtmlPanelGroup;
import javax.faces.context.FacesContext;
+import javax.faces.el.MethodBinding;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
/**
* JSF component class
- *
*/
-//xxxx nick -> alex - extend UIComponentBase and
+//xxxx nick -> alex - extend UIComponentBase and
//create event listener & event classes to define PageSwitchEvent
public abstract class UIDatascroller extends UIComponentBase implements DataScrollerSource {
-
- public static final String COMPONENT_TYPE = "org.richfaces.Datascroller";
- public static final String COMPONENT_FAMILY = "org.richfaces.Datascroller";
- public static final String FIRST_FACET_NAME = "first";
+ public static final String COMPONENT_TYPE = "org.richfaces.Datascroller";
+ public static final String COMPONENT_FAMILY = "org.richfaces.Datascroller";
- public static final String LAST_FACET_NAME = "last";
+ public static final String FIRST_FACET_NAME = "first";
- public static final String NEXT_FACET_NAME = "next";
+ public static final String LAST_FACET_NAME = "last";
- public static final String PREVIOUS_FACET_NAME = "previous";
+ public static final String NEXT_FACET_NAME = "next";
- public static final String FAST_FORWARD_FACET_NAME = "fastforward";
+ public static final String PREVIOUS_FACET_NAME = "previous";
- public static final String FAST_REWIND_FACET_NAME = "fastrewind";
-
-
+ public static final String FAST_FORWARD_FACET_NAME = "fastforward";
+
+ public static final String FAST_REWIND_FACET_NAME = "fastrewind";
+
+ private transient UIData _UIData;
+ private transient boolean allowCache;
+
public void addScrollerListener(DataScrollerListener listener) {
addFacesListener(listener);
}
@@ -75,471 +75,405 @@
public void broadcast(FacesEvent event) throws AbortProcessingException {
super.broadcast(event);
- if (event instanceof DataScrollerEvent){
+ if (event instanceof DataScrollerEvent) {
- if(getScrollerListeners().length < 1){
+ if (getScrollerListeners().length < 1) {
addScrollerListener(new DataScrollerAdapter(getScrollerListener()));
event.queue();
}
}
-
}
+ public abstract MethodBinding getScrollerListener();
-
- public abstract MethodBinding getScrollerListener();
- public abstract void setScrollerListener(MethodBinding scrollerListener);
- public abstract void setFor(String f);
- public abstract String getFor();
- public abstract int getFastStep();
- public abstract void setFastStep(int FastStep);
- public abstract boolean isRenderIfSinglePage();
- public abstract void setRenderIfSinglePage(boolean renderIfSinglePage);
- public abstract int getMaxPages();
- public abstract void setMaxPages(int maxPages);
- public abstract boolean isRenderCurrentAsText();
- public abstract void setRenderCurrentAsText(boolean renderCurrentAsText);
- public abstract String getSelectedStyleClass();
- public abstract void setSelectedStyleClass(String selectedStyleClass);
- public abstract String getSelectedStyle();
- public abstract void setSelectedStyle(String selectedStyle);
- public abstract String getEventsQueue();
- public abstract void setEventsQueue(String eventsQueue);
- public abstract boolean isAjaxSingle();
- public abstract void setAjaxSingle(boolean ajaxSingle);
- public abstract int getRequestDelay();
- public abstract void setRequestDelay(int requestDelay);
- //public abstract boolean isImmediate();
- //public abstract void setImmediate(boolean immediate);
- public abstract String getTableStyleClass();
- public abstract void setTableStyleClass(String tableStyleClass);
- public abstract String getStyleClass();
- public abstract String getStyle();
- public abstract void setStyleClass(String styleClass);
- public abstract void setStyle(String styleClass);
- public abstract String getHandleValue();
- public abstract void setHandleValue(String handleValue);
+ public abstract void setScrollerListener(MethodBinding scrollerListener);
+ public abstract void setFor(String f);
- //TODO nick -> alex - it's better not to cache reference here - the component can be encoded
- //with different "for" values. we can cache it, but than we should set it on phase start and
- //reset it to null on phase end:
- //public processUpdates(...) {
- // try { allowCache = true; ... } finally { allowCache = false; _UIData = null; }
- //}
-
+ public abstract String getFor();
- public void processUpdates(FacesContext context){
- try {
-
- } catch (RuntimeException e) {
- context.renderResponse();
- throw e;
- } finally
- { allowCache = false; _UIData = null; }
+ public abstract int getFastStep();
- }
+ public abstract void setFastStep(int FastStep);
- public void processValidators(FacesContext context){
- try {
-
- } catch (RuntimeException e) {
- context.renderResponse();
- throw e;
- }finally
- { allowCache = false; _UIData = null; }
-
-
- }
-
- public void processDecodes(FacesContext context){
- try {
- decode(context);
-
- } catch (RuntimeException e) {
- context.renderResponse();
- throw e;
+ public abstract boolean isRenderIfSinglePage();
- }finally
- { allowCache = false; _UIData = null; }
+ public abstract void setRenderIfSinglePage(boolean renderIfSinglePage);
- }
-
-
- private transient UIData _UIData;
- private transient boolean allowCache;
+ public abstract int getMaxPages();
+ public abstract void setMaxPages(int maxPages);
+
+ public abstract boolean isRenderCurrentAsText();
+
+ public abstract void setRenderCurrentAsText(boolean renderCurrentAsText);
+
+ public abstract String getSelectedStyleClass();
+
+ public abstract void setSelectedStyleClass(String selectedStyleClass);
+
+ public abstract String getSelectedStyle();
+
+ public abstract void setSelectedStyle(String selectedStyle);
+
+ public abstract String getEventsQueue();
+
+ public abstract void setEventsQueue(String eventsQueue);
+
+ public abstract boolean isAjaxSingle();
+
+ public abstract void setAjaxSingle(boolean ajaxSingle);
+
+ public abstract int getRequestDelay();
+
+ public abstract void setRequestDelay(int requestDelay);
+
+ public abstract String getTableStyleClass();
+
+ public abstract void setTableStyleClass(String tableStyleClass);
+
+ public abstract String getStyleClass();
+
+ public abstract String getStyle();
+
+ public abstract void setStyleClass(String styleClass);
+
+ public abstract void setStyle(String styleClass);
+
+ public abstract String getHandleValue();
+
+ public abstract void setHandleValue(String handleValue);
+
+ //TODO nick -> alex - it's better not to cache reference here - the component can be encoded
+ //with different "for" values. we can cache it, but than we should set it on phase start and
+ //reset it to null on phase end:
+ //public processUpdates(...) {
+ // try { allowCache = true; ... } finally { allowCache = false; _UIData = null; }
+ //}
+
+ public void processUpdates(FacesContext context) {
+ try {
+
+ } catch (RuntimeException e) {
+ context.renderResponse();
+ throw e;
+ } finally {
+ allowCache = false;
+ _UIData = null;
+ }
+ }
+
+ public void processValidators(FacesContext context) {
+ try {
+
+ } catch (RuntimeException e) {
+ context.renderResponse();
+ throw e;
+ } finally {
+ allowCache = false;
+ _UIData = null;
+ }
+ }
+
+ public void processDecodes(FacesContext context) {
+ try {
+ decode(context);
+
+ } catch (RuntimeException e) {
+ context.renderResponse();
+ throw e;
+ } finally {
+ allowCache = false;
+ _UIData = null;
+ }
+ }
+
// private UIData getUIData() {
// if (_UIData == null) {
// _UIData = getDataTable();
// }
// return _UIData;
// }
-
- private UIData getUIData() {
- if (!allowCache) {
- _UIData = getDataTable();
- allowCache=true;
- }
- return _UIData;
- }
-
- /**
- * Finds the dataTable which id is mapped to the "for" property
- *
- * @return the dataTable component
- */
- protected UIData getDataTable() {
- String forAttribute = getFor();
- UIComponent forComp;
- if (forAttribute == null) {
- forComp=this;
- while((forComp = forComp.getParent())!= null) {
- if (forComp instanceof UIData) {
- setFor(forComp.getId());
- return (UIData) forComp;
- }
- }
- throw new FacesException("could not dataTable for datascroller "+ this.getId());
- }
- else {
- forComp = findComponent(forAttribute);
- }
- if (forComp == null) {
- throw new IllegalArgumentException("could not dataTable with id '"
- + forAttribute + "'");
- }
- else if (!(forComp instanceof UIData)) {
- throw new IllegalArgumentException("component with id '" + forAttribute
- + "' must be of type " + UIData.class.getName() + ", not type "
- + forComp.getClass().getName());
- }
- return (UIData) forComp;
- }
+ private UIData getUIData() {
+ if (!allowCache) {
+ _UIData = getDataTable();
+ allowCache = true;
+ }
+ return _UIData;
+ }
- /**
- * Gets the index of the current page
- *
- * @return the page index
- */
- public int getPageIndex() {
- UIData uiData = getUIData();
- //xxxx nick -> alex - suppose this.getRows() would be better here
- int rows = getRows();
- if (0 == rows) {
- throw new FacesException("Missing 'rows' attribute on component '"
- + uiData.getId() + "'");
- }
- int pageIndex;
- if (rows > 0) {
- //xxxx nick -> alex - suppose this.getFirst() would be better here
- pageIndex = getFirstRow() / rows + 1;
- }
- else {
- //TODO nick -> nick - is it valid if under 0?
- pageIndex = 0;
- }
- if (getFirstRow() % rows > 0) {
- pageIndex++;
- }
- return pageIndex;
- }
+ /**
+ * Finds the dataTable which id is mapped to the "for" property
+ *
+ * @return the dataTable component
+ */
+ protected UIData getDataTable() {
+ String forAttribute = getFor();
+ UIComponent forComp;
+ if (forAttribute == null) {
+ forComp = this;
+ while ((forComp = forComp.getParent()) != null) {
+ if (forComp instanceof UIData) {
+ setFor(forComp.getId());
+ return (UIData) forComp;
+ }
+ }
+ throw new FacesException("could not dataTable for datascroller " + this.getId());
+ } else {
+ forComp = findComponent(forAttribute);
+ }
+ if (forComp == null) {
+ throw new IllegalArgumentException("could not dataTable with id '"
+ + forAttribute + "'");
+ } else if (!(forComp instanceof UIData)) {
+ throw new IllegalArgumentException("component with id '" + forAttribute
+ + "' must be of type " + UIData.class.getName() + ", not type "
+ + forComp.getClass().getName());
+ }
+ return (UIData) forComp;
+ }
- /**
- * Sets the page number according to the parameter recived from the
- * commandLink
- *
- * @param facetName
- */
- public void setPage(String facetName) {
+ /**
+ * Gets the index of the current page
+ *
+ * @return the page index
+ */
+ public int getPageIndex() {
+ UIData uiData = getUIData();
+ //xxxx nick -> alex - suppose this.getRows() would be better here
+ int rows = getRows();
+ if (0 == rows) {
+ throw new FacesException("Missing 'rows' attribute on component '"
+ + uiData.getId() + "'");
+ }
- UIData dataTable = getUIData();
+ int pageIndex;
+ if (rows > 0) {
+ //xxxx nick -> alex - suppose this.getFirst() would be better here
+ pageIndex = getFirstRow() / rows + 1;
+ } else {
+ //TODO nick -> nick - is it valid if under 0?
+ pageIndex = 0;
+ }
+ if (getFirstRow() % rows > 0) {
+ pageIndex++;
+ }
+ return pageIndex;
+ }
- // check if facet is selected
- if (FIRST_FACET_NAME.equals(facetName)) {
- dataTable.setFirst(0);
- }
- else if (PREVIOUS_FACET_NAME.equals(facetName)) {
- int previous = dataTable.getFirst() - getRows();
- if (previous >= 0) dataTable.setFirst(previous);
- }
- else if (NEXT_FACET_NAME.equals(facetName)) {
- int rows = getRows();
- int next = dataTable.getFirst() + rows;
- if (next < getRowCount()) dataTable.setFirst(next);
- //if (rows>0){
- // if (((next+rows)/rows)>getMaxPages()){
- // next=getMaxPages()*rows-rows;;
- // }
- //}
- }
- else if (FAST_FORWARD_FACET_NAME.equals(facetName)) {
- int fastStep = getFastStep();
- int rows = getRows();
- if (fastStep <= 0) fastStep = 1;
- int next = dataTable.getFirst() + rows * fastStep;
- int rowcount = getRowCount();
- if (next >= rowcount)
- next = (rowcount - 1) - ((rowcount - 1) % rows);
- //if (rows>0){
- // if (((next+rows)/rows)>getMaxPages()){
- // next=getMaxPages()*rows-rows;;
- //}
- //}
- dataTable.setFirst(next);
- }
- else if (FAST_REWIND_FACET_NAME.equals(facetName)) {
- int fastStep = getFastStep();
- if (fastStep <= 0) fastStep = 1;
- int previous = dataTable.getFirst() - getRows() * fastStep;
- if (previous < 0) previous = 0;
- dataTable.setFirst(previous);
- }
- else if (LAST_FACET_NAME.equals(facetName)) {
- int rowcount = getRowCount();
- int rows = getRows();
- int delta = rowcount % rows;
- int first = delta > 0 && delta < rows ? rowcount - delta : rowcount
- - rows;
- if (first >= 0) {
- //if (rows>0){
- //if (((first+rows)/rows)>getMaxPages()){
- // first=getMaxPages()*rows-rows;
- //}
- //}
- dataTable.setFirst(first);
- }
- else {
- dataTable.setFirst(0);
- }
- }
- // the paginator is selected
- else {
- int pageindex = Integer.parseInt(facetName);
- int pageCount = getPageCount();
- if (pageindex > pageCount) {
- pageindex = pageCount;
- }
- else if (pageindex <= 0) {
- pageindex = 1;
- }
- dataTable.setFirst(getRows() * (pageindex - 1));
- }
+ /**
+ * Sets the page number according to the parameter recived from the
+ * commandLink
+ *
+ * @param facetName
+ */
+ public void setPage(String facetName) {
- }
+ UIData dataTable = getUIData();
- /**
- * Sets the page index
- *
- * @param page number
- */
- public void setPageIndex(int page) {
- UIData uiData = getUIData();
- int rows = getRows();
- if (0 == rows) {
- throw new FacesException("Missing 'rows' attribute on component '"
- + uiData.getId() + "'");
- }
- if (page>0){
- uiData.setFirst(page * rows);
- }
- }
+ // check if facet is selected
+ if (FIRST_FACET_NAME.equals(facetName)) {
+ dataTable.setFirst(0);
+ } else if (PREVIOUS_FACET_NAME.equals(facetName)) {
+ int previous = dataTable.getFirst() - getRows();
+ if (previous >= 0) dataTable.setFirst(previous);
+ } else if (NEXT_FACET_NAME.equals(facetName)) {
+ int rows = getRows();
+ int next = dataTable.getFirst() + rows;
+ if (next < getRowCount()) dataTable.setFirst(next);
+ //if (rows>0){
+ // if (((next+rows)/rows)>getMaxPages()){
+ // next=getMaxPages()*rows-rows;;
+ // }
+ //}
+ } else if (FAST_FORWARD_FACET_NAME.equals(facetName)) {
+ int fastStep = getFastStep();
+ int rows = getRows();
+ if (fastStep <= 0) fastStep = 1;
+ int next = dataTable.getFirst() + rows * fastStep;
+ int rowcount = getRowCount();
+ if (next >= rowcount)
+ next = (rowcount - 1) - ((rowcount - 1) % rows);
+ //if (rows>0){
+ // if (((next+rows)/rows)>getMaxPages()){
+ // next=getMaxPages()*rows-rows;;
+ //}
+ //}
+ dataTable.setFirst(next);
+ } else if (FAST_REWIND_FACET_NAME.equals(facetName)) {
+ int fastStep = getFastStep();
+ if (fastStep <= 0) fastStep = 1;
+ int previous = dataTable.getFirst() - getRows() * fastStep;
+ if (previous < 0) previous = 0;
+ dataTable.setFirst(previous);
+ } else if (LAST_FACET_NAME.equals(facetName)) {
+ int rowcount = getRowCount();
+ int rows = getRows();
+ int delta = rowcount % rows;
+ int first = delta > 0 && delta < rows ? rowcount - delta : rowcount
+ - rows;
+ if (first >= 0) {
+ //if (rows>0){
+ //if (((first+rows)/rows)>getMaxPages()){
+ // first=getMaxPages()*rows-rows;
+ //}
+ //}
+ dataTable.setFirst(first);
+ } else {
+ dataTable.setFirst(0);
+ }
+ }
+ // the paginator is selected
+ else {
+ int pageindex = Integer.parseInt(facetName);
+ int pageCount = getPageCount();
+ if (pageindex > pageCount) {
+ pageindex = pageCount;
+ } else if (pageindex <= 0) {
+ pageindex = 1;
+ }
+ dataTable.setFirst(getRows() * (pageindex - 1));
+ }
- /**
- * @return the page count of the uidata
- */
- public int getPageCount() {
- //UIData uiData = getUIData();
- int rows = getRows();
- int pageCount;
- if (rows > 0) {
- pageCount = rows <= 0 ? 1 : getRowCount() / rows;
- if (getRowCount() % rows > 0) {
- pageCount++;
- }
- if (pageCount==0){
- pageCount=1;
- }
- }
- else {
- rows = 1;
- pageCount = 1;
- }
- return pageCount;
- }
+ }
- /**
- * @return int
- */
- public int getRowCount() {
- //xxx nick -> alex - scrollable models can return -1 here
- //let's implement "dychotomic" discovery
- // setPage(1)... if isPageAvailable() setPage(2) then 4, 8, etc.
- // setPage() { setRowIndex(pageIdx * rows); }
- // isPageAvailable() { return isRowAvailable() }
- //return getUIData().getRowCount();
- return BinarySearch(getUIData());
- }
+ /**
+ * Sets the page index
+ *
+ * @param page number
+ */
+ public void setPageIndex(int page) {
+ UIData uiData = getUIData();
+ int rows = getRows();
+ if (0 == rows) {
+ throw new FacesException("Missing 'rows' attribute on component '"
+ + uiData.getId() + "'");
+ }
+ if (page > 0) {
+ uiData.setFirst(page * rows);
+ }
+ }
-
- private int BinarySearch(UIData Data)
- {
- int n=1;
- int k=2;
- for (;;){
- Data.setRowIndex(k-1);
- if (Data.isRowAvailable()){
- n=k;
- k=k*2;
- }
- else{
- break;
- }
- }
-
-
- while (n < k) {
- int kk = (int)Math.round((n + k)/ 2)+1;
- Data.setRowIndex(kk-1);
- if (Data.isRowAvailable()){
- n = kk;
- }
- else{
- k=kk-1;
- }
- }
-
-
- Data.setRowIndex(k-1);
- if (Data.isRowAvailable()){
- return k;
- }
- else{
- return 0;
- }
- }
+ /**
+ * @return the page count of the uidata
+ */
+ public int getPageCount() {
+ //UIData uiData = getUIData();
+ int rows = getRows();
+ int pageCount;
+ if (rows > 0) {
+ pageCount = rows <= 0 ? 1 : getRowCount() / rows;
+ if (getRowCount() % rows > 0) {
+ pageCount++;
+ }
+ if (pageCount == 0) {
+ pageCount = 1;
+ }
+ } else {
+ rows = 1;
+ pageCount = 1;
+ }
+ return pageCount;
+ }
-
-
- /**
- * @return int
- */
- public int getRows() {
- int row=0;
- row=getUIData().getRows();
- if (row==0){
- //if (getRowCount()>=2){
- // row=2;
- //
- //}
- //else{
- row=getRowCount();
-
- //}
-
- }
-
- return row;
- //return getUIData().getRowCount();
-
- }
+ /**
+ * @return int
+ */
+ public int getRowCount() {
+ //xxx nick -> alex - scrollable models can return -1 here
+ //let's implement "dychotomic" discovery
+ // setPage(1)... if isPageAvailable() setPage(2) then 4, 8, etc.
+ // setPage() { setRowIndex(pageIdx * rows); }
+ // isPageAvailable() { return isRowAvailable() }
+ //return getUIData().getRowCount();
+ return new BinarySearch().search(getUIData());
+ }
- // facet getter methods
- public UIComponent getFirst() {
- return (UIComponent) getFacet(FIRST_FACET_NAME);
- }
+ /**
+ * @return int
+ */
+ public int getRows() {
+ int row = 0;
+ row = getUIData().getRows();
+ if (row == 0) {
+ row = getRowCount();
+ }
- public UIComponent getLast() {
- return (UIComponent) getFacet(LAST_FACET_NAME);
- }
+ return row;
+ }
- public UIComponent getNext() {
- return (UIComponent) getFacet(NEXT_FACET_NAME);
- }
+ // facet getter methods
+ public UIComponent getFirst() {
+ return getFacet(FIRST_FACET_NAME);
+ }
- public UIComponent getFastForward() {
- return (UIComponent) getFacet(FAST_FORWARD_FACET_NAME);
- }
+ public UIComponent getLast() {
+ return getFacet(LAST_FACET_NAME);
+ }
- public UIComponent getFastRewind() {
- return (UIComponent) getFacet(FAST_REWIND_FACET_NAME);
- }
+ public UIComponent getNext() {
+ return getFacet(NEXT_FACET_NAME);
+ }
- public UIComponent getPrevious() {
- return (UIComponent) getFacet(PREVIOUS_FACET_NAME);
- }
+ public UIComponent getFastForward() {
+ return getFacet(FAST_FORWARD_FACET_NAME);
+ }
- /**
- * @return int
- */
- public int getFirstRow() {
- return getUIData().getFirst();
- }
+ public UIComponent getFastRewind() {
+ return getFacet(FAST_REWIND_FACET_NAME);
+ }
- public void setFirstRow(int rows) {
- getUIData().setFirst(rows);
- }
+ public UIComponent getPrevious() {
+ return getFacet(PREVIOUS_FACET_NAME);
+ }
-
-
-
-
-
-
-/*
- public Object saveState(FacesContext context) {
- Object values[] = new Object[17];
- values[0] = super.saveState(context);
- values[1] = _for;
- values[2] = tableStyleClass;
- values[3] = tableStyle;
- values[4] = selectedStyleClass;
- values[5] = selectedStyle;
- values[6] = styleClass;
- values[7] = style;
- values[8] = maxPages;
- values[9] = renderIfSinglePage;
- values[10] = fastStep;
- values[11] = immediate;
- values[12] = ignoreDupResponses;
- values[13] = eventsQueue;
- values[14] = requestDelay;
- values[15] = ajaxSingle;
- values[16] = renderCurrentAsText;
- return values;
- }
+ /**
+ * @return int
+ */
+ public int getFirstRow() {
+ return getUIData().getFirst();
+ }
- public void restoreState(FacesContext context, Object state) {
- Object values[] = (Object[]) state;
- super.restoreState(context, values[0]);
- _for = (String) values[1];
- tableStyleClass = (String) values[2];
- tableStyle = (String) values[3];
- selectedStyleClass = (String) values[4];
- selectedStyle = (String) values[5];
- styleClass = (String) values[6];
- style = (String) values[7];
- maxPages = (Integer) values[8];
- renderIfSinglePage = (Boolean) values[9];
- fastStep = (Integer) values[10];
- immediate = (Boolean) values[11];
- ignoreDupResponses = (Boolean) values[12];
- eventsQueue = (String) values[13];
- requestDelay = (Integer) values[14];
- ajaxSingle = (Boolean) values[15];
- renderCurrentAsText = (Boolean) values[16];
- }
-*/
+ public void setFirstRow(int rows) {
+ getUIData().setFirst(rows);
+ }
- public String getFamily() {
- return COMPONENT_FAMILY;
- }
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
- //public String getRendererType() {
- // return RENDERER_TYPE;
- //}
+ static class BinarySearch {
+ public int search(UIData data) {
+ int n = 1;
+ int k = 2;
+ for (; ;) {
+ data.setRowIndex(k - 1);
+ if (data.isRowAvailable()) {
+ n = k;
+ k = k * 2;
+ } else {
+ break;
+ }
+ }
+ while (n < k) {
+ int kk = Math.round((n + k) / 2) + 1;
+ data.setRowIndex(kk - 1);
+ if (data.isRowAvailable()) {
+ n = kk;
+ } else {
+ k = kk - 1;
+ }
+ }
+ data.setRowIndex(k - 1);
+ if (data.isRowAvailable()) {
+ return k;
+ } else {
+ return 0;
+ }
+ }
+ }
}
Modified: trunk/richfaces/datascroller/src/test/java/org/richfaces/component/DatascrollerComponentTest.java
===================================================================
--- trunk/richfaces/datascroller/src/test/java/org/richfaces/component/DatascrollerComponentTest.java 2007-04-10 13:45:41 UTC (rev 340)
+++ trunk/richfaces/datascroller/src/test/java/org/richfaces/component/DatascrollerComponentTest.java 2007-04-10 13:52:19 UTC (rev 341)
@@ -77,12 +77,12 @@
form.setId("form");
facesContext.getViewRoot().getChildren().add(form);
- data = (UIData)application.createComponent(HtmlDataTable.COMPONENT_TYPE);
+ data = (UIData) application.createComponent(HtmlDataTable.COMPONENT_TYPE);
data.setId("data");
data.setRows(5);
form.getChildren().add(data);
- scroller = (UIDatascroller)application.createComponent("org.richfaces.Datascroller");
+ scroller = (UIDatascroller) application.createComponent("org.richfaces.Datascroller");
scroller.setId("dataScroller");
scroller.setFor(data.getId());
@@ -194,7 +194,8 @@
if (StringUtils.isNotBlank(srcAttr)) {
boolean found = false;
- for (Iterator srcIt = javaScripts.iterator(); srcIt.hasNext();) {
+ for (Iterator srcIt = javaScripts.iterator(); srcIt.hasNext();)
+ {
String src = (String) srcIt.next();
found = srcAttr.contains(src);
@@ -207,4 +208,96 @@
}
}
}
+
+ /**
+ * Test binary search
+ *
+ * @throws Exception
+ */
+ public void testBinarySearch() throws Exception {
+ class MockData extends UIData {
+ private int rowIndex;
+ private int minRow;
+ private int maxRow;
+
+ public int getMaxRow() {
+ return maxRow;
+ }
+
+ public void setMaxRow(int maxRow) {
+ this.maxRow = maxRow;
+ }
+
+ public int getMinRow() {
+ return minRow;
+ }
+
+ public void setMinRow(int minRow) {
+ this.minRow = minRow;
+ }
+
+ public boolean isRowAvailable() {
+ return rowIndex >= getMinRow() && rowIndex < getMaxRow();
+ }
+
+ public void setRowIndex(int rowIndex) {
+ this.rowIndex = rowIndex;
+ }
+ }
+
+ MockData data;
+ UIDatascroller.BinarySearch bs = new UIDatascroller.BinarySearch();
+
+ data = new MockData();
+ data.setMaxRow(1);
+ assertEquals(1, bs.search(data));
+
+ data = new MockData();
+ data.setMaxRow(2);
+ assertEquals(2, bs.search(data));
+
+ data = new MockData();
+ data.setMaxRow(3);
+ assertEquals(3, bs.search(data));
+
+ data = new MockData();
+ data.setMaxRow(4);
+ assertEquals(4, bs.search(data));
+
+ data = new MockData();
+ data.setMaxRow(5);
+ assertEquals(5, bs.search(data));
+
+ data = new MockData();
+ data.setMaxRow(6);
+ assertEquals(6, bs.search(data));
+
+ data = new MockData();
+ data.setMaxRow(7);
+ assertEquals(7, bs.search(data));
+
+ data = new MockData();
+ data.setMaxRow(8);
+ assertEquals(8, bs.search(data));
+
+ data = new MockData();
+ data.setMaxRow(9);
+ assertEquals(9, bs.search(data));
+
+ data = new MockData();
+ data.setMaxRow(10);
+ assertEquals(10, bs.search(data));
+
+ data = new MockData();
+ data.setMaxRow(11);
+ assertEquals(11, bs.search(data));
+
+ data = new MockData();
+ data.setMaxRow(12);
+ assertEquals(12, bs.search(data));
+
+ data = new MockData();
+ data.setMaxRow(13);
+ assertEquals(13, bs.search(data));
+ }
}
19 years
JBoss Rich Faces SVN: r340 - trunk/richfaces/modal-panel/src/test/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: sergeyhalipov
Date: 2007-04-10 09:45:41 -0400 (Tue, 10 Apr 2007)
New Revision: 340
Modified:
trunk/richfaces/modal-panel/src/test/java/org/richfaces/component/ModalPanelComponentTest.java
Log:
Ghanged JUnit test for modal-panel component.
Modified: trunk/richfaces/modal-panel/src/test/java/org/richfaces/component/ModalPanelComponentTest.java
===================================================================
--- trunk/richfaces/modal-panel/src/test/java/org/richfaces/component/ModalPanelComponentTest.java 2007-04-10 13:31:14 UTC (rev 339)
+++ trunk/richfaces/modal-panel/src/test/java/org/richfaces/component/ModalPanelComponentTest.java 2007-04-10 13:45:41 UTC (rev 340)
@@ -36,6 +36,7 @@
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
import org.apache.commons.lang.StringUtils;
+import org.richfaces.renderkit.ModalPanelRendererBase;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
@@ -46,6 +47,12 @@
*/
public class ModalPanelComponentTest extends AbstractAjax4JsfTestCase {
private static Set javaScripts = new HashSet();
+
+ protected String[] RESIZERS = new String[] {
+ "NWU", "N", "NEU", "NEL", "E",
+ "SEU", "SEL", "S", "SWL",
+ "SWU", "W", "NWL"
+ };
static {
javaScripts.add("org.ajax4jsf.framework.ajax.AjaxScript");
@@ -121,10 +128,19 @@
HtmlElement header = renderedView.getHtmlElementById(modalPanel.getClientId(facesContext) + "Header");
assertNotNull(header);
- System.out.println(header.getAttributeValue("class"));
+
assertTrue(header.getAttributeValue("class").contains("dr-mpnl-pnl-text dr-mpnl-pnl-h"));
assertTrue(header.getAttributeValue("class").contains("rich-mpnl-text"));
assertTrue(header.getAttributeValue("class").contains("rich-mpnl-header"));
+
+ // Test resizers
+ String[] resizers = RESIZERS;
+ for (int i = 0; i < resizers.length; i++) {
+ HtmlElement resizer = renderedView.getHtmlElementById(modalPanel.getClientId(facesContext) + "Resizer" + resizers[i]);
+ assertNotNull(resizer);
+ assertTrue(resizer.getAttributeValue("class").contains("dr-mpnl-resizer rich-mpnl-resizer"));
+ }
+
}
/**
19 years
JBoss Rich Faces SVN: r339 - in trunk/richfaces/gmap/src: test/java/org/richfaces/component and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: sergeyhalipov
Date: 2007-04-10 09:31:14 -0400 (Tue, 10 Apr 2007)
New Revision: 339
Added:
trunk/richfaces/gmap/src/test/java/org/richfaces/component/GmapComponentTest.java
Removed:
trunk/richfaces/gmap/src/test/java/org/richfaces/component/JSFComponentTest.java
Modified:
trunk/richfaces/gmap/src/main/java/org/richfaces/component/UIGmap.java
Log:
JUnit tests for gmap component.
Modified: trunk/richfaces/gmap/src/main/java/org/richfaces/component/UIGmap.java
===================================================================
--- trunk/richfaces/gmap/src/main/java/org/richfaces/component/UIGmap.java 2007-04-10 13:02:07 UTC (rev 338)
+++ trunk/richfaces/gmap/src/main/java/org/richfaces/component/UIGmap.java 2007-04-10 13:31:14 UTC (rev 339)
@@ -29,7 +29,7 @@
*/
public abstract class UIGmap extends UIComponentBase {
- private static final String COMPONENT_TYPE = "org.richfaces.Gmap";
+ public static final String COMPONENT_TYPE = "org.richfaces.Gmap";
private static final String COMPONENT_FAMILY = "org.richfaces.Gmap";
Copied: trunk/richfaces/gmap/src/test/java/org/richfaces/component/GmapComponentTest.java (from rev 332, trunk/richfaces/gmap/src/test/java/org/richfaces/component/JSFComponentTest.java)
===================================================================
--- trunk/richfaces/gmap/src/test/java/org/richfaces/component/GmapComponentTest.java (rev 0)
+++ trunk/richfaces/gmap/src/test/java/org/richfaces/component/GmapComponentTest.java 2007-04-10 13:31:14 UTC (rev 339)
@@ -0,0 +1,145 @@
+/**
+ * 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.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import javax.faces.component.UICommand;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
+import javax.faces.component.html.HtmlForm;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.apache.commons.lang.StringUtils;
+
+import com.gargoylesoftware.htmlunit.html.DomNode;
+import com.gargoylesoftware.htmlunit.html.DomText;
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlScript;
+
+/**
+ * Unit test for simple Component.
+ */
+public class GmapComponentTest extends AbstractAjax4JsfTestCase {
+ private UIForm form = null;
+ private UIComponent gmap = null;
+ private static Set javaScripts = new HashSet();
+
+ private final static String TEST_STYLE = "width:500px; height:400px";
+
+ static {
+ javaScripts.add("prototype.js");
+ javaScripts.add("org.ajax4jsf.framework.ajax.AjaxScript");
+ javaScripts.add("script/gmap.js");
+ javaScripts.add("http://maps.google.com");
+ }
+
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public GmapComponentTest( String testName )
+ {
+ super( testName );
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ form = new HtmlForm();
+ facesContext.getViewRoot().getChildren().add(form);
+
+ gmap = application.createComponent(UIGmap.COMPONENT_TYPE);
+ gmap.setId("gmap");
+
+ gmap.getAttributes().put("style", TEST_STYLE);
+ gmap.getAttributes().put("showGLargeMapControl", "true");
+ gmap.getAttributes().put("showGMapTypeControl", "true");
+ gmap.getAttributes().put("gmapVar", "testGmap");
+
+ form.getChildren().add(gmap);
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ gmap = null;
+ form = null;
+ }
+
+ public void testRendcerComponent() throws Exception {
+ HtmlPage renderedView = renderView();
+
+ HtmlElement htmlGmap = renderedView.getHtmlElementById(gmap.getClientId(facesContext));
+
+ assertNotNull(htmlGmap);
+ assertTrue("div".equals(htmlGmap.getTagName()));
+ assertEquals(htmlGmap.getAttributeValue("style"), TEST_STYLE);
+
+ assertTrue(htmlGmap.getAttributeValue("class").contains("dr-gmap"));
+ assertTrue(htmlGmap.getAttributeValue("class").contains("rich-gmap"));
+
+ }
+
+ 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/gmap.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);
+ }
+ }
+ }
+
+}
Deleted: trunk/richfaces/gmap/src/test/java/org/richfaces/component/JSFComponentTest.java
===================================================================
--- trunk/richfaces/gmap/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-10 13:02:07 UTC (rev 338)
+++ trunk/richfaces/gmap/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-10 13:31:14 UTC (rev 339)
@@ -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 );
- }
-}
19 years