Author: hlship
Date: Thu Dec 13 11:18:56 2007
New Revision: 603991

URL: http://svn.apache.org/viewvc?rev=603991&view=rev
Log:
Work-around brain damaged maven-surefire-plugin (which fails to set the current 
directory) so that tests run correctly from Maven

Added:
    
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry/test/TapestryTestConstants.java
Modified:
    tapestry/tapestry5/trunk/pom.xml
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ComponentResources.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/test/PageTesterContext.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/RunJetty.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/TemplateParserImplTest.java
    
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry/test/AbstractIntegrationTestSuite.java
    
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry/test/JettyRunner.java

Modified: tapestry/tapestry5/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/pom.xml?rev=603991&r1=603990&r2=603991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/pom.xml (original)
+++ tapestry/tapestry5/trunk/pom.xml Thu Dec 13 11:18:56 2007
@@ -232,7 +232,7 @@
                             
<suiteXmlFile>src/test/conf/testng.xml</suiteXmlFile>
                         </suiteXmlFiles>
                         <argLine>-Xmx500m</argLine>
-                        
<redirectTestOutputToFile>true</redirectTestOutputToFile>
+                        
<redirectTestOutputToFile>false</redirectTestOutputToFile>
                     </configuration>
                 </plugin>
                 <plugin>

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ComponentResources.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ComponentResources.java?rev=603991&r1=603990&r2=603991&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ComponentResources.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ComponentResources.java
 Thu Dec 13 11:18:56 2007
@@ -126,4 +126,5 @@
      * @return the informal Block parameter, or null if not bound
      */
     Block getBlockParameter(String parameterName);
+
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/test/PageTesterContext.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/test/PageTesterContext.java?rev=603991&r1=603990&r2=603991&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/test/PageTesterContext.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/test/PageTesterContext.java
 Thu Dec 13 11:18:56 2007
@@ -15,6 +15,7 @@
 package org.apache.tapestry.internal.test;
 
 import org.apache.tapestry.services.Context;
+import org.apache.tapestry.test.TapestryTestConstants;
 
 import java.io.File;
 import java.net.MalformedURLException;
@@ -23,11 +24,11 @@
 
 public class PageTesterContext implements Context
 {
-    private final String _contextRoot;
+    private final File _contextRoot;
 
     public PageTesterContext(String contextRoot)
     {
-        _contextRoot = contextRoot;
+        _contextRoot = new File(TapestryTestConstants.MODULE_BASE_DIR, 
contextRoot);
     }
 
     public String getInitParameter(String name)
@@ -55,14 +56,12 @@
 
     public List<String> getResourcePaths(String path)
     {
-        throw new UnsupportedOperationException(
-                "getResourcePaths() is not supported for 
ContextForPageTester.");
+        throw new UnsupportedOperationException("getResourcePaths() is not 
supported for ContextForPageTester.");
     }
 
     public Object getAttribute(String name)
     {
-        throw new UnsupportedOperationException(
-                "getAttribute() is not supported for ContextForPageTester.");
+        throw new UnsupportedOperationException("getAttribute() is not 
supported for ContextForPageTester.");
     }
 
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/RunJetty.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/RunJetty.java?rev=603991&r1=603990&r2=603991&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/RunJetty.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/RunJetty.java
 Thu Dec 13 11:18:56 2007
@@ -16,6 +16,8 @@
 
 import org.apache.tapestry.test.JettyRunner;
 
+import java.io.File;
+
 /**
  * A "shim" to run Demo App #1 inside IntelliJ.  I still haven't found a way 
to get IntelliJ to
  * export test classes and resources into a web facet.
@@ -27,6 +29,8 @@
         String contextName = args[0];
         String path = args[1];
 
-        new JettyRunner(contextName, 8080, path);
+        File workingDir = new File(System.getProperty("user.dir"));
+
+        new JettyRunner(workingDir, contextName, 8080, path);
     }
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/TemplateParserImplTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/TemplateParserImplTest.java?rev=603991&r1=603990&r2=603991&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/TemplateParserImplTest.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/TemplateParserImplTest.java
 Thu Dec 13 11:18:56 2007
@@ -22,6 +22,7 @@
 import org.apache.tapestry.ioc.internal.util.ClasspathResource;
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newSet;
 import org.apache.tapestry.ioc.internal.util.TapestryException;
+import org.apache.tapestry.test.TapestryTestConstants;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
@@ -449,9 +450,7 @@
 
         TextToken t1 = get(tokens, 1);
 
-        assertEquals(
-                t1.getText().replaceAll("\\s+", " "),
-                " ${expansions must be on a single line} ");
+        assertEquals(t1.getText().replaceAll("\\s+", " "), " ${expansions must 
be on a single line} ");
 
     }
 
@@ -553,28 +552,21 @@
     @DataProvider(name = "parse_failure_data")
     public Object[][] parse_failure_data()
     {
-        return new Object[][]
-                {
-                        {
-                                "mixin_requires_id_or_type.tml",
-                                "You may not specify mixins for element <span> 
because it does not represent a component (which requires either an id 
attribute or a type attribute).",
-                                2},
-                        {"illegal_nesting_within_body_element.tml",
-                         "Element 'xyz' is nested within a Tapestry body 
element", 2},
-                        {
-                                
"unexpected_attribute_in_parameter_element.tml",
-                                "Element <parameter> does not support an 
attribute named 'grok'. The only allowed attribute name is 'name'.",
-                                4},
-                        {"name_attribute_of_parameter_element_omitted.tml",
-                         "The name attribute of the <parameter> element must 
be specified.", 4},
-                        {"name_attribute_of_parameter_element_blank.tml",
-                         "The name attribute of the <parameter> element must 
be specified.", 4},
-                        {
-                                "unexpected_attribute_in_block_element.tml",
-                                "Element <block> does not support an attribute 
named 'name'. The only allowed attribute name is 'id'.",
-                                3},
+        return new Object[][]{{"mixin_requires_id_or_type.tml",
+                               "You may not specify mixins for element <span> 
because it does not represent a component (which requires either an id 
attribute or a type attribute).",
+                               2}, {"illegal_nesting_within_body_element.tml",
+                                    "Element 'xyz' is nested within a Tapestry 
body element", 2}, {
+                "unexpected_attribute_in_parameter_element.tml",
+                "Element <parameter> does not support an attribute named 
'grok'. The only allowed attribute name is 'name'.",
+                4}, {"name_attribute_of_parameter_element_omitted.tml",
+                     "The name attribute of the <parameter> element must be 
specified.", 4}, {
+                "name_attribute_of_parameter_element_blank.tml",
+                "The name attribute of the <parameter> element must be 
specified.", 4}, {
+                "unexpected_attribute_in_block_element.tml",
+                "Element <block> does not support an attribute named 'name'. 
The only allowed attribute name is 'id'.",
+                3},
 
-                };
+        };
     }
 
     @Test(dataProvider = "parse_failure_data")
@@ -589,11 +581,8 @@
         {
             if (!ex.getMessage().contains(errorMessageSubstring))
             {
-                throw new AssertionError(
-                        format(
-                                "Message [%s] does not contain substring 
[%s].",
-                                ex.getMessage(),
-                                errorMessageSubstring));
+                throw new AssertionError(format("Message [%s] does not contain 
substring [%s].", ex.getMessage(),
+                                                errorMessageSubstring));
             }
 
             assertEquals(ex.getLocation().getLine(), expectedLine);
@@ -603,11 +592,8 @@
     @DataProvider(name = "doctype_parsed_correctly_data")
     public Object[][] doctype_parsed_correctly_data()
     {
-        return new Object[][]
-                {
-                        {"xhtml1_strict_doctype.tml"},
-                        {"xhtml1_transitional_doctype.tml"},
-                        {"xhtml1_frameset_doctype.tml"}};
+        return new Object[][]{{"xhtml1_strict_doctype.tml"}, 
{"xhtml1_transitional_doctype.tml"},
+                              {"xhtml1_frameset_doctype.tml"}};
     }
 
     @Test(dataProvider = "doctype_parsed_correctly_data")
@@ -622,30 +608,36 @@
     @DataProvider(name = "doctype_token_added_correctly_data")
     public Object[][] doctype_token_added_correctly_data()
     {
-        return new Object[][]
-                {
-                        {"xhtml1_strict_doctype.tml", "html", "-//W3C//DTD 
XHTML 1.0 Strict//EN",
-                         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"},
-                        {"xhtml1_transitional_doctype.tml", "html",
-                         "-//W3C//DTD XHTML 1.0 Transitional//EN",
-                         
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"},
-                        {"xhtml1_frameset_doctype.tml", "html", "-//W3C//DTD 
XHTML 1.0 Frameset//EN",
-                         
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"},
-                        {"html4_strict_doctype.tml", "HTML", "-//W3C//DTD HTML 
4.01//EN",
-                         "http://www.w3.org/TR/html4/strict.dtd"},
-                        {"html4_transitional_doctype.tml", "HTML",
-                         "-//W3C//DTD HTML 4.01 Transitional//EN",
-                         "http://www.w3.org/TR/html4/loose.dtd"},
-                        {"html4_frameset_doctype.tml", "HTML", "-//W3C//DTD 
HTML 4.01 Frameset//EN",
-                         "http://www.w3.org/TR/html4/frameset.dtd"},
-                        {"system_doctype.xml", "foo", null,
-                         
"src/test/resources/org/apache/tapestry/internal/services/simple.dtd"}};
+        return new Object[][]{{"xhtml1_strict_doctype.tml", "html", 
"-//W3C//DTD XHTML 1.0 Strict//EN",
+                               
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"}, 
{"xhtml1_transitional_doctype.tml",
+                                                                               
       "html",
+                                                                               
       "-//W3C//DTD XHTML 1.0 Transitional//EN",
+                                                                               
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"},
+                                                                               
      {"xhtml1_frameset_doctype.tml",
+                                                                               
       "html",
+                                                                               
       "-//W3C//DTD XHTML 1.0 Frameset//EN",
+                                                                               
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"},
+                                                                               
      {"html4_strict_doctype.tml",
+                                                                               
       "HTML",
+                                                                               
       "-//W3C//DTD HTML 4.01//EN",
+                                                                               
       "http://www.w3.org/TR/html4/strict.dtd"},
+                                                                               
      {"html4_transitional_doctype.tml",
+                                                                               
       "HTML",
+                                                                               
       "-//W3C//DTD HTML 4.01 Transitional//EN",
+                                                                               
       "http://www.w3.org/TR/html4/loose.dtd"},
+                                                                               
      {"html4_frameset_doctype.tml",
+                                                                               
       "HTML",
+                                                                               
       "-//W3C//DTD HTML 4.01 Frameset//EN",
+                                                                               
       "http://www.w3.org/TR/html4/frameset.dtd"},
+                                                                               
      {"system_doctype.xml", "foo", null,
+                                                                               
       "src/test/resources/org/apache/tapestry/internal/services/simple.dtd"}};
     }
 
     @Test(dataProvider = "doctype_token_added_correctly_data")
-    public void doctype_added_correctly(String fileName, String name, String 
publicId,
-                                        String systemId) throws Exception
+    public void doctype_added_correctly(String fileName, String name, String 
publicId, String systemId) throws Exception
     {
+        System.setProperty("user.dir", 
TapestryTestConstants.MODULE_BASE_DIR_PATH);
+
         List<TemplateToken> tokens = tokens(fileName);
         DTDToken t2 = get(tokens, 0);
         assertEquals(t2.getName(), name);

Modified: 
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry/test/AbstractIntegrationTestSuite.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry/test/AbstractIntegrationTestSuite.java?rev=603991&r1=603990&r2=603991&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry/test/AbstractIntegrationTestSuite.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry/test/AbstractIntegrationTestSuite.java
 Thu Dec 13 11:18:56 2007
@@ -184,7 +184,7 @@
     @BeforeClass(alwaysRun = true)
     public void setup() throws Exception
     {
-        _jettyRunner = new JettyRunner("/", JETTY_PORT, _webappRoot);
+        _jettyRunner = new JettyRunner(TapestryTestConstants.MODULE_BASE_DIR, 
"/", JETTY_PORT, _webappRoot);
 
         _server = new SeleniumServer();
 

Modified: 
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry/test/JettyRunner.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry/test/JettyRunner.java?rev=603991&r1=603990&r2=603991&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry/test/JettyRunner.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry/test/JettyRunner.java
 Thu Dec 13 11:18:56 2007
@@ -19,6 +19,7 @@
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.servlet.WebApplicationContext;
 
+import java.io.File;
 import static java.lang.String.format;
 
 /**
@@ -33,6 +34,8 @@
 
     public static final int DEFAULT_PORT = 80;
 
+    private final File _workingDir;
+
     private final String _contextPath;
 
     private final int _port;
@@ -42,23 +45,17 @@
     private final Server _jetty;
 
     /**
-     * Defaults the context path to "/" and the port to 80.
-     */
-    public JettyRunner(String warPath)
-    {
-        this(DEFAULT_CONTEXT_PATH, DEFAULT_PORT, warPath);
-    }
-
-    /**
      * Creates and starts a new instance of Jetty. This should be done from a 
test case setup
      * method.
      *
+     * @param workingDir  current directory (used for any relative files)
      * @param contextPath the context path for the deployed application
      * @param port        the port number used to access the application
      * @param warPath     the path to the exploded web application (typically, 
"src/main/webapp")
      */
-    public JettyRunner(String contextPath, int port, String warPath)
+    public JettyRunner(File workingDir, String contextPath, int port, String 
warPath)
     {
+        _workingDir = workingDir;
         _contextPath = contextPath;
         _port = port;
         _warPath = warPath;
@@ -99,10 +96,14 @@
 
     private Server createAndStart()
     {
-        System.out.printf("Starting Jetty instance on port %d (%s mapped to 
%s)\n", _port, _contextPath, _warPath);
-
         try
         {
+
+            String warPath = new File(_workingDir, _warPath).getPath();
+            String webDefaults = new File(_workingDir, 
"src/test/conf/webdefault.xml").getPath();
+
+            System.out.printf("Starting Jetty instance on port %d (%s mapped 
to %s)\n", _port, _contextPath, warPath);
+
             Server server = new Server();
 
             SocketListener socketListener = new SocketListener();
@@ -112,9 +113,9 @@
             NCSARequestLog log = new NCSARequestLog();
             server.setRequestLog(log);
 
-            WebApplicationContext context = 
server.addWebApplication(_contextPath, _warPath);
+            WebApplicationContext context = 
server.addWebApplication(_contextPath, warPath);
 
-            context.setDefaultsDescriptor("src/test/conf/webdefault.xml");
+            context.setDefaultsDescriptor(webDefaults);
 
             server.start();
 

Added: 
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry/test/TapestryTestConstants.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry/test/TapestryTestConstants.java?rev=603991&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry/test/TapestryTestConstants.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry/test/TapestryTestConstants.java
 Thu Dec 13 11:18:56 2007
@@ -0,0 +1,38 @@
+// Copyright 2007 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.test;
+
+import java.io.File;
+
+public class TapestryTestConstants
+{
+    /**
+     * The current working directory (i.e., property "user.dir").
+     */
+    public static final String CURRENT_DIR_PATH = 
System.getProperty("user.dir");
+    /**
+     * The Surefire plugin sets basedir but DOES NOT change the current 
working directory.
+     * When building across modules, basedir changes for each module, but 
user.dir does not.
+     * This value should be used when referecing local files.  Outside of 
surefire, the
+     * "basedir" property will not be set, and the current working directory 
will be the
+     * default.
+     */
+    public static final String MODULE_BASE_DIR_PATH = 
System.getProperty("basedir", CURRENT_DIR_PATH);
+
+    /**
+     * [EMAIL PROTECTED] #MODULE_BASE_DIR_PATH} as a file.
+     */
+    public static final File MODULE_BASE_DIR = new File(MODULE_BASE_DIR_PATH);
+}


Reply via email to