[richfaces-svn-commits] JBoss Rich Faces SVN: r376 - in trunk/richfaces: common/src/main/java/org/richfaces/component/util and 15 other directories.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Wed Apr 11 16:16:30 EDT 2007
Author: nbelaevski
Date: 2007-04-11 16:16:30 -0400 (Wed, 11 Apr 2007)
New Revision: 376
Added:
trunk/richfaces/common/src/test/
trunk/richfaces/common/src/test/java/
trunk/richfaces/common/src/test/java/org/
trunk/richfaces/common/src/test/java/org/richfaces/
trunk/richfaces/common/src/test/java/org/richfaces/component/
trunk/richfaces/common/src/test/java/org/richfaces/component/nsutils/
trunk/richfaces/common/src/test/java/org/richfaces/component/nsutils/NSUtilsTest.java
trunk/richfaces/common/src/test/java/org/richfaces/component/util/
trunk/richfaces/common/src/test/java/org/richfaces/component/util/FormUtilTest.java
trunk/richfaces/common/src/test/java/org/richfaces/component/util/HtmlUtilTest.java
trunk/richfaces/common/src/test/java/org/richfaces/renderkit/
trunk/richfaces/common/src/test/java/org/richfaces/renderkit/CompositeRendererTest.java
trunk/richfaces/common/src/test/resources/
trunk/richfaces/common/src/test/resources/org/
trunk/richfaces/common/src/test/resources/org/richfaces/
trunk/richfaces/common/src/test/resources/org/richfaces/renderkit/
trunk/richfaces/common/src/test/resources/org/richfaces/renderkit/form_script
trunk/richfaces/common/src/test/resources/org/richfaces/renderkit/form_style
trunk/richfaces/common/src/test/resources/org/richfaces/renderkit/input_script
trunk/richfaces/common/src/test/resources/org/richfaces/renderkit/input_style
Modified:
trunk/richfaces/common/src/main/java/org/richfaces/component/util/HtmlUtil.java
trunk/richfaces/common/src/main/java/org/richfaces/renderkit/CompositeRenderer.java
trunk/richfaces/common/src/main/java/org/richfaces/renderkit/html/BaseGradient.java
trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeComponentTest.java
Log:
Tests added
Modified: trunk/richfaces/common/src/main/java/org/richfaces/component/util/HtmlUtil.java
===================================================================
--- trunk/richfaces/common/src/main/java/org/richfaces/component/util/HtmlUtil.java 2007-04-11 20:13:32 UTC (rev 375)
+++ trunk/richfaces/common/src/main/java/org/richfaces/component/util/HtmlUtil.java 2007-04-11 20:16:30 UTC (rev 376)
@@ -42,10 +42,10 @@
}
public static String addToSize(String declaration, String delta) {
- Integer intDelta = Integer.valueOf(delta);
+ Double doubleDelta = HtmlDimensions.decode(delta);
Double decoded = HtmlDimensions.decode(declaration);
return HtmlDimensions.formatPx(
- new Double(decoded.doubleValue() + intDelta.doubleValue()));
+ new Double(decoded.doubleValue() + doubleDelta.doubleValue()));
}
}
Modified: trunk/richfaces/common/src/main/java/org/richfaces/renderkit/CompositeRenderer.java
===================================================================
--- trunk/richfaces/common/src/main/java/org/richfaces/renderkit/CompositeRenderer.java 2007-04-11 20:13:32 UTC (rev 375)
+++ trunk/richfaces/common/src/main/java/org/richfaces/renderkit/CompositeRenderer.java 2007-04-11 20:16:30 UTC (rev 376)
@@ -143,7 +143,7 @@
protected void doDecode(FacesContext context, UIComponent component) {
super.doDecode(context, component);
- DECODE_COMMAND.execute(renderers.iterator(), context, component, null, null);
+ DECODE_COMMAND.execute(renderers.iterator(), context, component, null, component.getClass());
}
protected void mergeScriptOptions(ScriptOptions scriptOptions, FacesContext context, UIComponent component) {
@@ -191,7 +191,7 @@
}
protected String getScriptContributions(String varString, FacesContext context, UIComponent component) {
- return getScriptContributions(varString, context, component, null);
+ return getScriptContributions(varString, context, component, component.getClass());
}
protected String getScriptContributions(String varString, FacesContext context, UIComponent component, Class acceptableClass) {
@@ -212,15 +212,23 @@
renderers.add(renderer);
}
+ protected RendererContributor[] getContributors() {
+ return (RendererContributor[]) renderers.toArray(new RendererContributor[renderers.size()]);
+ }
+
public void contributorDecodeCallback(UIComponent component, FacesContext context, RendererContributor contributor,
Object argument) {
}
- public void addParameterEncoder(AttributeParametersEncoder encoder) {
+ protected void addParameterEncoder(AttributeParametersEncoder encoder) {
parameterEncoders.add(encoder);
}
+ protected AttributeParametersEncoder[] getParameterEncoders() {
+ return (AttributeParametersEncoder[]) parameterEncoders.toArray(new AttributeParametersEncoder[renderers.size()]);
+ }
+
public void encodeAttributeParameters(FacesContext context, UIComponent component) throws IOException {
for (Iterator iterator = parameterEncoders.iterator(); iterator.hasNext();) {
AttributeParametersEncoder encoder = (AttributeParametersEncoder) iterator.next();
Modified: trunk/richfaces/common/src/main/java/org/richfaces/renderkit/html/BaseGradient.java
===================================================================
--- trunk/richfaces/common/src/main/java/org/richfaces/renderkit/html/BaseGradient.java 2007-04-11 20:13:32 UTC (rev 375)
+++ trunk/richfaces/common/src/main/java/org/richfaces/renderkit/html/BaseGradient.java 2007-04-11 20:16:30 UTC (rev 376)
@@ -157,25 +157,7 @@
return null;
}
}
- private Integer getDimensionValueParameter(FacesContext context, Object data, String name) {
- Skin skin = SkinFactory.getInstance().getSkin(context);
- String tmp = (String) skin.getParameter(context,name);
- if (tmp!=null) {
- return new Integer(HtmlDimensions.decode(tmp).intValue());
- } else {
- return null;
- }
- }
- private Integer getIntegerValueParameter(FacesContext context, Object data, String name) {
- Skin skin = SkinFactory.getInstance().getSkin(context);
- String tmp = (String) skin.getParameter(context,name);
- if (tmp!=null) {
- return new Integer(tmp);
- } else {
- return null;
- }
- }
-
+
/**
*
*/
Added: trunk/richfaces/common/src/test/java/org/richfaces/component/nsutils/NSUtilsTest.java
===================================================================
--- trunk/richfaces/common/src/test/java/org/richfaces/component/nsutils/NSUtilsTest.java (rev 0)
+++ trunk/richfaces/common/src/test/java/org/richfaces/component/nsutils/NSUtilsTest.java 2007-04-11 20:16:30 UTC (rev 376)
@@ -0,0 +1,64 @@
+/**
+ * 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.nsutils;
+
+import java.io.StringWriter;
+
+import javax.faces.component.UIInput;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.apache.shale.test.mock.MockResponseWriter;
+
+public class NSUtilsTest extends AbstractAjax4JsfTestCase {
+
+ public NSUtilsTest(String name) {
+ super(name);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testWriteNameSpace() throws Exception {
+ StringWriter stringWriter = new StringWriter();
+ facesContext.setResponseWriter(new MockResponseWriter(stringWriter, "text/html", "UTF8"));
+ ResponseWriter writer = facesContext.getResponseWriter();
+
+ UIInput input = new UIInput();
+
+ writer.startDocument();
+ writer.startElement("span", input);
+
+ NSUtils.writeNameSpace(facesContext, input);
+
+ writer.endElement("span");
+ writer.endDocument();
+
+ String result = stringWriter.getBuffer().toString();
+ assertTrue(result.contains("span xmlns:rich=\"http://richfaces.ajax4jsf.org/rich\""));
+ }
+}
Added: trunk/richfaces/common/src/test/java/org/richfaces/component/util/FormUtilTest.java
===================================================================
--- trunk/richfaces/common/src/test/java/org/richfaces/component/util/FormUtilTest.java (rev 0)
+++ trunk/richfaces/common/src/test/java/org/richfaces/component/util/FormUtilTest.java 2007-04-11 20:16:30 UTC (rev 376)
@@ -0,0 +1,88 @@
+/**
+ * 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.util;
+
+import java.util.List;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
+import javax.faces.component.UIOutput;
+import javax.faces.component.UIViewRoot;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.EnclosingFormRequiredException;
+
+/**
+ * @author Nick Belaevski - nbelaevski at exadel.com
+ * created 11.04.2007
+ *
+ */
+public class FormUtilTest extends AbstractAjax4JsfTestCase {
+
+ public FormUtilTest(String name) {
+ super(name);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testThrowEnclFormReqExceptionIfNeed() throws Exception {
+ UIViewRoot viewRoot = facesContext.getViewRoot();
+ UIComponent form = application.createComponent(UIForm.COMPONENT_TYPE);
+ viewRoot.getChildren().add(form);
+
+ UIComponent testComponent = application.createComponent(UIOutput.COMPONENT_TYPE);
+ form.getChildren().add(testComponent);
+
+ FormUtil.throwEnclFormReqExceptionIfNeed(facesContext, testComponent);
+ }
+
+ public void testThrowEnclFormReqExceptionIfNeedNoForm() throws Exception {
+ UIViewRoot viewRoot = facesContext.getViewRoot();
+
+ UIComponent testComponent = application.createComponent(UIOutput.COMPONENT_TYPE);
+ viewRoot.getChildren().add(testComponent);
+
+ try {
+ FormUtil.throwEnclFormReqExceptionIfNeed(facesContext, testComponent);
+
+ fail();
+ } catch (EnclosingFormRequiredException e) {
+
+ }
+ }
+
+ public void testThrowEnclFormReqExceptionIfNeedClient() throws Exception {
+ UIViewRoot viewRoot = facesContext.getViewRoot();
+
+ UIComponent testComponent = application.createComponent(UIOutput.COMPONENT_TYPE);
+ testComponent.getAttributes().put("switchType", "CLIENT");
+ viewRoot.getChildren().add(testComponent);
+
+ FormUtil.throwEnclFormReqExceptionIfNeed(facesContext, testComponent);
+ }
+}
Added: trunk/richfaces/common/src/test/java/org/richfaces/component/util/HtmlUtilTest.java
===================================================================
--- trunk/richfaces/common/src/test/java/org/richfaces/component/util/HtmlUtilTest.java (rev 0)
+++ trunk/richfaces/common/src/test/java/org/richfaces/component/util/HtmlUtilTest.java 2007-04-11 20:16:30 UTC (rev 376)
@@ -0,0 +1,51 @@
+/**
+ * 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.util;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Nick Belaevski - nbelaevski at exadel.com
+ * created 11.04.2007
+ *
+ */
+public class HtmlUtilTest extends TestCase {
+ public void testQualifySize() throws Exception {
+ assertEquals("", HtmlUtil.qualifySize(""));
+
+ assertEquals("100px", HtmlUtil.qualifySize("100px"));
+ assertEquals("100px", HtmlUtil.qualifySize("100"));
+ assertEquals("100pt", HtmlUtil.qualifySize("100pt"));
+
+ assertEquals("100in", HtmlUtil.qualifySize("100in"));
+ assertEquals("100cm", HtmlUtil.qualifySize("100cm"));
+ assertEquals("100em", HtmlUtil.qualifySize("100em"));
+ assertEquals("100%", HtmlUtil.qualifySize("100%"));
+ }
+
+ public void testAddToSize() throws Exception {
+ assertEquals("120px", HtmlUtil.addToSize("100", "20px"));
+ assertEquals("120px", HtmlUtil.addToSize("100px", "20"));
+ assertEquals("120px", HtmlUtil.addToSize("100", "20"));
+ assertEquals("120px", HtmlUtil.addToSize("100px", "20px"));
+ }
+}
Added: trunk/richfaces/common/src/test/java/org/richfaces/renderkit/CompositeRendererTest.java
===================================================================
--- trunk/richfaces/common/src/test/java/org/richfaces/renderkit/CompositeRendererTest.java (rev 0)
+++ trunk/richfaces/common/src/test/java/org/richfaces/renderkit/CompositeRendererTest.java 2007-04-11 20:16:30 UTC (rev 376)
@@ -0,0 +1,498 @@
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
+import javax.faces.component.UIInput;
+import javax.faces.component.UIOutput;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.framework.resource.InternetResource;
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.apache.shale.test.mock.MockFacesContext;
+import org.apache.shale.test.mock.MockResponseWriter;
+
+import junit.framework.TestCase;
+
+public class CompositeRendererTest extends AbstractAjax4JsfTestCase {
+
+ public CompositeRendererTest(String name) {
+ super(name);
+ }
+
+ private CompositeRenderer compositeRenderer;
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ this.compositeRenderer = new CompositeRenderer() {
+
+ protected Class getComponentClass() {
+ return UIComponent.class;
+ }
+ };
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ this.compositeRenderer = null;
+ }
+
+ public final void testDoDecodeFacesContextUIComponent() {
+ TestDecodeContributor[] contributors = new TestDecodeContributor[5];
+ for (int i = 0; i < contributors.length; i++) {
+ contributors[i] = new TestDecodeContributor();
+ compositeRenderer.addContributor(contributors[i]);
+ }
+
+ UIInput component = new UIInput();
+ compositeRenderer.doDecode(facesContext, component);
+
+ for (int i = 0; i < contributors.length; i++) {
+ assertSame(compositeRenderer, contributors[i].getRenderer());
+ assertSame(facesContext, contributors[i].getContext());
+ assertSame(component, contributors[i].getComponent());
+ }
+ }
+
+ public final void testMergeScriptOptionsScriptOptionsFacesContextUIComponent() {
+ UIInput input = new UIInput();
+
+ ScriptOptions inputOptions = new ScriptOptions(input);
+ inputOptions.addOption("input", "1");
+
+ ScriptOptions formOptions = new ScriptOptions(input);
+ formOptions.addOption("form", "2");
+
+ ScriptOptions options = new ScriptOptions(input);
+ options.addOption("generic", "3");
+
+ TestDecodeContributor inputContributor;
+ TestDecodeContributor formContributor;
+ TestDecodeContributor contributor;
+ TestDecodeContributor nullContributor;
+
+ inputContributor = new TestDecodeContributor(UIComponent.class, inputOptions);
+ formContributor = new TestDecodeContributor(UIComponent.class, formOptions);
+ contributor = new TestDecodeContributor(UIComponent.class, options);
+ nullContributor = new TestDecodeContributor(UIComponent.class, (ScriptOptions) null);
+
+ compositeRenderer.addContributor(contributor);
+ compositeRenderer.addContributor(formContributor);
+ compositeRenderer.addContributor(inputContributor);
+ compositeRenderer.addContributor(nullContributor);
+
+ ScriptOptions scriptOptions = new ScriptOptions(input);
+ compositeRenderer.mergeScriptOptions(scriptOptions, facesContext, input);
+ Map map = scriptOptions.getMap();
+
+ assertEquals(3, map.size());
+ assertEquals("1", map.get("input"));
+ assertEquals("2", map.get("form"));
+ assertEquals("3", map.get("generic"));
+ }
+
+ public final void testMergeScriptOptionsScriptOptionsFacesContextUIComponentClass() {
+ UIInput input = new UIInput();
+
+ ScriptOptions inputOptions = new ScriptOptions(input);
+ inputOptions.addOption("input", "1");
+
+ ScriptOptions formOptions = new ScriptOptions(input);
+ formOptions.addOption("form", "2");
+
+ ScriptOptions options = new ScriptOptions(input);
+ options.addOption("generic", "3");
+
+ TestDecodeContributor inputContributor;
+ TestDecodeContributor formContributor;
+ TestDecodeContributor contributor;
+ TestDecodeContributor nullContributor;
+
+ inputContributor = new TestDecodeContributor(UIInput.class, inputOptions);
+ formContributor = new TestDecodeContributor(NamingContainer.class, formOptions);
+ contributor = new TestDecodeContributor(UIComponent.class, options);
+ nullContributor = new TestDecodeContributor(UIForm.class, (ScriptOptions) null);
+
+ compositeRenderer.addContributor(contributor);
+ compositeRenderer.addContributor(formContributor);
+ compositeRenderer.addContributor(inputContributor);
+ compositeRenderer.addContributor(nullContributor);
+
+ ScriptOptions scriptOptions = new ScriptOptions(input);
+ compositeRenderer.mergeScriptOptions(scriptOptions, facesContext, input, UIForm.class);
+ Map map = scriptOptions.getMap();
+
+ assertEquals(2, map.size());
+ assertEquals("2", map.get("form"));
+ assertEquals("3", map.get("generic"));
+ }
+
+ public final void testGetScripts() {
+ TestDecodeContributor inputContributor;
+ TestDecodeContributor formContributor;
+ TestDecodeContributor contributor;
+
+ inputContributor = new TestDecodeContributor(UIComponent.class, new String[] { "input_script" }, null);
+ formContributor = new TestDecodeContributor(UIComponent.class, new String[] { "form_script" }, null);
+ contributor = new TestDecodeContributor(UIComponent.class, null, null);
+
+ compositeRenderer.addContributor(contributor);
+ compositeRenderer.addContributor(formContributor);
+ compositeRenderer.addContributor(inputContributor);
+
+ InternetResource[] scripts = compositeRenderer.getScripts();
+
+ assertEquals(2, scripts.length);
+
+ assertTrue(scripts[0].getKey().contains("org/richfaces/renderkit/form_script"));
+ assertTrue(scripts[1].getKey().contains("org/richfaces/renderkit/input_script"));
+ }
+
+ public final void testGetStyles() {
+ TestDecodeContributor inputContributor;
+ TestDecodeContributor formContributor;
+ TestDecodeContributor contributor;
+
+ inputContributor = new TestDecodeContributor(UIComponent.class, null, new String[] { "input_style" });
+ formContributor = new TestDecodeContributor(UIComponent.class, null, new String[] { "form_style" });
+ contributor = new TestDecodeContributor(UIComponent.class, null, null);
+
+ compositeRenderer.addContributor(contributor);
+ compositeRenderer.addContributor(inputContributor);
+ compositeRenderer.addContributor(formContributor);
+
+ InternetResource[] scripts = compositeRenderer.getStyles();
+
+ assertEquals(2, scripts.length);
+
+ assertTrue(scripts[0].getKey().contains("org/richfaces/renderkit/input_style"));
+ assertTrue(scripts[1].getKey().contains("org/richfaces/renderkit/form_style"));
+ }
+
+ public final void testGetScriptsClass() {
+ TestDecodeContributor inputContributor;
+ TestDecodeContributor formContributor;
+ TestDecodeContributor contributor;
+
+ inputContributor = new TestDecodeContributor(UIInput.class, new String[] { "input_script" }, null);
+ formContributor = new TestDecodeContributor(NamingContainer.class, new String[] { "form_script" }, null);
+ contributor = new TestDecodeContributor(UIComponent.class, null, null);
+
+ compositeRenderer.addContributor(contributor);
+ compositeRenderer.addContributor(formContributor);
+ compositeRenderer.addContributor(inputContributor);
+
+ InternetResource[] scripts = compositeRenderer.getScripts(UIInput.class);
+
+ assertEquals(1, scripts.length);
+
+ assertTrue(scripts[0].getKey().contains("org/richfaces/renderkit/input_script"));
+
+ scripts = compositeRenderer.getScripts(NamingContainer.class);
+
+ assertEquals(1, scripts.length);
+
+ assertTrue(scripts[0].getKey().contains("org/richfaces/renderkit/form_script"));
+
+ scripts = compositeRenderer.getStyles(String.class);
+ assertNull(scripts);
+ }
+
+ public final void testGetStylesClass() {
+ TestDecodeContributor inputContributor;
+ TestDecodeContributor formContributor;
+ TestDecodeContributor contributor;
+
+ inputContributor = new TestDecodeContributor(UIInput.class, null, new String[] { "input_style" });
+ formContributor = new TestDecodeContributor(NamingContainer.class, null, new String[] { "form_style" });
+ contributor = new TestDecodeContributor(UIComponent.class, null, null);
+
+ compositeRenderer.addContributor(contributor);
+ compositeRenderer.addContributor(formContributor);
+ compositeRenderer.addContributor(inputContributor);
+
+ InternetResource[] styles = compositeRenderer.getStyles(UIInput.class);
+
+ assertEquals(1, styles.length);
+
+ assertTrue(styles[0].getKey().contains("org/richfaces/renderkit/input_style"));
+
+ styles = compositeRenderer.getStyles(NamingContainer.class);
+
+ assertEquals(1, styles.length);
+ assertTrue(styles[0].getKey().contains("org/richfaces/renderkit/form_style"));
+
+ styles = compositeRenderer.getStyles(String.class);
+ assertNull(styles);
+ }
+
+ public final void testGetScriptContributionsStringFacesContextUIComponent() {
+ TestDecodeContributor inputContributor;
+ TestDecodeContributor formContributor;
+ TestDecodeContributor contributor;
+ TestDecodeContributor nullContributor;
+
+ inputContributor = new TestDecodeContributor(UIComponent.class, ".1;");
+ formContributor = new TestDecodeContributor(UIComponent.class, ".2;");
+ contributor = new TestDecodeContributor(UIComponent.class, ".3;");
+ nullContributor = new TestDecodeContributor(UIForm.class, (String) null);
+
+ compositeRenderer.addContributor(contributor);
+ compositeRenderer.addContributor(formContributor);
+ compositeRenderer.addContributor(inputContributor);
+ compositeRenderer.addContributor(nullContributor);
+
+ UIInput input = new UIInput();
+ input.getAttributes().put("test", ".testValue");
+
+ String contributions = compositeRenderer.getScriptContributions("theVar", facesContext, input);
+
+ assertEquals("theVar.testValue.3;theVar.testValue.2;theVar.testValue.1;", contributions);
+ }
+
+ public final void testGetScriptContributionsStringFacesContextUIComponentClass() {
+ TestDecodeContributor inputContributor;
+ TestDecodeContributor formContributor;
+ TestDecodeContributor contributor;
+ TestDecodeContributor nullContributor;
+
+ inputContributor = new TestDecodeContributor(UIInput.class, ".input;");
+ formContributor = new TestDecodeContributor(NamingContainer.class, ".namingContainer;");
+ contributor = new TestDecodeContributor(UIComponent.class, ".generic;");
+ nullContributor = new TestDecodeContributor(UIForm.class, (String) null);
+
+ compositeRenderer.addContributor(contributor);
+ compositeRenderer.addContributor(formContributor);
+ compositeRenderer.addContributor(inputContributor);
+ compositeRenderer.addContributor(nullContributor);
+
+ UIInput input = new UIInput();
+ input.getAttributes().put("test", ".testValue");
+
+ String contributions = compositeRenderer.getScriptContributions("theVar", facesContext, input,
+ UIForm.class);
+
+ assertEquals("theVar.testValue.generic;theVar.testValue.namingContainer;", contributions);
+ }
+
+ public final void testAddContributor() {
+ TestDecodeContributor[] contributors = new TestDecodeContributor[5];
+ for (int i = 0; i < contributors.length; i++) {
+ contributors[i] = new TestDecodeContributor();
+ compositeRenderer.addContributor(contributors[i]);
+ }
+
+ assertTrue(Arrays.deepEquals(contributors, compositeRenderer.getContributors()));
+ }
+
+ public final void testContributorDecodeCallback() {
+ TestDecodeContributor inputContributor;
+ TestDecodeContributor formContributor;
+
+ formContributor = new TestDecodeContributor(NamingContainer.class);
+ inputContributor = new TestDecodeContributor(UIInput.class);
+
+ compositeRenderer.addContributor(inputContributor);
+ compositeRenderer.addContributor(formContributor);
+
+ UIComponent component = new UIInput();
+ compositeRenderer.doDecode(facesContext, component);
+
+ assertSame(compositeRenderer, inputContributor.getRenderer());
+ assertSame(facesContext, inputContributor.getContext());
+ assertSame(component, inputContributor.getComponent());
+
+ assertNull(formContributor.getRenderer());
+ assertNull(formContributor.getContext());
+ assertNull(formContributor.getComponent());
+
+ inputContributor.reset();
+ formContributor.reset();
+
+ assertNull(inputContributor.getRenderer());
+ assertNull(inputContributor.getContext());
+ assertNull(inputContributor.getComponent());
+
+ assertNull(formContributor.getRenderer());
+ assertNull(formContributor.getContext());
+ assertNull(formContributor.getComponent());
+
+ component = new UIForm();
+ compositeRenderer.doDecode(facesContext, component);
+
+ assertSame(compositeRenderer, formContributor.getRenderer());
+ assertSame(facesContext, formContributor.getContext());
+ assertSame(component, formContributor.getComponent());
+
+ assertNull(inputContributor.getRenderer());
+ assertNull(inputContributor.getContext());
+ assertNull(inputContributor.getComponent());
+ }
+
+ public final void testAddParameterEncoder() {
+ TestAttributeParameterEncoder[] encoders = new TestAttributeParameterEncoder[5];
+ for (int i = 0; i < encoders.length; i++) {
+ encoders[i] = new TestAttributeParameterEncoder("aaa");
+ compositeRenderer.addParameterEncoder(encoders[i]);
+ }
+
+ assertTrue(Arrays.deepEquals(encoders, compositeRenderer.getParameterEncoders()));
+ }
+
+ public final void testEncodeAttributeParameters() throws IOException {
+
+ TestAttributeParameterEncoder encoder1 = new TestAttributeParameterEncoder("Attribute");
+ TestAttributeParameterEncoder encoder2 = new TestAttributeParameterEncoder("MoreAttribute");
+
+ compositeRenderer.addParameterEncoder(encoder1);
+ compositeRenderer.addParameterEncoder(encoder2);
+
+ UIInput input = new UIInput();
+ input.getAttributes().put("Attribute", "testValue1");
+ input.getAttributes().put("MoreAttribute", "testValue2");
+
+ //ResponseWriter responseWriter = facesContext.getResponseWriter();
+ StringWriter stringWriter = new StringWriter();
+ MockResponseWriter responseWriter = new MockResponseWriter(stringWriter, "text/html", "UTF8");
+ facesContext.setResponseWriter(responseWriter);
+
+ responseWriter.startDocument();
+ responseWriter.startElement("span", input);
+ compositeRenderer.encodeAttributeParameters(facesContext, input);
+ responseWriter.endElement("span");
+ responseWriter.endDocument();
+
+ responseWriter.flush();
+
+ String result = stringWriter.getBuffer().toString();
+ assertTrue(result.contains("testAttribute=\"testValue1\""));
+ assertTrue(result.contains("testMoreAttribute=\"testValue2\""));
+ }
+}
+
+class TestDecodeContributor implements RendererContributor {
+
+ private String[] scriptDependencies;
+ private String[] styleDependencies;
+
+ private String scriptContribution;
+
+ private Class componentClass;
+ private FacesContext context;
+ private UIComponent component;
+ private CompositeRenderer renderer;
+ private ScriptOptions options;
+
+ public TestDecodeContributor(Class componentClass, ScriptOptions options) {
+ super();
+
+ this.componentClass = componentClass;
+ this.options = options;
+ }
+
+ public TestDecodeContributor() {
+ this(UIComponent.class);
+ }
+
+ public TestDecodeContributor(Class componentClass) {
+ super();
+ this.componentClass = componentClass;
+ }
+
+ public TestDecodeContributor(Class componentClass, String scriptContribution) {
+ super();
+
+ this.componentClass = componentClass;
+ this.scriptContribution = scriptContribution;
+ }
+
+ public TestDecodeContributor(Class componentClass, String[] scriptDependencies,
+ String[] styleDependencies) {
+ super();
+
+ this.componentClass = componentClass;
+ this.scriptDependencies = scriptDependencies;
+ this.styleDependencies = styleDependencies;
+ }
+
+ public void decode(FacesContext context, UIComponent component,
+ CompositeRenderer compositeRenderer) {
+
+ this.component = component;
+ this.context = context;
+ this.renderer = compositeRenderer;
+ }
+
+ public Class getAcceptableClass() {
+ return componentClass;
+ }
+
+ public String getScriptContribution(FacesContext context,
+ UIComponent component) {
+ return scriptContribution != null ? component.getAttributes().get("test") + scriptContribution :
+ null;
+ }
+
+ public String[] getScriptDependencies() {
+ return scriptDependencies;
+ }
+
+ public String[] getStyleDependencies() {
+ return styleDependencies;
+ }
+
+ public ScriptOptions buildOptions(FacesContext context,
+ UIComponent component) {
+ return options;
+ }
+
+ public UIComponent getComponent() {
+ return component;
+ }
+
+ public FacesContext getContext() {
+ return context;
+ }
+
+ public CompositeRenderer getRenderer() {
+ return renderer;
+ }
+
+ public void reset() {
+ this.component = null;
+ this.context = null;
+ this.renderer = null;
+ }
+}
+
+class TestAttributeParameterEncoder implements AttributeParametersEncoder {
+
+ private String attributeName;
+
+ public TestAttributeParameterEncoder(String attributeName) {
+ super();
+ this.attributeName = attributeName;
+ }
+
+ public void doEncode(FacesContext context, UIComponent component)
+ throws IOException {
+
+ context.getResponseWriter().writeAttribute("test" + attributeName, component.getAttributes().get(attributeName)
+ , null);
+ }
+
+ public String doEncodeAsString(FacesContext context, UIComponent component)
+ throws IOException {
+ return "test" + attributeName + "=" + component.getAttributes().get(attributeName) + ";";
+ }
+
+}
Added: trunk/richfaces/common/src/test/resources/org/richfaces/renderkit/form_script
===================================================================
Added: trunk/richfaces/common/src/test/resources/org/richfaces/renderkit/form_style
===================================================================
Added: trunk/richfaces/common/src/test/resources/org/richfaces/renderkit/input_script
===================================================================
Added: trunk/richfaces/common/src/test/resources/org/richfaces/renderkit/input_style
===================================================================
Modified: trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeComponentTest.java
===================================================================
--- trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeComponentTest.java 2007-04-11 20:13:32 UTC (rev 375)
+++ trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeComponentTest.java 2007-04-11 20:16:30 UTC (rev 376)
@@ -22,8 +22,10 @@
package org.richfaces.component;
import java.io.IOException;
+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;
@@ -34,15 +36,21 @@
import javax.faces.component.html.HtmlForm;
import javax.faces.context.FacesContext;
+import org.ajax4jsf.dnd.DnDScript;
import org.ajax4jsf.framework.ViewHandlerWrapper;
+import org.ajax4jsf.framework.resource.PrototypeScript;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.apache.commons.lang.StringUtils;
import org.richfaces.component.xml.XmlTreeDataBuilder;
import org.xml.sax.InputSource;
import com.gargoylesoftware.htmlunit.KeyValuePair;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
+import com.gargoylesoftware.htmlunit.html.HtmlLink;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlScript;
+import com.gargoylesoftware.htmlunit.html.HtmlStyle;
/**
* Unit test for simple Component.
@@ -50,7 +58,36 @@
public class TreeComponentTest
extends AbstractAjax4JsfTestCase
{
- private UICommand command = null;
+ private static Set javaScripts = new HashSet();
+
+ static {
+ javaScripts.add("/org/richfaces/renderkit/html/scripts/json/json.js");
+ javaScripts.add("prototype.js");
+ javaScripts.add("dnd.js");
+ javaScripts.add("/org/richfaces/renderkit/html/scripts/dnd/dnd-common.js");
+ javaScripts.add("/org/richfaces/renderkit/html/scripts/dnd/dnd-draggable.js");
+ javaScripts.add("/org/richfaces/renderkit/html/scripts/dnd/dnd-dropzone.js");
+
+
+ javaScripts.add("/org/ajax4jsf/framework/ajax/scripts/AJAX.js");
+ javaScripts.add("/org/ajax4jsf/renderkit/html/scripts/form.js");
+ javaScripts.add("/org/richfaces/renderkit/html/scripts/events.js");
+ javaScripts.add("/org/richfaces/renderkit/html/scripts/tree.js");
+ javaScripts.add("/org/richfaces/renderkit/html/scripts/tree-selection.js");
+ javaScripts.add("/org/richfaces/renderkit/html/scripts/tree-item.js");
+ javaScripts.add("/org/richfaces/renderkit/html/scripts/tree-item-dnd.js");
+ javaScripts.add("/org/richfaces/renderkit/html/scripts/drag-indicator.js");
+
+ }
+
+ private static Set cssStyles = new HashSet();
+
+ static {
+ cssStyles.add("/org/richfaces/renderkit/html/css/dragIndicator.xcss");
+ cssStyles.add("/org/richfaces/renderkit/html/css/tree.xcss");
+ }
+
+ private UICommand command = null;
private UIInput input = null;
private UIForm form = null;
private UIComponent tree = null;
@@ -145,6 +182,54 @@
System.out.println(renderedView.getWebResponse().getContentAsString());
}
+ public void testRenderStyle() throws Exception {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ List styles = page.getDocumentElement().getHtmlElementsByTagName("link");
+ for (Iterator it = styles.iterator(); it.hasNext();) {
+ HtmlLink item = (HtmlLink) it.next();
+ String srcAttr = item.getHrefAttribute();
+
+ if (StringUtils.isNotBlank(srcAttr)) {
+ boolean found = false;
+ for (Iterator srcIt = cssStyles.iterator(); srcIt.hasNext();) {
+ String src = (String) srcIt.next();
+
+ found = srcAttr.contains(src);
+ if (found) {
+ break;
+ }
+ }
+
+ assertTrue(found);
+ }
+ }
+ }
+
+ 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 testProcess() {
}
}
More information about the richfaces-svn-commits
mailing list