[jboss-cvs] JBossAS SVN: r92409 - in branches/Branch_5_x: testsuite/imports/sections and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Aug 16 20:46:41 EDT 2009


Author: stan.silvert at jboss.com
Date: 2009-08-16 20:46:41 -0400 (Sun, 16 Aug 2009)
New Revision: 92409

Added:
   branches/Branch_5_x/testsuite/src/resources/web/html/jsftest/beanvalidation.xhtml
Modified:
   branches/Branch_5_x/testsuite/build.xml
   branches/Branch_5_x/testsuite/imports/sections/jsf.xml
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/web/test/JSFIntegrationUnitTestCase.java
   branches/Branch_5_x/testsuite/src/resources/web/html/jsftest/WEB-INF/faces-config.xml
   branches/Branch_5_x/tomcat/build.xml
   branches/Branch_5_x/tomcat/pom.xml
   branches/Branch_5_x/tomcat/src/main/org/jboss/web/jsf/integration/config/JBossJSFConfigureListener.java
Log:
JBAS-7178 Integrate JSR-303 Bean Validation with JSF


Modified: branches/Branch_5_x/testsuite/build.xml
===================================================================
--- branches/Branch_5_x/testsuite/build.xml	2009-08-16 23:27:40 UTC (rev 92408)
+++ branches/Branch_5_x/testsuite/build.xml	2009-08-17 00:46:41 UTC (rev 92409)
@@ -159,6 +159,7 @@
       <path refid="jboss.metadata.classpath"/>
       <path refid="jboss.integration.classpath"/>
       <path refid="jboss.profileservice.spi.classpath"/>
+      <path refid="validation.api.classpath"/>
       <path refid="stax.api.classpath"/>
       <!-- needed for messaging JMS provider tests -->
       <path refid="jboss.messaging.classpath"/>

Modified: branches/Branch_5_x/testsuite/imports/sections/jsf.xml
===================================================================
--- branches/Branch_5_x/testsuite/imports/sections/jsf.xml	2009-08-16 23:27:40 UTC (rev 92408)
+++ branches/Branch_5_x/testsuite/imports/sections/jsf.xml	2009-08-17 00:46:41 UTC (rev 92409)
@@ -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: branches/Branch_5_x/testsuite/src/main/org/jboss/test/web/test/JSFIntegrationUnitTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/web/test/JSFIntegrationUnitTestCase.java	2009-08-16 23:27:40 UTC (rev 92408)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/web/test/JSFIntegrationUnitTestCase.java	2009-08-17 00:46:41 UTC (rev 92409)
@@ -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: branches/Branch_5_x/testsuite/src/resources/web/html/jsftest/WEB-INF/faces-config.xml
===================================================================
--- branches/Branch_5_x/testsuite/src/resources/web/html/jsftest/WEB-INF/faces-config.xml	2009-08-16 23:27:40 UTC (rev 92408)
+++ branches/Branch_5_x/testsuite/src/resources/web/html/jsftest/WEB-INF/faces-config.xml	2009-08-17 00:46:41 UTC (rev 92409)
@@ -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: branches/Branch_5_x/testsuite/src/resources/web/html/jsftest/beanvalidation.xhtml
===================================================================
--- branches/Branch_5_x/testsuite/src/resources/web/html/jsftest/beanvalidation.xhtml	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/resources/web/html/jsftest/beanvalidation.xhtml	2009-08-17 00:46:41 UTC (rev 92409)
@@ -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: branches/Branch_5_x/tomcat/build.xml
===================================================================
--- branches/Branch_5_x/tomcat/build.xml	2009-08-16 23:27:40 UTC (rev 92408)
+++ branches/Branch_5_x/tomcat/build.xml	2009-08-17 00:46:41 UTC (rev 92409)
@@ -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: branches/Branch_5_x/tomcat/pom.xml
===================================================================
--- branches/Branch_5_x/tomcat/pom.xml	2009-08-16 23:27:40 UTC (rev 92408)
+++ branches/Branch_5_x/tomcat/pom.xml	2009-08-17 00:46:41 UTC (rev 92409)
@@ -254,6 +254,10 @@
       <groupId>javax.faces</groupId>
       <artifactId>jsf-api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>javax.validation</groupId>
+      <artifactId>validation-api</artifactId>
+    </dependency>
   </dependencies>
   
 </project>

Modified: branches/Branch_5_x/tomcat/src/main/org/jboss/web/jsf/integration/config/JBossJSFConfigureListener.java
===================================================================
--- branches/Branch_5_x/tomcat/src/main/org/jboss/web/jsf/integration/config/JBossJSFConfigureListener.java	2009-08-16 23:27:40 UTC (rev 92408)
+++ branches/Branch_5_x/tomcat/src/main/org/jboss/web/jsf/integration/config/JBossJSFConfigureListener.java	2009-08-17 00:46:41 UTC (rev 92409)
@@ -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;
 
 /**
@@ -57,6 +59,7 @@
         checkForMyFaces();
         initializeJspRuntime();
         initialized = true;
+        addBeanValidatorFactory();
         super.contextInitialized(event);
     }
     
@@ -70,6 +73,12 @@
         }
     }
     
+    private void addBeanValidatorFactory()
+    {
+       this.servletContext.setAttribute(BeanValidator.VALIDATOR_FACTORY_KEY, 
+                                        Validation.buildDefaultValidatorFactory());
+    }
+    
     // This method accounts for a peculiar problem with Jasper that pops up from time
     // to time.  In some cases, if the JspRuntimeContext is not loaded then the JspFactory
     // will not be initialized for JSF.  This method assures that it will always be




More information about the jboss-cvs-commits mailing list