jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From juanpa...@apache.org
Subject svn commit: r1689767 - in /jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki: TestEngine.java WikiEngineTest.java providers/FileSystemProviderTest.java
Date Tue, 07 Jul 2015 23:03:10 GMT
Author: juanpablo
Date: Tue Jul  7 23:03:09 2015
New Revision: 1689767

URL: http://svn.apache.org/r1689767
Log:
cleanTestProps was removing too much numbers on pageDir (JSPWIKI-821 related). If you were
compiling on a directory containing numbers, this was causing test failures.

As a side-effect of this change, FileSystemProviderTest.setUp and WikiEngineTest.testNonExistentDirectory
had to be adjusted as well.

Modified:
    jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/TestEngine.java
    jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/WikiEngineTest.java
    jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/providers/FileSystemProviderTest.java

Modified: jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/TestEngine.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/TestEngine.java?rev=1689767&r1=1689766&r2=1689767&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/TestEngine.java (original)
+++ jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/TestEngine.java Tue Jul  7 23:03:09
2015
@@ -30,10 +30,6 @@ import java.util.Properties;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 
-import net.sourceforge.stripes.mock.MockHttpServletRequest;
-import net.sourceforge.stripes.mock.MockHttpSession;
-import net.sourceforge.stripes.mock.MockServletContext;
-
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.apache.wiki.api.exceptions.ProviderException;
@@ -51,6 +47,10 @@ import org.apache.wiki.util.FileUtil;
 import org.apache.wiki.util.PropertyReader;
 import org.apache.wiki.util.TextUtil;
 
+import net.sourceforge.stripes.mock.MockHttpServletRequest;
+import net.sourceforge.stripes.mock.MockHttpSession;
+import net.sourceforge.stripes.mock.MockServletContext;
+
 /**
  *  Simple test engine that always assumes pages are found.
  */
@@ -234,14 +234,13 @@ public class TestEngine extends WikiEngi
 
                 if( files != null )
                 {
-                    for( int i = 0; i < files.length; i++ )
-                    {
-                        if( files[i].isDirectory() )
+                    for (File file2 : files) {
+                        if( file2.isDirectory() )
                         {
-                            deleteAll(files[i]);
+                            deleteAll(file2);
                         }
 
-                        files[i].delete();
+                        file2.delete();
                     }
                 }
             }
@@ -284,8 +283,9 @@ public class TestEngine extends WikiEngi
             // Remove the property file, too
             f = new File( files, mangleName(name)+".properties" );
 
-            if( f.exists() )
-                f.delete();
+            if( f.exists() ) {
+				f.delete();
+			}
 
             deleteAttachments( name );
             firePageEvent( WikiPageEvent.PAGE_DELETED, name );
@@ -411,10 +411,11 @@ public class TestEngine extends WikiEngi
     private static Properties cleanTestProps( Properties props )
     {
         String pageDir = props.getProperty( "jspwiki.fileSystemProvider.pageDir" );
+        String stripNumbers = pageDir.substring( pageDir.lastIndexOf( '/' ) );
         props.put( AuthenticationManager.PROP_LOGIN_THROTTLING, "false" );
         props.setProperty( "jspwiki.fileSystemProvider.pageDir",
-                           pageDir.replaceAll( "\\d", StringUtils.EMPTY )
-                           + System.currentTimeMillis() );
+        		           pageDir.substring( 0, pageDir.lastIndexOf( '/' ) ) +
+        		           stripNumbers.replaceAll( "\\d", StringUtils.EMPTY ) + System.currentTimeMillis()
);
         return props;
     }
 

Modified: jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/WikiEngineTest.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/WikiEngineTest.java?rev=1689767&r1=1689766&r2=1689767&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/WikiEngineTest.java (original)
+++ jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/WikiEngineTest.java Tue Jul  7
23:03:09 2015
@@ -92,7 +92,7 @@ public class WikiEngineTest extends Test
     public void testNonExistentDirectory()
         throws Exception
     {
-        String tmpdir = "." + File.separator  + "target";
+        String tmpdir = "./target";
         String dirname = "non-existent-directory";
         String newdir = tmpdir + File.separator + dirname;
 

Modified: jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/providers/FileSystemProviderTest.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/providers/FileSystemProviderTest.java?rev=1689767&r1=1689766&r2=1689767&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/providers/FileSystemProviderTest.java
(original)
+++ jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/providers/FileSystemProviderTest.java
Tue Jul  7 23:03:09 2015
@@ -1,4 +1,4 @@
-/* 
+/*
     Licensed to the Apache Software Foundation (ASF) under one
     or more contributor license agreements.  See the NOTICE file
     distributed with this work for additional information
@@ -14,7 +14,7 @@
     "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.  
+    under the License.
  */
 
 package org.apache.wiki.providers;
@@ -24,10 +24,6 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.Properties;
 
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
 import org.apache.log4j.PropertyConfigurator;
 import org.apache.wiki.PageManager;
 import org.apache.wiki.TestEngine;
@@ -35,6 +31,10 @@ import org.apache.wiki.WikiEngine;
 import org.apache.wiki.WikiPage;
 import org.apache.wiki.util.FileUtil;
 
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
 
 public class FileSystemProviderTest extends TestCase {
 
@@ -49,24 +49,26 @@ public class FileSystemProviderTest exte
         super( s );
     }
 
-    public void setUp() throws Exception {
-        m_pagedir = "." + File.separatorChar + "target" + File.separatorChar + "jspwiki.test.pages";
+    @Override
+	public void setUp() throws Exception {
+        m_pagedir = "./target/jspwiki.test.pages";
         props.setProperty( PageManager.PROP_PAGEPROVIDER, "FileSystemProvider" );
         props.setProperty( FileSystemProvider.PROP_PAGEDIR, m_pagedir );
 
         Properties props2 = new Properties();
         PropertyConfigurator.configure( props2 );
-        
+
         m_engine = new TestEngine(props);
         m_provider = new FileSystemProvider();
         m_provider.initialize( m_engine, props );
-        
+
         props.setProperty( WikiEngine.PROP_ENCODING, "UTF-8" );
         m_providerUTF8 = new FileSystemProvider();
         m_providerUTF8.initialize( m_engine, props );
     }
 
-    public void tearDown() {
+    @Override
+	public void tearDown() {
         TestEngine.deleteAll( new File( props.getProperty( FileSystemProvider.PROP_PAGEDIR
) ) );
     }
 
@@ -74,13 +76,13 @@ public class FileSystemProviderTest exte
         WikiPage page = new WikiPage(m_engine, "\u00c5\u00e4Test");
 
         m_provider.putPageText( page, "test" );
-        
+
         File resultfile = new File(  props.getProperty( FileSystemProvider.PROP_PAGEDIR )
, "%C5%E4Test.txt" );
-        
+
         assertTrue("No such file", resultfile.exists());
-        
+
         String contents = FileUtil.readContents( new FileInputStream(resultfile), "ISO-8859-1"
);
-        
+
         assertEquals("Wrong contents", contents, "test");
     }
 
@@ -109,14 +111,14 @@ public class FileSystemProviderTest exte
         WikiPage page = new WikiPage(m_engine, "Test/Foobar");
 
         m_providerUTF8.putPageText( page, "test" );
-        
+
         File resultfile = new File(  props.getProperty( FileSystemProvider.PROP_PAGEDIR )
, "Test%2FFoobar.txt" );
-        
+
         assertTrue("No such file", resultfile.exists());
-        
+
         String contents = FileUtil.readContents( new FileInputStream(resultfile),
                                                  "UTF-8" );
-        
+
         assertEquals("Wrong contents", contents, "test");
     }
 
@@ -126,14 +128,14 @@ public class FileSystemProviderTest exte
         WikiPage page = new WikiPage(m_engine, "Test/Foobar");
 
         m_provider.putPageText( page, "test" );
-   
+
         File resultfile = new File(  props.getProperty( FileSystemProvider.PROP_PAGEDIR )
, "Test%2FFoobar.txt" );
-   
+
         assertTrue("No such file", resultfile.exists());
-   
+
         String contents = FileUtil.readContents( new FileInputStream(resultfile),
                                                  "ISO-8859-1" );
-   
+
         assertEquals("Wrong contents", contents, "test");
     }
 
@@ -152,7 +154,7 @@ public class FileSystemProviderTest exte
 
         assertEquals("Wrong contents", contents, "test");
     }
-    
+
     public void testAuthor()
         throws Exception
     {
@@ -189,7 +191,7 @@ public class FileSystemProviderTest exte
 
         Properties pr = new Properties();
 
-        pr.setProperty( FileSystemProvider.PROP_PAGEDIR, 
+        pr.setProperty( FileSystemProvider.PROP_PAGEDIR,
                            newdir );
 
         FileSystemProvider test = new FileSystemProvider();
@@ -215,7 +217,7 @@ public class FileSystemProviderTest exte
 
             Properties pr = new Properties();
 
-            pr.setProperty( FileSystemProvider.PROP_PAGEDIR, 
+            pr.setProperty( FileSystemProvider.PROP_PAGEDIR,
                                tmpFile.getAbsolutePath() );
 
             FileSystemProvider test = new FileSystemProvider();
@@ -247,25 +249,25 @@ public class FileSystemProviderTest exte
 
         WikiPage p = new WikiPage(m_engine,"Test");
         p.setAuthor("AnonymousCoward");
-        
+
         m_provider.putPageText( p, "v1" );
 
         File f = new File( files, "Test"+FileSystemProvider.FILE_EXT );
 
         assertTrue( "file does not exist", f.exists() );
-        
+
         f = new File( files, "Test.properties" );
-        
+
         assertTrue( "property file does not exist", f.exists() );
-        
+
         m_provider.deletePage( "Test" );
 
         f = new File( files, "Test"+FileSystemProvider.FILE_EXT );
 
         assertFalse( "file exists", f.exists() );
-        
+
         f = new File( files, "Test.properties" );
-        
+
         assertFalse( "properties exist", f.exists() );
     }
 



Mime
View raw message