Author: alexsmirnov
Date: 2010-10-26 22:02:21 -0400 (Tue, 26 Oct 2010)
New Revision: 19679
Added:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/TestBean.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/TestScript.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/UIValidatorScriptCollectionTest.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/UIViewResourceTest.java
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/component/
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/component/faces-config.xml
Modified:
branches/RF-8742/ui/validator/api/pom.xml
branches/RF-8742/ui/validator/impl/pom.xml
branches/RF-8742/ui/validator/ui/pom.xml
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIValidatorScript.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScript.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptString.java
Log:
Incomplete - issue RF-9508: UIValidatorScript component test and implementation
https://jira.jboss.org/browse/RF-9508
Modified: branches/RF-8742/ui/validator/api/pom.xml
===================================================================
--- branches/RF-8742/ui/validator/api/pom.xml 2010-10-27 01:21:13 UTC (rev 19678)
+++ branches/RF-8742/ui/validator/api/pom.xml 2010-10-27 02:02:21 UTC (rev 19679)
@@ -64,6 +64,12 @@
<version>1.0.5-SNAPSHOT</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>jsf-test-stage</artifactId>
+ <version>1.0.5-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<scm>
Modified: branches/RF-8742/ui/validator/impl/pom.xml
===================================================================
--- branches/RF-8742/ui/validator/impl/pom.xml 2010-10-27 01:21:13 UTC (rev 19678)
+++ branches/RF-8742/ui/validator/impl/pom.xml 2010-10-27 02:02:21 UTC (rev 19679)
@@ -77,6 +77,13 @@
<version>1.0.5-SNAPSHOT</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>jsf-test-stage</artifactId>
+ <version>1.0.5-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
<scm>
Modified: branches/RF-8742/ui/validator/ui/pom.xml
===================================================================
--- branches/RF-8742/ui/validator/ui/pom.xml 2010-10-27 01:21:13 UTC (rev 19678)
+++ branches/RF-8742/ui/validator/ui/pom.xml 2010-10-27 02:02:21 UTC (rev 19679)
@@ -106,6 +106,12 @@
<version>1.0.5-SNAPSHOT</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>jsf-test-stage</artifactId>
+ <version>1.0.5-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
Modified:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIValidatorScript.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIValidatorScript.java 2010-10-27
01:21:13 UTC (rev 19678)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIValidatorScript.java 2010-10-27
02:02:21 UTC (rev 19679)
@@ -290,8 +290,10 @@
@Override
public void encodeEnd(FacesContext context) throws IOException {
- // TODO Auto-generated method stub
-
+ Renderer renderer = getRenderer(context);
+ if(null != renderer){
+ renderer.encodeEnd(context, this);
+ }
}
@Override
Modified:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java 2010-10-27
01:21:13 UTC (rev 19678)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java 2010-10-27
02:02:21 UTC (rev 19679)
@@ -24,4 +24,41 @@
protected Object buildBody() {
return ajaxScript;
}
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((ajaxScript == null) ? 0 : ajaxScript.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ AjaxOnlyScript other = (AjaxOnlyScript) obj;
+ if (ajaxScript == null) {
+ if (other.ajaxScript != null) {
+ return false;
+ }
+ } else if (!ajaxScript.equals(other.ajaxScript)) {
+ return false;
+ }
+ return true;
+ }
+
}
Modified:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2010-10-27
01:21:13 UTC (rev 19678)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2010-10-27
02:02:21 UTC (rev 19679)
@@ -63,5 +63,49 @@
body.append(EOL).append("}\n");
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((converter == null) ? 0 : converter.hashCode());
+ result = prime * result + ((validators == null) ? 0 : validators.hashCode());
+ return result;
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ClientOnlyScript other = (ClientOnlyScript) obj;
+ if (converter == null) {
+ if (other.converter != null) {
+ return false;
+ }
+ } else if (!converter.equals(other.converter)) {
+ return false;
+ }
+ if (validators == null) {
+ if (other.validators != null) {
+ return false;
+ }
+ } else if (!validators.equals(other.validators)) {
+ return false;
+ }
+ return true;
+ }
+
+
}
Modified:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScript.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScript.java 2010-10-27
01:21:13 UTC (rev 19678)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScript.java 2010-10-27
02:02:21 UTC (rev 19679)
@@ -8,6 +8,6 @@
* <p class="changed_added_4_0"></p>
* @return the resourceName
*/
- public abstract LibraryResource getResource();
+ LibraryResource getResource();
}
\ No newline at end of file
Modified:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java 2010-10-27
01:21:13 UTC (rev 19678)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java 2010-10-27
02:02:21 UTC (rev 19679)
@@ -35,10 +35,12 @@
public class LibraryScriptFunction extends JSFunction implements LibraryScriptString {
private final LibraryResource resource;
+ private String name;
public LibraryScriptFunction(LibraryScript libraryScript, Object... parameters) {
super(libraryScript.getName(), parameters);
this.resource = libraryScript.getResource();
+ name = libraryScript.getName();
}
/* (non-Javadoc)
@@ -48,6 +50,57 @@
return resource;
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((resource == null) ? 0 : resource.hashCode());
+ result = prime * result + getParameters().hashCode();
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ LibraryScriptFunction other = (LibraryScriptFunction) obj;
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ if (resource == null) {
+ if (other.resource != null) {
+ return false;
+ }
+ } else if (!resource.equals(other.resource)) {
+ return false;
+ } else if (!getParameters().equals(other.getParameters())){
+ return false;
+ }
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+
}
Modified:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptString.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptString.java 2010-10-27
01:21:13 UTC (rev 19678)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptString.java 2010-10-27
02:02:21 UTC (rev 19679)
@@ -1,19 +1,13 @@
package org.richfaces.renderkit.html;
import org.ajax4jsf.javascript.ScriptString;
-import org.richfaces.validator.LibraryResource;
/**
* This interface describes JavaScript object with possible dependent resource.
* @author asmirnov
*
*/
-public interface LibraryScriptString extends ScriptString {
+public interface LibraryScriptString extends LibraryScript, ScriptString {
- /**
- * <p class="changed_added_4_0"></p>
- * @return the resource
- */
- LibraryResource getResource();
}
\ No newline at end of file
Added:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/TestBean.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/TestBean.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/TestBean.java 2010-10-27
02:02:21 UTC (rev 19679)
@@ -0,0 +1,32 @@
+/**
+ *
+ */
+package org.richfaces.component;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class TestBean {
+
+ public static final String FOO_VALUE = "fooValue";
+
+ private String value=FOO_VALUE;
+
+ /**
+ * @return the value
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * @param value the value to set
+ */
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+
+
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/TestBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/TestScript.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/TestScript.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/TestScript.java 2010-10-27
02:02:21 UTC (rev 19679)
@@ -0,0 +1,61 @@
+package org.richfaces.component;
+
+import org.richfaces.renderkit.html.LibraryScriptString;
+import org.richfaces.validator.LibraryResource;
+
+final class TestScript implements LibraryScriptString {
+ private final String name;
+
+ TestScript(String name) {
+ this.name = name;
+ }
+
+ public String toScript() {
+ return name;
+ }
+
+ public void appendScript(StringBuffer functionString) {
+ functionString.append(name);
+
+ }
+
+ public LibraryResource getResource() {
+ return UIValidatorScriptCollectionTest.FOO_RESOURCE;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ TestScript other = (TestScript) obj;
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ return true;
+ }
+}
\ No newline at end of file
Property changes on:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/TestScript.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/UIValidatorScriptCollectionTest.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/UIValidatorScriptCollectionTest.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/UIValidatorScriptCollectionTest.java 2010-10-27
02:02:21 UTC (rev 19679)
@@ -0,0 +1,72 @@
+package org.richfaces.component;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.junit.Test;
+import org.richfaces.renderkit.html.ClientOnlyScript;
+import org.richfaces.renderkit.html.ComponentValidatorScript;
+import org.richfaces.renderkit.html.LibraryScriptString;
+import org.richfaces.validator.LibraryResource;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
+/**
+ * Test collection of validator scripts.
+ * @author asmirnov
+ *
+ */
+public class UIValidatorScriptCollectionTest {
+
+ static final LibraryResource FOO_RESOURCE = new LibraryResource("org.rf",
"foo");
+
+
+ @Test
+ public void testAddOrFindScript() {
+ UIValidatorScript validatorScriptComponent = new UIValidatorScript();
+ ComponentValidatorScript validatorScript = createValidatorScript("foo",
"bar");
+ ComponentValidatorScript validatorScript2 =
validatorScriptComponent.addOrFindScript(validatorScript);
+ Collection<ComponentValidatorScript> scripts =
validatorScriptComponent.getScripts();
+ assertEquals(1, scripts.size());
+ assertSame(validatorScript,Iterables.getOnlyElement(scripts));
+ }
+
+ @Test
+ public void testAddOrFindScript2() {
+ UIValidatorScript validatorScriptComponent = new UIValidatorScript();
+ ComponentValidatorScript validatorScript = createValidatorScript("foo",
"bar");
+ validatorScriptComponent.addOrFindScript(validatorScript);
+ ComponentValidatorScript validatorScript2 =
createValidatorScript("fooz", "baz","bar");
+ ComponentValidatorScript validatorScript3 =
validatorScriptComponent.addOrFindScript(validatorScript2);
+ Collection<ComponentValidatorScript> scripts =
validatorScriptComponent.getScripts();
+ assertEquals(2, scripts.size());
+ assertSame(validatorScript2,validatorScript3);
+ }
+
+ @Test
+ public void testAddOrFindScript3() {
+ UIValidatorScript validatorScriptComponent = new UIValidatorScript();
+ ComponentValidatorScript validatorScript = createValidatorScript("foo",
"bar");
+ validatorScriptComponent.addOrFindScript(validatorScript);
+ ComponentValidatorScript validatorScript2 =
createValidatorScript("foo", "bar");
+ ComponentValidatorScript validatorScript3 =
validatorScriptComponent.addOrFindScript(validatorScript2);
+ Collection<ComponentValidatorScript> scripts =
validatorScriptComponent.getScripts();
+ assertEquals(1, scripts.size());
+ assertSame(validatorScript,validatorScript3);
+ }
+
+ private LibraryScriptString createLibraryScript(final String name) {
+ return new TestScript(name);
+ }
+
+ private ComponentValidatorScript createValidatorScript(String converter, String
...validators){
+ ArrayList<LibraryScriptString> validatorScripts = Lists.newArrayList();
+ for (String validatorName : validators) {
+ validatorScripts.add(createLibraryScript(validatorName));
+ }
+ return new ClientOnlyScript(createLibraryScript(converter), validatorScripts);
+ }
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/UIValidatorScriptCollectionTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/UIViewResourceTest.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/UIViewResourceTest.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/UIViewResourceTest.java 2010-10-27
02:02:21 UTC (rev 19679)
@@ -0,0 +1,55 @@
+package org.richfaces.component;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import javax.faces.render.ResponseStateManager;
+
+import org.jboss.test.faces.FacesEnvironment;
+import org.jboss.test.faces.FacesEnvironment.FacesRequest;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Test for dynamic add/remove {@link UIValidatorScript} as view resource.
+ * @author asmirnov
+ *
+ */
+public class UIViewResourceTest {
+
+ private FacesEnvironment environment;
+
+
+ @Before
+ public void setUp() {
+ environment =
FacesEnvironment.createEnvironment().withContent("/test.xhtml",
+ "<html
xmlns=\"http://www.w3.org/1999/xhtml\"\n" +
+ "
xmlns:ui=\"http://java.sun.com/jsf/facelets\"\n" +
+ "
xmlns:h=\"http://java.sun.com/jsf/html\">"+
+ "<h:form id=\"helloForm\" >"+
+ " <h:outputText value=\"#{test.value}\"
/>\n" +
+ "</h:form>\n" +
+ "</html>").
+ withResource(FacesEnvironment.FACES_CONFIG_XML,
"org/richfaces/component/faces-config.xml").
+ start();
+ }
+
+ @After
+ public void thearDown() throws Exception{
+ environment.release();
+ environment = null;
+ }
+
+ @Test
+ public void testRequest() throws Exception {
+ FacesRequest request =
environment.createFacesRequest("http://localhost/test.jsf?foo=bar");
+ assertNotNull(request.execute());
+ String contentAsString = request.getConnection().getContentAsString();
+ assertTrue(contentAsString.contains(ResponseStateManager.VIEW_STATE_PARAM));
+ assertTrue(contentAsString.contains(TestBean.FOO_VALUE));
+ }
+
+
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/UIViewResourceTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added:
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/component/faces-config.xml
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/component/faces-config.xml
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/component/faces-config.xml 2010-10-27
02:02:21 UTC (rev 19679)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faces-config version="2.0" metadata-complete="false"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:cdk="http://jboss.org/schema/richfaces/cdk/extensions"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+<managed-bean>
+ <managed-bean-name>test</managed-bean-name>
+ <managed-bean-class>org.richfaces.component.TestBean</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+</managed-bean>
+</faces-config>
\ No newline at end of file
Property changes on:
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/component/faces-config.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native