You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2008/02/12 02:22:46 UTC

svn commit: r620684 - in /incubator/tuscany/java/sca: itest/ itest/services/src/main/webapp/ modules/host-webapp-junit/src/main/java/org/apache/tuscany/sca/host/webapp/junit/ modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ tools/m...

Author: rfeng
Date: Mon Feb 11 17:22:44 2008
New Revision: 620684

URL: http://svn.apache.org/viewvc?rev=620684&view=rev
Log:
Add a list operation to show/run available test cases

Removed:
    incubator/tuscany/java/sca/itest/services/src/main/webapp/
Modified:
    incubator/tuscany/java/sca/itest/pom.xml
    incubator/tuscany/java/sca/modules/host-webapp-junit/src/main/java/org/apache/tuscany/sca/host/webapp/junit/JUnitServletFilter.java
    incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
    incubator/tuscany/java/sca/tools/maven/maven-web-junit/src/main/java/org/apache/tuscany/tools/sca/web/junit/plugin/WebJUnitGeneratorMojo.java
    incubator/tuscany/java/sca/tools/maven/maven-web-junit/src/main/java/org/apache/tuscany/tools/sca/web/junit/plugin/WebJUnitMojo.java

Modified: incubator/tuscany/java/sca/itest/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/pom.xml?rev=620684&r1=620683&r2=620684&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/pom.xml (original)
+++ incubator/tuscany/java/sca/itest/pom.xml Mon Feb 11 17:22:44 2008
@@ -298,7 +298,7 @@
                             <execution>
                                 <id>web-junit-test</id>
                                 <configuration>
-                                    <url>${http.base}/${project.build.finalName}/junit</url>
+                                    <url>${http.base}/${project.build.finalName}/junit?op=runAll</url>
                                 </configuration>
                                 <phase>integration-test</phase>
                                 <goals>
@@ -345,7 +345,7 @@
                                 <deployables>
                                     <deployable>
                                         <location>${project.build.directory}/${project.build.finalName}.war</location>
-                                        <pingURL>${http.base}/${project.build.finalName}/junit</pingURL>
+                                        <pingURL>${http.base}/${project.build.finalName}/junit?op=list</pingURL>
                                         <type>war</type>
                                     </deployable>
                                 </deployables>
@@ -392,7 +392,7 @@
                             <execution>
                                 <id>web-junit-test</id>
                                 <configuration>
-                                    <url>${http.base}/${project.build.finalName}/junit</url>
+                                    <url>${http.base}/${project.build.finalName}/junit?op=runAll</url>
                                 </configuration>
                                 <phase>integration-test</phase>
                                 <goals>
@@ -439,7 +439,7 @@
                                 <deployables>
                                     <deployable>
                                         <location>${project.build.directory}/${project.build.finalName}.war</location>
-                                        <pingURL>${http.base}/${project.build.finalName}/junit</pingURL>
+                                        <pingURL>${http.base}/${project.build.finalName}/junit?op=list</pingURL>
                                         <type>war</type>
                                     </deployable>
                                 </deployables>
@@ -488,7 +488,7 @@
                             <execution>
                                 <id>web-junit-test</id>
                                 <configuration>
-                                    <url>${http.base}/${project.build.finalName}/junit</url>
+                                    <url>${http.base}/${project.build.finalName}/junit?op=runAll</url>
                                 </configuration>
                                 <phase>integration-test</phase>
                                 <goals>
@@ -586,7 +586,7 @@
                                     <goal>test</goal>
                                 </goals>
                                 <configuration>
-                                    <url>${http.base}/${project.build.finalName}/junit</url>
+                                    <url>${http.base}/${project.build.finalName}/junit?op=runAll</url>
                                 </configuration>
                             </execution>
                         </executions>

Modified: incubator/tuscany/java/sca/modules/host-webapp-junit/src/main/java/org/apache/tuscany/sca/host/webapp/junit/JUnitServletFilter.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-webapp-junit/src/main/java/org/apache/tuscany/sca/host/webapp/junit/JUnitServletFilter.java?rev=620684&r1=620683&r2=620684&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/host-webapp-junit/src/main/java/org/apache/tuscany/sca/host/webapp/junit/JUnitServletFilter.java (original)
+++ incubator/tuscany/java/sca/modules/host-webapp-junit/src/main/java/org/apache/tuscany/sca/host/webapp/junit/JUnitServletFilter.java Mon Feb 11 17:22:44 2008
@@ -172,15 +172,15 @@
     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
         ServletException {
 
-        if(!junitEnabled) {
+        if (!junitEnabled) {
             chain.doFilter(request, response);
             return;
         }
-        
+
         HttpServletRequest req = (HttpServletRequest)request;
         String path = req.getServletPath();
-        
-        if(!"/junit".equals(path)) {
+
+        if (!"/junit".equals(path)) {
             chain.doFilter(request, response);
             return;
         }
@@ -190,11 +190,38 @@
 
         Set<String> testCases = null;
         // ClassLoader cl = Thread.currentThread().getContextClassLoader();
-        if (query == null || "ALL".equals(query)) {
-            testCases = this.allTestCases;
+        String op = req.getParameter("op");
+        if (query == null || op == null || "list".equalsIgnoreCase(op)) {
+            response.setContentType("text/html");
+            ps.println("<html><body>");
+            ps.println("<h2>Available Test Cases</h2><p>");
+            ps.println("<form method=\"get\" action=\"junit\">");
+            ps.println("<table border=\"1\">");
+            for (String s : this.allTestCases) {
+                ps.print("<tr><td>");
+                ps.print("<input type=\"checkbox\" name=\"test\" value=\"" + s
+                    + "\"/><a href=\"junit?op=runSelected&test="
+                    + s
+                    + "\">"
+                    + s
+                    + "</a>");
+                ps.println("</td></tr>");
+            }
+            ps.println("</table>");
+            ps.println("<p><input type=\"submit\" name=\"op\" value=\"RunSelected\"/>");
+            ps.println("<input type=\"submit\" name=\"op\" value=\"RunAll\"/>");
+            ps.println("</form></body></html>");
+            return;
         } else {
-            String[] tests = query.split(",");
-            testCases = new HashSet<String>(Arrays.asList(tests));
+            if ("runAll".equalsIgnoreCase(op)) {
+                testCases = this.allTestCases;
+            } else {
+                String[] tests = req.getParameterValues("test");
+                if (tests == null) {
+                    tests = new String[0];
+                }
+                testCases = new HashSet<String>(Arrays.asList(tests));
+            }
         }
 
         int errors = 0;

Modified: incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java?rev=620684&r1=620683&r2=620684&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java (original)
+++ incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java Mon Feb 11 17:22:44 2008
@@ -239,31 +239,22 @@
     @SuppressWarnings("unchecked")
     public void initContextPath(ServletConfig config) {
         ServletContext context = config.getServletContext();
-        int version = context.getMajorVersion() * 100 + context.getMinorVersion();
-
+        // The getContextPath() is introduced since Servlet 2.5
         Method m;
         try {
+            // Try to get the method anyway since some ServletContext impl has this method even before 2.5
             m = context.getClass().getMethod("getContextPath", new Class[] {});
-            try {
-                contextPath = (String)m.invoke(context, new Object[] {});
-            } catch (Exception e) {
-                throw new RuntimeException(e);
+            contextPath = (String)m.invoke(context, new Object[] {});
+        } catch (Exception e) {
+            contextPath = config.getInitParameter("contextPath");
+            if (contextPath == null) {
+                logger.warning("Servlet level is: " + context.getMajorVersion() + "." + context.getMinorVersion());
+                throw new IllegalStateException(
+                                                "'contextPath' init parameter must be set for pre-2.5 servlet container");
             }
-        } catch (NoSuchMethodException e) {
-            throw new IllegalStateException("'contextPath' init parameter must be set for pre-2.5 servlet container");
-        }
-        
-        // Fall back for containers using old Servlet APIs
-        if (contextPath == null) {
-        	contextPath = config.getInitParameter("contextPath");
         }
-        
-        // contextPath == null => throw proper exception
-        if (contextPath == null) {
-        	throw new IllegalArgumentException("Could not retrieve webapp contextPath either from servletContext or init Parameter");
-        }
-        
-        logger.info("initContextPath: " + contextPath);
+
+        logger.info("ContextPath: " + contextPath);
     }
 
     void destroy() {

Modified: incubator/tuscany/java/sca/tools/maven/maven-web-junit/src/main/java/org/apache/tuscany/tools/sca/web/junit/plugin/WebJUnitGeneratorMojo.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tools/maven/maven-web-junit/src/main/java/org/apache/tuscany/tools/sca/web/junit/plugin/WebJUnitGeneratorMojo.java?rev=620684&r1=620683&r2=620684&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tools/maven/maven-web-junit/src/main/java/org/apache/tuscany/tools/sca/web/junit/plugin/WebJUnitGeneratorMojo.java (original)
+++ incubator/tuscany/java/sca/tools/maven/maven-web-junit/src/main/java/org/apache/tuscany/tools/sca/web/junit/plugin/WebJUnitGeneratorMojo.java Mon Feb 11 17:22:44 2008
@@ -72,15 +72,11 @@
     private final static String WEB_XML =
         ASL_HEADER + "\n<!DOCTYPE web-app PUBLIC \"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN\" \"http://java.sun.com/dtd/web-app_2_3.dtd\">"
             + "\n<web-app>"
-            + "\n   <display-name>${display-name}</display-name>"
+            + "\n       <display-name>${display-name}</display-name>"
             + "\n       <filter>"
             + "\n           <filter-name>tuscany</filter-name>"
             + "\n           <filter-class>org.apache.tuscany.sca.host.webapp.TuscanyServletFilter</filter-class>"
             + "\n       </filter>"
-            + "\n       <filter-mapping>"
-            + "\n           <filter-name>tuscany</filter-name>"
-            + "\n           <url-pattern>/*</url-pattern>"
-            + "\n       </filter-mapping>"
             + "\n       <filter>"
             + "\n           <filter-name>junit</filter-name>"
             + "\n           <filter-class>org.apache.tuscany.sca.host.webapp.junit.JUnitServletFilter</filter-class>"
@@ -90,8 +86,12 @@
             + "\n           </init-param>"
             + "\n       </filter>"
             + "\n       <filter-mapping>"
+            + "\n           <filter-name>tuscany</filter-name>"
+            + "\n           <url-pattern>/*</url-pattern>"
+            + "\n       </filter-mapping>"
+            + "\n       <filter-mapping>"
             + "\n           <filter-name>junit</filter-name>"
-            + "\n           <url-pattern>/junit</url-pattern>"
+            + "\n           <url-pattern>/junit/*</url-pattern>"
             + "\n       </filter-mapping>"            
             + "\n</web-app>\n";
 

Modified: incubator/tuscany/java/sca/tools/maven/maven-web-junit/src/main/java/org/apache/tuscany/tools/sca/web/junit/plugin/WebJUnitMojo.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tools/maven/maven-web-junit/src/main/java/org/apache/tuscany/tools/sca/web/junit/plugin/WebJUnitMojo.java?rev=620684&r1=620683&r2=620684&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tools/maven/maven-web-junit/src/main/java/org/apache/tuscany/tools/sca/web/junit/plugin/WebJUnitMojo.java (original)
+++ incubator/tuscany/java/sca/tools/maven/maven-web-junit/src/main/java/org/apache/tuscany/tools/sca/web/junit/plugin/WebJUnitMojo.java Mon Feb 11 17:22:44 2008
@@ -84,7 +84,7 @@
         reset();
 
         if (url == null) {
-            url = "http://localhost:8080/" + project.getBuild().getFinalName() + "/junit";
+            url = "http://localhost:8080/" + project.getBuild().getFinalName() + "/junit?op=runAll";
         }
 
         if (testCases != null) {



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org