Author: dfabulich
Date: Thu Mar 27 17:28:46 2008
New Revision: 642046

URL: http://svn.apache.org/viewvc?rev=642046&view=rev
Log:
[SUREFIRE-459] Very basic Jetty test fails.  By default forkmode=once and 
useSystemclassloader=true, which causes us to launch the tests using a a 
manifest-only jar; this confuses Jetty when it passes java.class.path to javac 
to compile JSPs.  Fixed by deliberately "faking out" the java.class.path, 
setting it to what the classpath would have been if we'd launched the app in a 
conventional way.  This also has the benefit of more generally insulating our 
users from the manifest-only jar; java.class.path will look "normal" now.

Added:
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/pom.xml
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/main/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/main/resources/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/main/webapp/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/main/webapp/WEB-INF/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/main/webapp/WEB-INF/web.xml
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/main/webapp/index.jsp
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/test/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/test/java/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/test/java/WebAppTest.java
Modified:
    
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java

Modified: 
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java?rev=642046&r1=642045&r2=642046&view=diff
==============================================================================
--- 
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
 (original)
+++ 
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
 Thu Mar 27 17:28:46 2008
@@ -318,10 +318,17 @@
         {
             // The test classloader must be constructed first to avoid issues 
with commons-logging until we properly
             // separate the TestNG classloader
-            ClassLoader testsClassLoader = useSystemClassLoader() ? 
getClass().getClassLoader() // ClassLoader.getSystemClassLoader()
-                            : createClassLoader( classPathUrls, null, 
childDelegation );
-
-            recordTestClassPath();
+            ClassLoader testsClassLoader;
+            String testClassPath = getTestClassPathAsString();
+            System.setProperty( "surefire.test.class.path", testClassPath );
+            if (useSystemClassLoader()) {
+                testsClassLoader = getClass().getClassLoader(); // 
ClassLoader.getSystemClassLoader()
+                // SUREFIRE-459, trick the app under test into thinking its 
classpath was conventional (instead of a single manifest-only jar) 
+                System.setProperty( "surefire.real.class.path", 
System.getProperty( "java.class.path" ));
+                System.setProperty( "java.class.path", testClassPath );
+            } else {
+                testsClassLoader = createClassLoader( classPathUrls, null, 
childDelegation );
+            }
             
             ClassLoader surefireClassLoader = createClassLoader( 
surefireClassPathUrls, testsClassLoader );
 
@@ -357,13 +364,13 @@
 
     
     
-    private void recordTestClassPath()
+    private String getTestClassPathAsString()
     {
         StringBuffer sb = new StringBuffer();
         for (int i = 0; i < classPathUrls.size(); i++) {
             sb.append( classPathUrls.get( i ) ).append( File.pathSeparatorChar 
);
         }
-        System.setProperty( "surefire.test.class.path", sb.toString() );
+        return sb.toString();
     }
     
     private int runSuitesForkOnce()

Added: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/pom.xml?rev=642046&view=auto
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/pom.xml
 (added)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/pom.xml
 Thu Mar 27 17:28:46 2008
@@ -0,0 +1,102 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.surefire.its</groupId>
+  <artifactId>webapp</artifactId>
+  <packaging>war</packaging>
+  <version>1.0-SNAPSHOT</version>
+  <name>sample webapp with Jetty test</name>
+  <build>
+    <finalName>webapp</finalName>
+    <plugins>
+        <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-war-plugin</artifactId>
+            <version>2.0</version>
+            <executions>
+                <execution>
+                    <phase>generate-test-resources</phase>
+                    <goals>
+                        <goal>exploded</goal>
+                    </goals>
+                    <configuration>
+                        
<webappDirectory>${project.build.directory}/webapp</webappDirectory>
+                    </configuration>
+                </execution>
+            </executions>
+        </plugin>
+    </plugins>
+  </build>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>jetty</groupId>
+      <artifactId>org.mortbay.jetty</artifactId>
+      <version>5.1.10</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+      <version>2.4</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+               <groupId>jetty</groupId>
+               <artifactId>jasper-compiler</artifactId>
+               <version>5.1.10</version>
+               <scope>test</scope>
+       </dependency>
+       <dependency>
+        <groupId>jetty</groupId>
+        <artifactId>jasper-runtime</artifactId>
+        <version>5.1.10</version>
+    </dependency>
+    <dependency>
+        <groupId>commons-beanutils</groupId>
+        <artifactId>commons-beanutils</artifactId>
+        <version>1.7.0</version>
+        <scope>test</scope>
+    </dependency>
+    <dependency>
+        <groupId>javax.servlet</groupId>
+        <artifactId>jsp-api</artifactId>
+        <version>2.0</version>
+    </dependency>
+    <dependency>
+        <groupId>ant</groupId>
+        <artifactId>ant</artifactId>
+        <version>1.6.5</version>
+    </dependency>
+    <dependency>
+        <groupId>commons-el</groupId>
+        <artifactId>commons-el</artifactId>
+        <version>1.0</version>
+    </dependency>
+  </dependencies>
+  <profiles>
+    <profile>
+      <id>default-tools.jar</id>
+      <activation>
+        <property>
+          <name>java.vendor</name>
+          <value>Sun Microsystems Inc.</value>
+       </property>
+     </activation>
+      <dependencies>
+        <dependency>
+          <groupId>com.sun</groupId>
+          <artifactId>tools</artifactId>
+          <version>system</version>
+          <scope>system</scope>
+          <systemPath>${java.home}/../lib/tools.jar</systemPath>
+       </dependency>
+     </dependencies>
+   </profile>
+  </profiles>
+</project>

Added: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/main/webapp/WEB-INF/web.xml
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/main/webapp/WEB-INF/web.xml?rev=642046&view=auto
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/main/webapp/WEB-INF/web.xml
 (added)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/main/webapp/WEB-INF/web.xml
 Thu Mar 27 17:28:46 2008
@@ -0,0 +1,7 @@
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd"; >
+
+<web-app>
+  <display-name>Archetype Created Web Application</display-name>
+</web-app>

Added: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/main/webapp/index.jsp
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/main/webapp/index.jsp?rev=642046&view=auto
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/main/webapp/index.jsp
 (added)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/main/webapp/index.jsp
 Thu Mar 27 17:28:46 2008
@@ -0,0 +1,5 @@
+<html>
+<body>
+<h2>Hello World!</h2>
+</body>
+</html>

Added: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/test/java/WebAppTest.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/test/java/WebAppTest.java?rev=642046&view=auto
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/test/java/WebAppTest.java
 (added)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/webapp/src/test/java/WebAppTest.java
 Thu Mar 27 17:28:46 2008
@@ -0,0 +1,37 @@
+import java.io.InputStream;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.mortbay.jetty.Server;
+
+
+public class WebAppTest extends TestCase {
+    private Server server = null;
+    
+    public void setUp() throws Exception {
+        System.setProperty("org.mortbay.xml.XmlParser.NotValidating", "true");
+        
+        server = new Server();
+        String testPort = ":18080";
+        server.addListener(testPort);
+        server.addWebApplication("127.0.0.1", "/webapp", "target/webapp");
+        
+        server.start();
+    }
+    
+    public void testBlah() throws Exception {
+        URL url = new URL("http://127.0.0.1:18080/webapp/index.jsp";);
+        InputStream stream = url.openStream();
+        StringBuffer sb = new StringBuffer();
+        for (int i = stream.read(); i != -1; i = stream.read()) {
+            sb.append((char)i);
+        }
+        String value = sb.toString();
+        assertTrue(value, value.contains("Hello"));
+    }
+    
+    public void tearDown() throws Exception {
+        if (server != null) server.stop();
+    }
+}


Reply via email to