Author: alexsmirnov
Date: 2010-11-01 17:31:19 -0400 (Mon, 01 Nov 2010)
New Revision: 19863
Added:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/AjaxValidationTest.java
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/component/WEB-INF/
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/component/WEB-INF/faces-config.xml
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/component/test.xhtml
Removed:
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/component/faces-config.xml
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/renderkit/html/ClientValidatorRenderer.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/faces-config.xml
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/UIViewResourceTest.java
Log:
RESOLVED - issue RF-9593: CSV - create tests and implementation for AJAX transport.
https://jira.jboss.org/browse/RF-9593
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-11-01
19:50:05 UTC (rev 19862)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIValidatorScript.java 2010-11-01
21:31:19 UTC (rev 19863)
@@ -131,7 +131,7 @@
}
}
- public static final String COMPONENT_TYPE =
"org.richfaces.ValidatroScript";
+ public static final String COMPONENT_TYPE =
"org.richfaces.ValidatorScript";
public static final String COMPONENT_FAMILY = "org.richfaces.Script";
Modified:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2010-11-01
19:50:05 UTC (rev 19862)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2010-11-01
21:31:19 UTC (rev 19863)
@@ -235,10 +235,13 @@
private String createAjaxScript(ClientBehaviorContext behaviorContext,
ClientValidatorBehavior behavior) {
String ajaxScript = behavior.getAjaxScript(behaviorContext);
- ajaxScript=ajaxScript.replace("this", "element");
+ ajaxScript=ajaxScript.replace("this", ValidatorScriptBase.ELEMENT);
String clientId = getComponentClientId(behaviorContext);
ajaxScript = replaceTextToVariable(ajaxScript, clientId,
ValidatorScriptBase.CLIENT_ID);
- ajaxScript = replaceTextToVariable(ajaxScript, behaviorContext.getSourceId(),
ValidatorScriptBase.SOURCE_ID);
+ String sourceId = behaviorContext.getSourceId();
+ if(null != sourceId){
+ ajaxScript = replaceTextToVariable(ajaxScript, sourceId,
ValidatorScriptBase.ELEMENT);
+ }
return ajaxScript;
}
Modified:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java 2010-11-01
19:50:05 UTC (rev 19862)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java 2010-11-01
21:31:19 UTC (rev 19863)
@@ -6,6 +6,7 @@
public abstract class ValidatorScriptBase extends JSFunctionDefinition implements
ComponentValidatorScript {
+ protected static final String ELEMENT = "element";
protected static final String EVENT = "event";
protected static final JSLiteral EVENT_LITERAL = new JSLiteral(EVENT);
protected static final JSLiteral THIS = new JSLiteral("this");
@@ -25,7 +26,7 @@
private boolean bodyProcessed = false;
public ValidatorScriptBase() {
- super(CLIENT_ID,SOURCE_ID,"element",EVENT,DISABLE_AJAX);
+ super(CLIENT_ID,ELEMENT,EVENT,DISABLE_AJAX);
}
public void appendScript(StringBuffer functionString) {
@@ -40,7 +41,7 @@
protected abstract Object buildBody();
public String createCallScript(String clientId,String sourceId) {
- JSFunction callFunction = new
JSFunction(getName(),clientId,sourceId,THIS,EVENT_LITERAL);
+ JSFunction callFunction = new
JSFunction(getName(),clientId,null!=sourceId?sourceId:THIS,EVENT_LITERAL);
return callFunction.toScript();
}
Modified: branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/faces-config.xml
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/faces-config.xml 2010-11-01
19:50:05 UTC (rev 19862)
+++
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/faces-config.xml 2010-11-01
21:31:19 UTC (rev 19863)
@@ -1,7 +1,7 @@
<?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">
<component>
- <component-type>org.richfaces.ValidatroScript</component-type>
+ <component-type>org.richfaces.ValidatorScript</component-type>
<component-class>org.richfaces.component.UIValidatorScript</component-class>
</component>
<behavior>
Added:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/AjaxValidationTest.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/AjaxValidationTest.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/AjaxValidationTest.java 2010-11-01
21:31:19 UTC (rev 19863)
@@ -0,0 +1,90 @@
+package org.richfaces.component;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+import static org.junit.matchers.JUnitMatchers.*;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import org.hamcrest.Matcher;
+import org.jboss.test.faces.htmlunit.HtmlUnitEnvironment;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlInput;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+
+/**
+ * Test for dynamic add/remove {@link UIValidatorScript} as view resource.
+ * @author asmirnov
+ *
+ */
+public class AjaxValidationTest {
+
+ private HtmlUnitEnvironment environment;
+
+
+ @Before
+ public void setUp() {
+ this.environment = new HtmlUnitEnvironment();
+
this.environment.withWebRoot("org/richfaces/component/test.xhtml").start();
+ }
+
+ @After
+ public void thearDown() throws Exception{
+ environment.release();
+ environment = null;
+ }
+
+ @Test
+ public void testRequest() throws Exception {
+ HtmlPage page = requestPage();
+ HtmlInput input = hetInput(page);
+ assertNotNull(input);
+
+ }
+
+ @Test
+ public void testSubmitTooShortValue() throws Exception {
+ submitValueAndCheckMesage("",containsString("Error"));
+ }
+
+ @Test
+ public void testSubmitTooLongValue() throws Exception {
+ submitValueAndCheckMesage("123456",containsString("Error"));
+ }
+
+ @Test
+ public void testSubmitProperValue() throws Exception {
+ submitValueAndCheckMesage("ab",equalTo(""));
+ }
+
+ private void submitValueAndCheckMesage(String value, Matcher<String> matcher)
throws Exception {
+ HtmlPage page = requestPage();
+ HtmlInput input = hetInput(page);
+ input.setValueAttribute(value);
+ input.fireEvent("keyup");
+ HtmlElement message = page.getElementById("form:message");
+ assertThat(message.getTextContent(), matcher);
+// System.out.println(page.asXml());
+ }
+ private HtmlInput hetInput(HtmlPage page) {
+ HtmlForm htmlForm = page.getFormByName("form");
+ assertNotNull(htmlForm);
+ HtmlInput input = htmlForm.getInputByName("form:text");
+ return input;
+ }
+
+ private HtmlPage requestPage() throws MalformedURLException, IOException {
+ HtmlPage page = environment.getPage("/test.jsf");
+// System.out.println(page.asXml());
+ return page;
+ }
+
+
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/AjaxValidationTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
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 2010-11-01
19:50:05 UTC (rev 19862)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/UIViewResourceTest.java 2010-11-01
21:31:19 UTC (rev 19863)
@@ -34,7 +34,7 @@
" <h:commandButton id=\"command\"
value=\"Ok\" action=\"#{test.action}\"/>\n" +
"</h:form>\n" +
"</html>").
- withResource(FacesEnvironment.FACES_CONFIG_XML,
"org/richfaces/component/faces-config.xml").
+ withResource(FacesEnvironment.FACES_CONFIG_XML,
"org/richfaces/component/WEB-INF/faces-config.xml").
start();
}
Copied:
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/component/WEB-INF/faces-config.xml
(from rev 19848,
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/WEB-INF/faces-config.xml
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/component/WEB-INF/faces-config.xml 2010-11-01
21:31:19 UTC (rev 19863)
@@ -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/WEB-INF/faces-config.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Deleted:
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 2010-11-01
19:50:05 UTC (rev 19862)
+++
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/component/faces-config.xml 2010-11-01
21:31:19 UTC (rev 19863)
@@ -1,8 +0,0 @@
-<?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
Added:
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/component/test.xhtml
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/component/test.xhtml
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/component/test.xhtml 2010-11-01
21:31:19 UTC (rev 19863)
@@ -0,0 +1,17 @@
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:csv="http://richfaces.org/csv">
+ <h:head><title>Ajax validator</title></h:head>
+ <h:body>
+ <h:form id="form">
+ <h:inputText id="text" value="#{test.value}">
+ <f:validateLength minimum="1" maximum="3"/>
+ <csv:validator event="keyup" />
+ </h:inputText>
+ <h:outputText id="out"
value="#{test.value}"></h:outputText>
+ <h:message id="message" for="text" />
+ <h:commandLink id="submit">Submit</h:commandLink>
+ </h:form>
+ </h:body>
+</html>
Property changes on:
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/component/test.xhtml
___________________________________________________________________
Name: svn:mime-type
+ text/plain