[jboss-cvs] JBossAS SVN: r92577 - in trunk: testsuite/imports/sections and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 19 09:22:07 EDT 2009
Author: stan.silvert at jboss.com
Date: 2009-08-19 09:22:07 -0400 (Wed, 19 Aug 2009)
New Revision: 92577
Added:
trunk/testsuite/src/resources/web/html/jsftest/beanvalidation.xhtml
Modified:
trunk/testsuite/build.xml
trunk/testsuite/imports/sections/jsf.xml
trunk/testsuite/src/main/org/jboss/test/web/test/JSFIntegrationUnitTestCase.java
trunk/testsuite/src/resources/web/html/jsftest/WEB-INF/faces-config.xml
trunk/tomcat/build.xml
trunk/tomcat/pom.xml
trunk/tomcat/src/main/org/jboss/web/jsf/integration/config/JBossJSFConfigureListener.java
Log:
JBAS-7178 Integrate JSF-303 Bean Validation with JSF
Modified: trunk/testsuite/build.xml
===================================================================
--- trunk/testsuite/build.xml 2009-08-19 13:07:25 UTC (rev 92576)
+++ trunk/testsuite/build.xml 2009-08-19 13:22:07 UTC (rev 92577)
@@ -244,6 +244,7 @@
<fileset refid="sun-jaxb:jaxb-xjc:jar"/>
<fileset refid="javax.faces:jsf-api:jar"/>
<fileset refid="javax.faces:jsf-impl:jar"/>
+ <fileset refid="javax.validation:validation-api:jar"/>
<fileset refid="jboss.web:el-api:jar"/>
<fileset refid="jboss.web:jasper-jdt:jar"/>
<fileset refid="jboss.web:jbossweb:jar"/>
Modified: trunk/testsuite/imports/sections/jsf.xml
===================================================================
--- trunk/testsuite/imports/sections/jsf.xml 2009-08-19 13:07:25 UTC (rev 92576)
+++ trunk/testsuite/imports/sections/jsf.xml 2009-08-19 13:22:07 UTC (rev 92577)
@@ -7,6 +7,7 @@
webxml="${build.resources}/web/WEB-INF/jsftest-web.xml">
<fileset dir="${build.resources}/web/html/jsftest">
<include name="**/*.jsp"/>
+ <include name="**/*.xhtml"/>
</fileset>
<classes dir="${build.classes}">
Modified: trunk/testsuite/src/main/org/jboss/test/web/test/JSFIntegrationUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/web/test/JSFIntegrationUnitTestCase.java 2009-08-19 13:07:25 UTC (rev 92576)
+++ trunk/testsuite/src/main/org/jboss/test/web/test/JSFIntegrationUnitTestCase.java 2009-08-19 13:22:07 UTC (rev 92577)
@@ -21,10 +21,6 @@
*/
package org.jboss.test.web.test;
-import com.sun.faces.util.FacesLogger;
-
-import java.net.URL;
-
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -66,17 +62,17 @@
{
String responseBody = getResponseBody("jbosstest-jsf");
- assertTrue(contains(responseBody, "@PostConstruct was called."));
- assertTrue(contains(responseBody, "@PreDestroy was called."));
- assertTrue(contains(responseBody, "Datasource was injected."));
+ assertTrue(responseBody.contains("@PostConstruct was called."));
+ assertTrue(responseBody.contains("@PreDestroy was called."));
+ assertTrue(responseBody.contains("Datasource was injected."));
// Tests JSF/JSTL integration
- assertTrue(contains(responseBody, "number one"));
- assertTrue(contains(responseBody, "number two"));
- assertTrue(contains(responseBody, "number three"));
+ assertTrue(responseBody.contains("number one"));
+ assertTrue(responseBody.contains("number two"));
+ assertTrue(responseBody.contains("number three"));
// Tests enum support
- assertTrue(contains(responseBody, "JBoss Color selection is PURPLE"));
+ assertTrue(responseBody.contains("JBoss Color selection is PURPLE"));
}
@@ -88,16 +84,28 @@
// Initial JSF request
WebRequest req = new GetMethodWebRequest(baseURL + "bundled-myfaces-hellojsf/index.faces");
WebResponse webResponse = webConversation.getResponse(req);
- assertTrue(contains(webResponse.getText(), "Enter your name"));
+ assertTrue(webResponse.getText().contains("Enter your name"));
// submit data
WebForm form = webResponse.getFormWithID("form1");
form.setParameter("form1:input_foo_text", "Stan");
SubmitButton submitButton = form.getSubmitButtonWithID("form1:submit_button");
webResponse = form.submit(submitButton);
- assertTrue(contains(webResponse.getText(), "Hello Stan"));
+ assertTrue(webResponse.getText().contains("Hello Stan"));
}
+ public void testBeanValidationIntegratedWithJSF() throws Exception
+ {
+ WebConversation wc = new WebConversation();
+ String url = makeRequestString("jbosstest-jsf", "/beanvalidation.jsf");
+ WebResponse response = wc.getResponse(url);
+ WebForm form = response.getFormWithID("form1");
+ form.setParameter("form1:input_name", "a");
+ SubmitButton submitButton = form.getSubmitButtonWithID("form1:submit_button");
+ response = form.submit(submitButton);
+ assertTrue(response.getText().contains("size must be between 2 and"));
+ }
+
private String getResponseBody(String warName) throws Exception
{
HttpClient client = new HttpClient();
@@ -115,14 +123,17 @@
return responseBody;
}
-
- private boolean contains(String base, String target) {
- return base.indexOf(target) != -1;
+
+ // makes default GetMethod request for index.jsf
+ private GetMethod makeRequest(String warName)
+ {
+ return new GetMethod(makeRequestString(warName, "index.jsf"));
}
-
- private GetMethod makeRequest(String warName) {
+
+ private String makeRequestString(String warName, String jsfPage)
+ {
String baseURL = HttpUtils.getBaseURL();
- return new GetMethod(baseURL + warName + "/index.jsf");
+ return baseURL + warName + "/" + jsfPage;
}
public static Test suite() throws Exception
Modified: trunk/testsuite/src/resources/web/html/jsftest/WEB-INF/faces-config.xml
===================================================================
--- trunk/testsuite/src/resources/web/html/jsftest/WEB-INF/faces-config.xml 2009-08-19 13:07:25 UTC (rev 92576)
+++ trunk/testsuite/src/resources/web/html/jsftest/WEB-INF/faces-config.xml 2009-08-19 13:22:07 UTC (rev 92577)
@@ -2,8 +2,9 @@
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
- version="1.2">
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
+ version="2.0">
<managed-bean>
<description>Injection Test</description>
Added: trunk/testsuite/src/resources/web/html/jsftest/beanvalidation.xhtml
===================================================================
--- trunk/testsuite/src/resources/web/html/jsftest/beanvalidation.xhtml (rev 0)
+++ trunk/testsuite/src/resources/web/html/jsftest/beanvalidation.xhtml 2009-08-19 13:22:07 UTC (rev 92577)
@@ -0,0 +1,28 @@
+<!DOCTYPE html
+PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+ <title>JBoss JSF Bean Validation Integration Test</title>
+ </head>
+ <body>
+ <h3>The name should fail Bean Validation if length less than 2</h3>
+ <f:view>
+ <h:form id="form1">
+
+ <h:outputText value="Enter your name:" rendered="#{empty validatedBean.name}" id="prompt"/>
+ <h:outputText value="Hello #{validatedBean.name}" rendered="#{!empty validatedBean.name}" id="greeting"/><br/>
+
+ <h:inputText value="#{validatedBean.name}" id="input_name"/>
+ <h:message for="input_name" styleClass="errorMessage"/>
+ <br/>
+ <h:commandButton value="Submit" action="/beanvalidation.xhtml" id="submit_button"/>
+ </h:form>
+ </f:view>
+
+ </body>
+</html>
Modified: trunk/tomcat/build.xml
===================================================================
--- trunk/tomcat/build.xml 2009-08-19 13:07:25 UTC (rev 92576)
+++ trunk/tomcat/build.xml 2009-08-19 13:22:07 UTC (rev 92577)
@@ -52,6 +52,7 @@
<path refid="jboss.web.classpath"/>
<path refid="sun.jaxb.classpath"/>
<path refid="sun.jsf.classpath"/>
+ <path refid="validation.api.classpath"/>
<path refid="apache.commons.classpath"/>
<path refid="apache.log4j.classpath"/>
<path refid="junit.junit.classpath"/>
Modified: trunk/tomcat/pom.xml
===================================================================
--- trunk/tomcat/pom.xml 2009-08-19 13:07:25 UTC (rev 92576)
+++ trunk/tomcat/pom.xml 2009-08-19 13:22:07 UTC (rev 92577)
@@ -119,10 +119,10 @@
<copy file="${maven.dependency.javax.servlet.jstl.jar.path}"
tofile="${output.deploy}/jbossweb.sar/jstl.jar"/>
<mkdir dir="${output.deploy}/jbossweb.sar/jsf-libs"/>
- <copy todir="${output.deploy}/jbossweb.sar/jsf-libs">
- <fileset file="${maven.dependency.javax.faces.jsf-api.jar.path}"/>
- <fileset file="${maven.dependency.javax.faces.jsf-impl.jar.path}"/>
- </copy>
+ <copy file="${maven.dependency.javax.faces.jsf-api.jar.path}"
+ tofile="${output.deploy}/jbossweb.sar/jsf-libs/jsf-api.jar"/>
+ <copy file="${maven.dependency.javax.faces.jsf-impl.jar.path}"
+ tofile="${output.deploy}/jbossweb.sar/jsf-libs/jsf-impl.jar"/>
<!-- jar for jsf integration classes -->
<copy file="target/${project.build.finalName}-jboss-faces.jar"
@@ -381,6 +381,10 @@
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ </dependency>
</dependencies>
</project>
Modified: trunk/tomcat/src/main/org/jboss/web/jsf/integration/config/JBossJSFConfigureListener.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/jsf/integration/config/JBossJSFConfigureListener.java 2009-08-19 13:07:25 UTC (rev 92576)
+++ trunk/tomcat/src/main/org/jboss/web/jsf/integration/config/JBossJSFConfigureListener.java 2009-08-19 13:22:07 UTC (rev 92577)
@@ -22,8 +22,10 @@
package org.jboss.web.jsf.integration.config;
import com.sun.faces.config.ConfigureListener;
+import javax.faces.validator.BeanValidator;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
+import javax.validation.Validation;
import org.jboss.logging.Logger;
/**
@@ -56,6 +58,7 @@
checkForMyFaces();
initializeJspRuntime();
+ addBeanValidatorFactory();
initialized = true;
super.contextInitialized(event);
}
@@ -101,5 +104,11 @@
// ignore - this is a good thing
}
}
+
+ private void addBeanValidatorFactory()
+ {
+ this.servletContext.setAttribute(BeanValidator.VALIDATOR_FACTORY_KEY,
+ Validation.buildDefaultValidatorFactory());
+ }
}
More information about the jboss-cvs-commits
mailing list