[richfaces-svn-commits] JBoss Rich Faces SVN: r349 - in trunk/richfaces/separator/src: test/java/org/richfaces and 3 other directories.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Wed Apr 11 05:43:26 EDT 2007
Author: A.Skokov
Date: 2007-04-11 05:43:26 -0400 (Wed, 11 Apr 2007)
New Revision: 349
Added:
trunk/richfaces/separator/src/test/java/org/richfaces/renderkit/
trunk/richfaces/separator/src/test/java/org/richfaces/renderkit/html/
trunk/richfaces/separator/src/test/java/org/richfaces/renderkit/html/SeparatorRendererTest.java
Modified:
trunk/richfaces/separator/src/main/java/org/richfaces/renderkit/html/SeparatorRendererBase.java
trunk/richfaces/separator/src/test/java/org/richfaces/component/SeparatorComponentTest.java
Log:
test updated
Modified: trunk/richfaces/separator/src/main/java/org/richfaces/renderkit/html/SeparatorRendererBase.java
===================================================================
--- trunk/richfaces/separator/src/main/java/org/richfaces/renderkit/html/SeparatorRendererBase.java 2007-04-10 17:35:06 UTC (rev 348)
+++ trunk/richfaces/separator/src/main/java/org/richfaces/renderkit/html/SeparatorRendererBase.java 2007-04-11 09:43:26 UTC (rev 349)
@@ -22,91 +22,90 @@
package org.richfaces.renderkit.html;
-import java.io.IOException;
+import org.ajax4jsf.framework.renderer.RendererBase;
+import org.ajax4jsf.framework.util.HtmlDimensions;
+import org.richfaces.component.UISeparator;
+import org.richfaces.renderkit.html.images.BevelSeparatorImage;
+import org.richfaces.renderkit.html.images.SimpleSeparatorImage;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
+import java.io.IOException;
-import org.ajax4jsf.framework.renderer.RendererBase;
-import org.ajax4jsf.framework.util.HtmlDimensions;
+public class SeparatorRendererBase extends RendererBase {
-import org.richfaces.component.UISeparator;
-import org.richfaces.renderkit.html.images.BevelSeparatorImage;
-import org.richfaces.renderkit.html.images.SimpleSeparatorImage;
+ private static final String[] SUPPORTED_TYPES = {
+ UISeparator.LINE_TYPE_BEVEL,
+ UISeparator.LINE_TYPE_DASHED,
+ UISeparator.LINE_TYPE_DOTTED,
+ UISeparator.LINE_TYPE_DOUBLE,
+ UISeparator.LINE_TYPE_SOLID
+ };
-public class SeparatorRendererBase extends RendererBase {
-
- private static final String[] SUPPORTED_TYPES = {
- UISeparator.LINE_TYPE_BEVEL ,
- UISeparator.LINE_TYPE_DASHED,
- UISeparator.LINE_TYPE_DOTTED,
- UISeparator.LINE_TYPE_DOUBLE,
- UISeparator.LINE_TYPE_SOLID
- };
-
- private String getCSSDimension(UIComponent component, String attributeName, String defaultValue) {
- Object hO = component.getAttributes().get(attributeName);
- String height;
- if (hO == null) {
- height = defaultValue;
- } else if (hO instanceof String ) {
- height = (String) hO;
- if (height.trim().length() == 0) {
- height = defaultValue;
- }
- } else {
- height = hO.toString();
- }
- return getUtils().encodePctOrPx(height);
- }
-
- protected Class getComponentClass() {
- return UISeparator.class;
- }
+ private String getCSSDimension(UIComponent component, String attributeName, String defaultValue) {
+ Object hO = component.getAttributes().get(attributeName);
+ String height;
+ if (hO == null) {
+ height = defaultValue;
+ } else if (hO instanceof String) {
+ height = (String) hO;
+ if (height.trim().length() == 0) {
+ height = defaultValue;
+ }
+ } else {
+ height = hO.toString();
+ }
+ return getUtils().encodePctOrPx(height);
+ }
- public boolean getRendersChildren() {
- return true;
- }
-
- private boolean isSupportedLineType(String lineType) {
- for (int i = 0; i < SUPPORTED_TYPES.length; i++){
- if (lineType.equalsIgnoreCase(SUPPORTED_TYPES[i])) return true;
- }
- return false;
- }
+ protected Class getComponentClass() {
+ return UISeparator.class;
+ }
- public String backgroundImage(FacesContext context, UIComponent component) throws IOException {
- UISeparator separator = (UISeparator) component;
- String lineType = separator.getLineType();
- if (! isSupportedLineType(lineType)) {
- lineType = UISeparator.LINE_TYPE_BEVEL;
- }
- String height = getCSSDimension(component, "height", UISeparator.DEFAULT_HEIGHT);
- if (height.trim().endsWith("%")) throw new FacesException("It is not allowed to set height of separator in percent (component "+component.getId()+")!");
- int h = HtmlDimensions.decode(height).intValue();
-
- if(lineType == null || lineType.trim().length() == 0){
- lineType = UISeparator.LINE_TYPE_BEVEL;
- }
- //XXX by nick - fantonov - equalsIgnoreCase here?
- if(lineType.equalsIgnoreCase(UISeparator.LINE_TYPE_BEVEL) && h < 3 ){
- lineType = UISeparator.LINE_TYPE_SOLID;
- }
- String uri = null;
- if (lineType.equalsIgnoreCase(UISeparator.LINE_TYPE_BEVEL)) {
- uri = getResource(BevelSeparatorImage.class.getName()).getUri(context, component);
- } else {
- uri = getResource(SimpleSeparatorImage.class.getName()).getUri(context, component);
- }
- return uri;
- }
-
- public String getHeight(FacesContext context, UIComponent component) {
- return getCSSDimension(component, "height", UISeparator.DEFAULT_HEIGHT);
- }
+ public boolean getRendersChildren() {
+ return true;
+ }
- public String getWidth(FacesContext context, UIComponent component) {
- return getCSSDimension(component, "width", UISeparator.DEFAULT_WIDTH);
- }
+ protected boolean isSupportedLineType(String lineType) {
+ for (int i = 0; i < SUPPORTED_TYPES.length; i++) {
+ if (lineType.equalsIgnoreCase(SUPPORTED_TYPES[i])) return true;
+ }
+ return false;
+ }
+
+ public String backgroundImage(FacesContext context, UIComponent component) throws IOException {
+ UISeparator separator = (UISeparator) component;
+ String lineType = separator.getLineType();
+ if (! isSupportedLineType(lineType)) {
+ lineType = UISeparator.LINE_TYPE_BEVEL;
+ }
+ String height = getHeight(context, component);
+ if (height.trim().endsWith("%"))
+ throw new FacesException("It is not allowed to set height of separator in percent (component " + component.getId() + ")!");
+ int h = HtmlDimensions.decode(height).intValue();
+
+ if (lineType == null || lineType.trim().length() == 0) {
+ lineType = UISeparator.LINE_TYPE_BEVEL;
+ }
+ //XXX by nick - fantonov - equalsIgnoreCase here?
+ if (lineType.equalsIgnoreCase(UISeparator.LINE_TYPE_BEVEL) && h < 3) {
+ lineType = UISeparator.LINE_TYPE_SOLID;
+ }
+ String uri = null;
+ if (lineType.equalsIgnoreCase(UISeparator.LINE_TYPE_BEVEL)) {
+ uri = getResource(BevelSeparatorImage.class.getName()).getUri(context, component);
+ } else {
+ uri = getResource(SimpleSeparatorImage.class.getName()).getUri(context, component);
+ }
+ return uri;
+ }
+
+ public String getHeight(FacesContext context, UIComponent component) {
+ return getCSSDimension(component, "height", UISeparator.DEFAULT_HEIGHT);
+ }
+
+ public String getWidth(FacesContext context, UIComponent component) {
+ return getCSSDimension(component, "width", UISeparator.DEFAULT_WIDTH);
+ }
}
Modified: trunk/richfaces/separator/src/test/java/org/richfaces/component/SeparatorComponentTest.java
===================================================================
--- trunk/richfaces/separator/src/test/java/org/richfaces/component/SeparatorComponentTest.java 2007-04-10 17:35:06 UTC (rev 348)
+++ trunk/richfaces/separator/src/test/java/org/richfaces/component/SeparatorComponentTest.java 2007-04-11 09:43:26 UTC (rev 349)
@@ -24,6 +24,7 @@
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.renderkit.html.SeparatorRendererBase;
import javax.faces.component.UIComponent;
import javax.faces.component.UIOutput;
@@ -60,15 +61,15 @@
facesContext.getViewRoot().getChildren().add(form);
- out1 = (UIOutput)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
+ out1 = (UIOutput) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
out1.setValue("output1");
form.getChildren().add(out1);
- ui = (UISeparator)application.createComponent("org.richfaces.separator");
+ ui = (UISeparator) application.createComponent("org.richfaces.separator");
ui.setId("separator");
form.getChildren().add(ui);
- out2 = (UIOutput)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
+ out2 = (UIOutput) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
out2.setValue("output2");
form.getChildren().add(out2);
}
@@ -98,7 +99,7 @@
assertNotNull(div1);
assertEquals("div", div1.getNodeName());
- HtmlElement div2 = (HtmlElement)div1.getHtmlElementsByTagName("div").get(0);
+ HtmlElement div2 = (HtmlElement) div1.getHtmlElementsByTagName("div").get(0);
String classAttr = div2.getAttributeValue("class");
assertTrue(classAttr.contains("rich-separator"));
String styleAttr = div2.getAttributeValue("style");
Added: trunk/richfaces/separator/src/test/java/org/richfaces/renderkit/html/SeparatorRendererTest.java
===================================================================
--- trunk/richfaces/separator/src/test/java/org/richfaces/renderkit/html/SeparatorRendererTest.java (rev 0)
+++ trunk/richfaces/separator/src/test/java/org/richfaces/renderkit/html/SeparatorRendererTest.java 2007-04-11 09:43:26 UTC (rev 349)
@@ -0,0 +1,107 @@
+/**
+ * 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.renderkit.html;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.UISeparator;
+
+/**
+ * Unit test for SeparatorRenderer.
+ */
+public class SeparatorRendererTest extends AbstractAjax4JsfTestCase {
+
+ private static final String[] SUPPORTED_TYPES = {
+ UISeparator.LINE_TYPE_BEVEL,
+ UISeparator.LINE_TYPE_DASHED,
+ UISeparator.LINE_TYPE_DOTTED,
+ UISeparator.LINE_TYPE_DOUBLE,
+ UISeparator.LINE_TYPE_SOLID
+ };
+
+ private SeparatorRendererBase renderer;
+ private UISeparator ui;
+
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public SeparatorRendererTest(String testName) {
+ super(testName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+
+ renderer = new SeparatorRendererBase();
+ ui = (UISeparator) application.createComponent("org.richfaces.separator");
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ renderer = null;
+ ui = null;
+ }
+
+ public void testSupportedTypes() throws Exception {
+ for (int i = 0; i < SUPPORTED_TYPES.length; i++) {
+ assertEquals(true, renderer.isSupportedLineType(SUPPORTED_TYPES[i]));
+ }
+
+ boolean notSupported = renderer.isSupportedLineType("UNDEFINED");
+ assertFalse(notSupported);
+ }
+
+ public void testBackgroundImage() throws Exception {
+ assertEquals(UISeparator.LINE_TYPE_BEVEL, ui.getLineType());
+ ui.setLineType("UNDEFINED");
+ String uri = renderer.backgroundImage(facesContext, ui);
+ assertTrue(uri.contains("org.richfaces.renderkit.html.images.BevelSeparatorImage"));
+
+ ui.setLineType(UISeparator.LINE_TYPE_BEVEL);
+ uri = renderer.backgroundImage(facesContext, ui);
+ assertTrue(uri.contains("org.richfaces.renderkit.html.images.BevelSeparatorImage"));
+
+ ui.setLineType(UISeparator.LINE_TYPE_DOTTED);
+ uri = renderer.backgroundImage(facesContext, ui);
+ assertTrue(uri.contains("org.richfaces.renderkit.html.images.SimpleSeparatorImage"));
+
+ ui.setLineType(UISeparator.LINE_TYPE_BEVEL);
+ ui.setHeight("10%");
+ try {
+ uri = renderer.backgroundImage(facesContext, ui);
+ assertTrue(false);
+ } catch(Exception ex) {
+ }
+
+ ui.setLineType(UISeparator.LINE_TYPE_BEVEL);
+ ui.setHeight("2");
+ assertTrue(uri.contains("org.richfaces.renderkit.html.images.SimpleSeparatorImage"));
+ }
+}
More information about the richfaces-svn-commits
mailing list