Author: nbelaevski
Date: 2010-02-11 15:54:15 -0500 (Thu, 11 Feb 2010)
New Revision: 16445
Added:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/pom.xml
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/java/
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/java/org/
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/java/org/richfaces/
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/java/org/richfaces/cdk/
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/java/org/richfaces/cdk/renderkit/
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/java/org/richfaces/cdk/renderkit/AbstractGridRenderer.java
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/grid.template.xml
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/input.template.xml
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/link.template.xml
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/BaseRendererTest.java
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/GridRendererTest.java
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/HtmlOutputTextStub.java
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/InputRendererTest.java
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/LinkRendererTest.java
Log:
https://jira.jboss.org/jira/browse/RF-8307
Property changes on:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test
___________________________________________________________________
Name: svn:ignore
+ .classpath
.project
.settings
target
Added: root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/pom.xml
===================================================================
--- root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/pom.xml
(rev 0)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/pom.xml 2010-02-11
20:54:15 UTC (rev 16445)
@@ -0,0 +1,88 @@
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>renderer-template-test</artifactId>
+ <name>Test for renderer templates compilation</name>
+ <version>0.0.1-SNAPSHOT</version>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>maven-cdk-plugin</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ <configuration>
+ </configuration>
+ <executions>
+ <execution>
+ <id>generate</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ <inherited>false</inherited>
+ <configuration>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <!--
http://maven.apache.org/plugins/maven-compiler-plugin/ -->
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>**/BaseRendererTest.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.7</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>jsf-mock</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.5.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.faces</groupId>
+ <artifactId>jsf-api</artifactId>
+ <version>2.0.2</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>annotations</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.richfaces.framework</groupId>
+ <artifactId>richfaces-commons</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ <version>1.2</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Added:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/java/org/richfaces/cdk/renderkit/AbstractGridRenderer.java
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/java/org/richfaces/cdk/renderkit/AbstractGridRenderer.java
(rev 0)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/java/org/richfaces/cdk/renderkit/AbstractGridRenderer.java 2010-02-11
20:54:15 UTC (rev 16445)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.cdk.renderkit;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.Renderer;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class AbstractGridRenderer extends Renderer {
+
+ /**
+ * @param facesContext
+ * @param child
+ */
+ protected void renderChild(FacesContext facesContext, UIComponent child) throws
IOException {
+ ResponseWriter responseWriter = facesContext.getResponseWriter();
+
+ responseWriter.startElement("div", child);
+ child.encodeAll(facesContext);
+ responseWriter.endElement("div");
+ }
+
+}
Added:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/grid.template.xml
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/grid.template.xml
(rev 0)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/grid.template.xml 2010-02-11
20:54:15 UTC (rev 16445)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<cdk:root
xmlns="http://richfaces.org/cdk/xhtml-el"
xmlns:cdk="http://richfaces.org/cdk/core"
+
xmlns:c="http://richfaces.org/cdk/jstl/core"
xmlns:cc="http://richfaces.org/cdk/jsf/composite"
+
xmlns:javaee="http://java.sun.com/xml/ns/javaee">
+
+ <cc:interface>
+ <cdk:class>org.richfaces.cdk.renderkit.html.GridRenderer</cdk:class>
+ <cdk:superclass>org.richfaces.cdk.renderkit.AbstractGridRenderer</cdk:superclass>
+ <cdk:component-family>org.richfaces.cdk.Grid</cdk:component-family>
+ <cdk:renderer-type>org.richfaces.cdk.GridRenderer</cdk:renderer-type>
+ </cc:interface>
+
+ <cc:implementation>
+ <table id="#{clientId}">
+ <tbody>
+ <cdk:body>
+ <c:forEach items="#{cc.children}" var="child">
+ <tr>
+ <td>
+ <cdk:call>
+ <![CDATA[
+ renderChild(facesContext, child)
+ ]]>
+ </cdk:call>
+ </td>
+ </tr>
+ </c:forEach>
+ </cdk:body>
+ </tbody>
+ </table>
+ </cc:implementation>
+</cdk:root>
Added:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/input.template.xml
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/input.template.xml
(rev 0)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/input.template.xml 2010-02-11
20:54:15 UTC (rev 16445)
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<cdk:root
xmlns="http://richfaces.org/cdk/xhtml-el"
xmlns:cdk="http://richfaces.org/cdk/core"
+
xmlns:c="http://richfaces.org/cdk/jstl/core"
xmlns:cc="http://richfaces.org/cdk/jsf/composite"
+
xmlns:javaee="http://java.sun.com/xml/ns/javaee">
+
+ <cc:interface>
+ <cdk:class>org.richfaces.cdk.renderkit.html.InputRenderer</cdk:class>
+ <cdk:component-family>org.richfaces.cdk.Input</cdk:component-family>
+ <cdk:renderer-type>org.richfaces.cdk.InputRenderer</cdk:renderer-type>
+ </cc:interface>
+
+ <cc:implementation>
+ <span id="#{clientId}">
+ <cdk:body />
+
+ <cdk:object name="componentIsDisabled"
value="#{cc.attributes['disabled'] == true}" />
+ <c:choose>
+ <c:when test="#{not componentIsDisabled}">
+ <input type="text" />
+
+ <cdk:object name="image"
value="#{cc.attributes['image']}" />
+ <cdk:object name="disabledImage"
value="#{cc.attributes['disabledImage']}" />
+ <c:choose>
+ <c:when test="#{disabledImage != null}">
+ <img src="#{disabledImage}" alt="" />
+ </c:when>
+ <c:when test="#{image != null}">
+ <img src="#{image}" alt=""
onclick="alert('clicked')" />
+ </c:when>
+ <c:otherwise>
+ No image defined
+ </c:otherwise>
+ </c:choose>
+ </c:when>
+ <c:otherwise>
+ <input type="text" disabled="#{true}" />
+ </c:otherwise>
+ </c:choose>
+ </span>
+ </cc:implementation>
+</cdk:root>
Added:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/link.template.xml
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/link.template.xml
(rev 0)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/link.template.xml 2010-02-11
20:54:15 UTC (rev 16445)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<cdk:root
xmlns="http://richfaces.org/cdk/xhtml-el"
xmlns:cdk="http://richfaces.org/cdk/core"
+
xmlns:c="http://richfaces.org/cdk/jstl/core"
xmlns:cc="http://richfaces.org/cdk/jsf/composite"
+
xmlns:javaee="http://java.sun.com/xml/ns/javaee">
+
+ <cc:interface>
+ <cdk:class>org.richfaces.cdk.renderkit.html.CommandLinkRenderer</cdk:class>
+ <cdk:component-family>org.richfaces.cdk.Link</cdk:component-family>
+ <cdk:renderer-type>org.richfaces.cdk.LinkRenderer</cdk:renderer-type>
+ </cc:interface>
+
+ <cc:implementation>
+ <a id="#{clientId}" href="#{cc.attributes['href']}"
cdk:passThroughWithExclusions="target rel rev">
+ <cdk:object name="imageSource"
value="#{cc.attributes['imageSource']}" />
+ <c:if test="#{not empty imageSource}">
+ <img src="#{imageSource}" alt="" class="rich-link
#{cc.attributes['linkImageStyleClass']}
#{cc.attributes['imageStyleClass']}" />
+ </c:if>
+ value: #{cc.attributes['value']}; differentValue:
#{cc.attributes['differentValue']}; anotherValue:
#{cc.attributes['anotherValue']};
+ </a>
+ </cc:implementation>
+</cdk:root>
Added:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/BaseRendererTest.java
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/BaseRendererTest.java
(rev 0)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/BaseRendererTest.java 2010-02-11
20:54:15 UTC (rev 16445)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.same;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.easymock.IAnswer;
+import org.jboss.test.faces.mock.FacesMock;
+import org.jboss.test.faces.mock.MockFacesEnvironment;
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class BaseRendererTest {
+
+ protected final String CLIENT_ID = "mainForm:personEntry";
+
+ protected MockFacesEnvironment environment;
+
+ protected ResponseWriter responseWriter;
+
+ protected FacesContext facesContext;
+
+ protected UIComponent component;
+
+ protected Map<String, Object> componentAttributes;
+
+ protected List<UIComponent> childrenList;
+
+ protected void replayAll() throws Exception {
+ FacesMock.replay(environment, responseWriter, component);
+ }
+
+ protected void verifyAll() throws Exception {
+ FacesMock.verify(environment, responseWriter, component);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ environment = MockFacesEnvironment.createEnvironment();
+ facesContext = environment.getFacesContext();
+ component = FacesMock.createMock(UIComponent.class);
+
+ componentAttributes = new HashMap<String, Object>();
+ expect(component.getAttributes()).andStubReturn(componentAttributes);
+
+
expect(component.getClientId(same(environment.getFacesContext()))).andStubReturn(CLIENT_ID);
+
+ childrenList = new ArrayList<UIComponent>();
+ expect(component.getChildCount()).andAnswer(new IAnswer<Integer>() {
+ @Override
+ public Integer answer() throws Throwable {
+ return childrenList.size();
+ }
+ }).anyTimes();
+ expect(component.getChildren()).andStubReturn(childrenList);
+
+ responseWriter = FacesMock.createMock(ResponseWriter.class);
+
expect(environment.getFacesContext().getResponseWriter()).andStubReturn(responseWriter);
+ expect(responseWriter.getContentType()).andStubReturn("text/html");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ verifyAll();
+
+ environment.release();
+ environment = null;
+
+ responseWriter = null;
+ facesContext = null;
+ component = null;
+ componentAttributes = null;
+ childrenList = null;
+ }
+
+}
Added:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/GridRendererTest.java
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/GridRendererTest.java
(rev 0)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/GridRendererTest.java 2010-02-11
20:54:15 UTC (rev 16445)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk;
+
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.same;
+
+import javax.faces.component.UIComponent;
+
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+import org.richfaces.cdk.renderkit.html.GridRenderer;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class GridRendererTest extends BaseRendererTest {
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ childrenList.add(new HtmlOutputTextStub("First child"));
+ childrenList.add(new HtmlOutputTextStub("Second child"));
+ }
+
+ @Test
+ public void testEncodeBegin() throws Exception {
+ responseWriter.startElement(eq("table"), same(component));
+ responseWriter.writeAttribute(eq("id"), eq(CLIENT_ID),
EasyMock.<String>isNull());
+ responseWriter.startElement(eq("tbody"), same(component));
+
+ replayAll();
+
+ GridRenderer renderer = new GridRenderer();
+ renderer.encodeBegin(facesContext, component);
+ }
+
+ @Test
+ public void testEncodeChildren() throws Exception {
+ responseWriter.startElement(eq("tr"),
EasyMock.<UIComponent>notNull());
+ responseWriter.startElement(eq("td"),
EasyMock.<UIComponent>notNull());
+
+ responseWriter.startElement(eq("div"),
EasyMock.<UIComponent>notNull());
+ responseWriter.writeText(eq("First child"),
EasyMock.<String>isNull());
+ responseWriter.endElement(eq("div"));
+
+ responseWriter.endElement(eq("td"));
+ responseWriter.endElement(eq("tr"));
+
+
+ responseWriter.startElement(eq("tr"),
EasyMock.<UIComponent>notNull());
+ responseWriter.startElement(eq("td"),
EasyMock.<UIComponent>notNull());
+
+ responseWriter.startElement(eq("div"),
EasyMock.<UIComponent>notNull());
+ responseWriter.writeText(eq("Second child"),
EasyMock.<String>isNull());
+ responseWriter.endElement(eq("div"));
+
+ responseWriter.endElement(eq("td"));
+ responseWriter.endElement(eq("tr"));
+
+ replayAll();
+
+ GridRenderer renderer = new GridRenderer();
+ renderer.encodeChildren(facesContext, component);
+ }
+
+ @Test
+ public void testEncodeEnd() throws Exception {
+ responseWriter.endElement(eq("tbody"));
+ responseWriter.endElement(eq("table"));
+
+ replayAll();
+
+ GridRenderer renderer = new GridRenderer();
+ renderer.encodeEnd(facesContext, component);
+ }
+
+}
\ No newline at end of file
Added:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/HtmlOutputTextStub.java
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/HtmlOutputTextStub.java
(rev 0)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/HtmlOutputTextStub.java 2010-02-11
20:54:15 UTC (rev 16445)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+
+class HtmlOutputTextStub extends UIComponentBase {
+
+ private String prologText = "";
+ private String bodyText = "";
+ private String epilogText = "";
+
+ public HtmlOutputTextStub() {
+ super();
+ }
+
+ public HtmlOutputTextStub(String epilogText) {
+ super();
+ this.epilogText = epilogText;
+ }
+
+ @Override
+ public String getFamily() {
+ return javax.faces.component.html.HtmlOutputText.COMPONENT_FAMILY;
+ }
+
+ private void renderText(FacesContext facesContext, String text) throws IOException {
+ if (text != null && text.length() > 0) {
+ facesContext.getResponseWriter().writeText(text, null);
+ }
+ }
+
+ @Override
+ public boolean getRendersChildren() {
+ return true;
+ }
+
+ @Override
+ public void encodeBegin(FacesContext context) throws IOException {
+ renderText(context, prologText);
+ }
+
+ @Override
+ public void encodeChildren(FacesContext context) throws IOException {
+ renderText(context, bodyText);
+ }
+
+ @Override
+ public void encodeEnd(FacesContext context) throws IOException {
+ renderText(context, epilogText);
+ }
+
+ public void setBodyText(String bodyText) {
+ this.bodyText = bodyText;
+ }
+
+ public void setPrologText(String prologText) {
+ this.prologText = prologText;
+ }
+
+ public void setEpilogText(String epilogText) {
+ this.epilogText = epilogText;
+ }
+
+ public String getBodyText() {
+ return bodyText;
+ }
+
+ public String getPrologText() {
+ return prologText;
+ }
+
+ public String getEpilogText() {
+ return epilogText;
+ }
+}
\ No newline at end of file
Added:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/InputRendererTest.java
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/InputRendererTest.java
(rev 0)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/InputRendererTest.java 2010-02-11
20:54:15 UTC (rev 16445)
@@ -0,0 +1,143 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk;
+
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.same;
+
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+import org.richfaces.cdk.renderkit.html.InputRenderer;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class InputRendererTest extends BaseRendererTest {
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ childrenList.add(new HtmlOutputTextStub("Single child"));
+ }
+
+ @Test
+ public void testEncodeBeginDefaultComponent() throws Exception {
+ responseWriter.startElement(eq("span"), same(component));
+ responseWriter.writeAttribute(eq("id"), eq(CLIENT_ID),
EasyMock.<String>isNull());
+
+ replayAll();
+
+ InputRenderer renderer = new InputRenderer();
+ renderer.encodeBegin(facesContext, component);
+ }
+
+ @Test
+ public void testEncodeChildrenDefaultComponent() throws Exception {
+ responseWriter.writeText(eq("Single child"),
EasyMock.<String>isNull());
+
+ replayAll();
+
+ InputRenderer renderer = new InputRenderer();
+ renderer.encodeChildren(facesContext, component);
+ }
+
+
+ @Test
+ public void testEncodeEndDefaultComponent() throws Exception {
+ responseWriter.startElement(eq("input"), same(component));
+ responseWriter.writeAttribute(eq("type"), eq("text"),
EasyMock.<String>isNull());
+ responseWriter.endElement(eq("input"));
+
+ responseWriter.writeText(eq("No image defined"),
EasyMock.<String>isNull());
+
+ responseWriter.endElement(eq("span"));
+
+ replayAll();
+
+ InputRenderer renderer = new InputRenderer();
+ renderer.encodeEnd(facesContext, component);
+ }
+
+ @Test
+ public void testEncodeEndDisabledComponent() throws Exception {
+ componentAttributes.put("disabled", Boolean.TRUE);
+
+ responseWriter.startElement(eq("input"), same(component));
+ responseWriter.writeAttribute(eq("disabled"), eq(Boolean.TRUE),
EasyMock.<String>isNull());
+ responseWriter.writeAttribute(eq("type"), eq("text"),
EasyMock.<String>isNull());
+ responseWriter.endElement(eq("input"));
+
+ responseWriter.endElement(eq("span"));
+
+ replayAll();
+
+ InputRenderer renderer = new InputRenderer();
+ renderer.encodeEnd(facesContext, component);
+ }
+
+ @Test
+ public void testEncodeEndDisabledImage() throws Exception {
+ componentAttributes.put("image", "http://site/img.png");
+ componentAttributes.put("disabledImage",
"http://site/disabled.png");
+
+ responseWriter.startElement(eq("input"), same(component));
+ responseWriter.writeAttribute(eq("type"), eq("text"),
EasyMock.<String>isNull());
+ responseWriter.endElement(eq("input"));
+
+ responseWriter.startElement(eq("img"), same(component));
+ responseWriter.writeAttribute(eq("alt"), eq(""),
EasyMock.<String>isNull());
+ responseWriter.writeURIAttribute(eq("src"),
eq("http://site/disabled.png"), EasyMock.<String>isNull());
+ responseWriter.endElement(eq("img"));
+
+ responseWriter.endElement(eq("span"));
+
+ replayAll();
+
+ InputRenderer renderer = new InputRenderer();
+ renderer.encodeEnd(facesContext, component);
+ }
+
+ @Test
+ public void testEncodeEndImage() throws Exception {
+ componentAttributes.put("image", "http://site/img.png");
+
+ responseWriter.startElement(eq("input"), same(component));
+ responseWriter.writeAttribute(eq("type"), eq("text"),
EasyMock.<String>isNull());
+ responseWriter.endElement(eq("input"));
+
+ responseWriter.startElement(eq("img"), same(component));
+ responseWriter.writeAttribute(eq("alt"), eq(""),
EasyMock.<String>isNull());
+ responseWriter.writeAttribute(eq("onclick"),
eq("alert('clicked')"), EasyMock.<String>isNull());
+ responseWriter.writeURIAttribute(eq("src"),
eq("http://site/img.png"), EasyMock.<String>isNull());
+ responseWriter.endElement(eq("img"));
+
+ responseWriter.endElement(eq("span"));
+
+ replayAll();
+
+ InputRenderer renderer = new InputRenderer();
+ renderer.encodeEnd(facesContext, component);
+ }
+}
\ No newline at end of file
Added:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/LinkRendererTest.java
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/LinkRendererTest.java
(rev 0)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/LinkRendererTest.java 2010-02-11
20:54:15 UTC (rev 16445)
@@ -0,0 +1,145 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk;
+
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.same;
+
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+import org.richfaces.cdk.renderkit.html.CommandLinkRenderer;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class LinkRendererTest extends BaseRendererTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ childrenList.add(new HtmlOutputTextStub("Child text"));
+ }
+
+ private void initializeBasePathAttributes() {
+ componentAttributes.put("href", "http://some-site");
+ componentAttributes.put("value", "The link");
+ componentAttributes.put("anotherValue", Integer.valueOf(12));
+ componentAttributes.put("styleClass", "menu-link");
+ componentAttributes.put("onclick",
"this.disabled='true'");
+ componentAttributes.put("target", "_blank");
+ componentAttributes.put("rel", "Next");
+ componentAttributes.put("rev", "Prev");
+ componentAttributes.put("imageSource",
"http://some-site/img.png");
+ componentAttributes.put("imageStyleClass", "my-link-image");
+ }
+
+ @Test
+ public void testEncodeBeginBasePath() throws Exception {
+ initializeBasePathAttributes();
+
+ replayAll();
+
+ CommandLinkRenderer renderer = new CommandLinkRenderer();
+ renderer.encodeBegin(facesContext, component);
+ }
+
+ @Test
+ public void testEncodeChildrenBasePath() throws Exception {
+ initializeBasePathAttributes();
+
+ responseWriter.writeText(eq("Child text"),
EasyMock.<String>isNull());
+
+ replayAll();
+
+ CommandLinkRenderer renderer = new CommandLinkRenderer();
+ renderer.encodeChildren(facesContext, component);
+ }
+
+ @Test
+ public void testEncodeEndBasePath() throws Exception {
+ initializeBasePathAttributes();
+
+ responseWriter.startElement(eq("a"), same(component));
+
+ //attributes
+ responseWriter.writeAttribute(eq("id"), eq(CLIENT_ID),
EasyMock.<String>isNull());
+ responseWriter.writeURIAttribute(eq("href"),
eq("http://some-site"), EasyMock.<String>isNull());
+
+ //pass-through attributes
+ responseWriter.writeAttribute(eq("class"), eq("menu-link"),
EasyMock.<String>isNull());
+ responseWriter.writeAttribute(eq("onclick"),
eq("this.disabled='true'"), EasyMock.<String>isNull());
+
+ responseWriter.startElement(eq("img"), same(component));
+ responseWriter.writeAttribute(eq("alt"), eq(""),
EasyMock.<String>isNull());
+ responseWriter.writeAttribute(eq("class"), eq("rich-link
my-link-image"), EasyMock.<String>isNull());
+ responseWriter.writeURIAttribute(eq("src"),
eq("http://some-site/img.png"), EasyMock.<String>isNull());
+ responseWriter.endElement(eq("img"));
+
+ responseWriter.writeText(eq("value: The link; differentValue: ;
anotherValue: 12;"), EasyMock.<String>isNull());
+
+ responseWriter.endElement(eq("a"));
+
+ replayAll();
+
+ CommandLinkRenderer renderer = new CommandLinkRenderer();
+ renderer.encodeEnd(facesContext, component);
+ }
+
+ @Test
+ public void testEncodeBeginShortPath() throws Exception {
+ replayAll();
+
+ CommandLinkRenderer renderer = new CommandLinkRenderer();
+ renderer.encodeBegin(facesContext, component);
+ }
+
+ @Test
+ public void testEncodeChildrenShortPath() throws Exception {
+ responseWriter.writeText(eq("Child text"),
EasyMock.<String>isNull());
+
+ replayAll();
+
+ CommandLinkRenderer renderer = new CommandLinkRenderer();
+ renderer.encodeChildren(facesContext, component);
+ }
+
+ @Test
+ public void testEncodeEndShortPath() throws Exception {
+ responseWriter.startElement(eq("a"), same(component));
+
+ //attributes
+ responseWriter.writeAttribute(eq("id"), eq(CLIENT_ID),
EasyMock.<String>isNull());
+
+ responseWriter.writeText(eq("value: ; differentValue: ; anotherValue:
;"), EasyMock.<String>isNull());
+ responseWriter.endElement(eq("a"));
+
+ replayAll();
+
+ CommandLinkRenderer renderer = new CommandLinkRenderer();
+ renderer.encodeEnd(facesContext, component);
+ }
+}
\ No newline at end of file