jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From juanpa...@apache.org
Subject svn commit: r1567444 - in /jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki: TestEngine.java WikiEngineTest.java providers/FileSystemProviderTest.java
Date Tue, 11 Feb 2014 23:10:11 GMT
Author: juanpablo
Date: Tue Feb 11 23:10:10 2014
New Revision: 1567444

URL: http://svn.apache.org/r1567444
Log:
* TestEngine( Properties ) sets up a different directory each time is instanciated as page
repo, and also cleans EhCache if it's used (JSPWIKI-813 related)

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=1567444&r1=1567443&r2=1567444&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 Feb 11 23:10:10
2014
@@ -23,7 +23,6 @@ import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.StringReader;
 import java.util.Locale;
 import java.util.Properties;
@@ -136,8 +135,7 @@ public class TestEngine extends WikiEngi
      * HttpSession.
      * @return the new request
      */
-    public MockHttpServletRequest newHttpRequest()
-    {
+    public MockHttpServletRequest newHttpRequest() {
         return newHttpRequest( "/Wiki.jsp" );
     }
 
@@ -147,8 +145,7 @@ public class TestEngine extends WikiEngi
      * @param path the path relative to the wiki context, for example "/Wiki.jsp"
      * @return the new request
      */
-    public MockHttpServletRequest newHttpRequest( String path )
-    {
+    public MockHttpServletRequest newHttpRequest( String path ) {
         MockHttpServletRequest request = new MockHttpServletRequest( "/JSPWiki", path );
         request.setSession( new MockHttpSession( this.getServletContext() ) );
         request.addLocale( new Locale( "" ) );
@@ -411,6 +408,8 @@ public class TestEngine extends WikiEngi
     private static Properties cleanTestProps( Properties props )
     {
         props.put( AuthenticationManager.PROP_LOGIN_THROTTLING, "false" );
+        props.setProperty( "jspwiki.fileSystemProvider.pageDir", 
+                           props.getProperty( "jspwiki.fileSystemProvider.pageDir" ) + 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=1567444&r1=1567443&r2=1567444&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 Feb 11
23:10:10 2014
@@ -20,8 +20,6 @@
 package org.apache.wiki;
 
 import java.io.File;
-import java.io.FileWriter;
-import java.io.StringReader;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.Properties;
@@ -29,15 +27,14 @@ import java.util.Properties;
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
-
 import net.sf.ehcache.CacheManager;
+
 import org.apache.wiki.attachment.Attachment;
 import org.apache.wiki.attachment.AttachmentManager;
 import org.apache.wiki.providers.BasicAttachmentProvider;
 import org.apache.wiki.providers.CachingProvider;
 import org.apache.wiki.providers.FileSystemProvider;
 import org.apache.wiki.providers.VerySimpleProvider;
-import org.apache.wiki.util.FileUtil;
 import org.apache.wiki.util.TextUtil;
 
 public class WikiEngineTest extends TestCase
@@ -95,16 +92,12 @@ public class WikiEngineTest extends Test
     {
         String tmpdir = System.getProperties().getProperty("java.io.tmpdir");
         String dirname = "non-existent-directory";
-
         String newdir = tmpdir + File.separator + dirname;
 
-        props.setProperty( FileSystemProvider.PROP_PAGEDIR, 
-                           newdir );
-
+        props.setProperty( FileSystemProvider.PROP_PAGEDIR, newdir );
         new TestEngine( props );
 
-        File f = new File( newdir );
-
+        File f = new File( props.getProperty( FileSystemProvider.PROP_PAGEDIR ) );
         assertTrue( "didn't create it", f.exists() );
         assertTrue( "isn't a dir", f.isDirectory() );
 
@@ -432,9 +425,9 @@ public class WikiEngineTest extends Test
     
             c = refMgr.findUnreferenced();
             assertEquals( "unreferenced count", 2, c.size() );
-            Iterator i = c.iterator();
-            String first = (String) i.next();
-            String second = (String) i.next();
+            Iterator< String > i = c.iterator();
+            String first = i.next();
+            String second = i.next();
             assertTrue( "unreferenced",            
                         (first.equals( NAME1 ) && second.equals( NAME1+"/TestAtt.txt"))
                         || (first.equals( NAME1+"/TestAtt.txt" ) && second.equals(
NAME1 )) );

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=1567444&r1=1567443&r2=1567444&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 Feb 11 23:10:10 2014
@@ -35,8 +35,9 @@ import org.apache.wiki.WikiEngine;
 import org.apache.wiki.WikiPage;
 import org.apache.wiki.util.FileUtil;
 
-public class FileSystemProviderTest extends TestCase
-{
+
+public class FileSystemProviderTest extends TestCase {
+
     FileSystemProvider m_provider;
     FileSystemProvider m_providerUTF8;
     String             m_pagedir;
@@ -44,28 +45,20 @@ public class FileSystemProviderTest exte
 
     TestEngine         m_engine;
 
-    public FileSystemProviderTest( String s )
-    {
+    public FileSystemProviderTest( String s ) {
         super( s );
     }
 
-    public void setUp()
-        throws Exception
-    {
+    public void setUp() throws Exception {
         m_pagedir = System.getProperties().getProperty("java.io.tmpdir") + File.separatorChar
+ "jspwiki.test.pages";
-
-        Properties props2 = new Properties();
-
         props.setProperty( PageManager.PROP_PAGEPROVIDER, "FileSystemProvider" );
-        props.setProperty( FileSystemProvider.PROP_PAGEDIR, 
-                           m_pagedir );
+        props.setProperty( FileSystemProvider.PROP_PAGEDIR, m_pagedir );
 
-        PropertyConfigurator.configure(props2);
+        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" );
@@ -73,36 +66,30 @@ public class FileSystemProviderTest exte
         m_providerUTF8.initialize( m_engine, props );
     }
 
-    public void tearDown()
-    {
-        TestEngine.deleteAll( new File(m_pagedir) );
+    public void tearDown() {
+        TestEngine.deleteAll( new File( props.getProperty( FileSystemProvider.PROP_PAGEDIR
) ) );
     }
 
-    public void testScandinavianLetters()
-        throws Exception
-    {
+    public void testScandinavianLetters() throws Exception {
         WikiPage page = new WikiPage(m_engine, "\u00c5\u00e4Test");
 
         m_provider.putPageText( page, "test" );
         
-        File resultfile = new File( m_pagedir, "%C5%E4Test.txt" );
+        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" );
+        String contents = FileUtil.readContents( new FileInputStream(resultfile), "ISO-8859-1"
);
         
         assertEquals("Wrong contents", contents, "test");
     }
 
-    public void testScandinavianLettersUTF8()
-        throws Exception
-    {
+    public void testScandinavianLettersUTF8() throws Exception {
         WikiPage page = new WikiPage(m_engine, "\u00c5\u00e4Test");
 
         m_providerUTF8.putPageText( page, "test\u00d6" );
 
-        File resultfile = new File( m_pagedir, "%C3%85%C3%A4Test.txt" );
+        File resultfile = new File(  props.getProperty( FileSystemProvider.PROP_PAGEDIR )
, "%C3%85%C3%A4Test.txt" );
 
         assertTrue("No such file", resultfile.exists());
 
@@ -123,7 +110,7 @@ public class FileSystemProviderTest exte
 
         m_providerUTF8.putPageText( page, "test" );
         
-        File resultfile = new File( m_pagedir, "Test%2FFoobar.txt" );
+        File resultfile = new File(  props.getProperty( FileSystemProvider.PROP_PAGEDIR )
, "Test%2FFoobar.txt" );
         
         assertTrue("No such file", resultfile.exists());
         
@@ -140,7 +127,7 @@ public class FileSystemProviderTest exte
 
         m_provider.putPageText( page, "test" );
    
-        File resultfile = new File( m_pagedir, "Test%2FFoobar.txt" );
+        File resultfile = new File(  props.getProperty( FileSystemProvider.PROP_PAGEDIR )
, "Test%2FFoobar.txt" );
    
         assertTrue("No such file", resultfile.exists());
    
@@ -157,7 +144,7 @@ public class FileSystemProviderTest exte
 
         m_provider.putPageText( page, "test" );
 
-        File resultfile = new File( m_pagedir, "%2ETest.txt" );
+        File resultfile = new File(  props.getProperty( FileSystemProvider.PROP_PAGEDIR )
, "%2ETest.txt" );
 
         assertTrue("No such file", resultfile.exists());
 
@@ -182,28 +169,20 @@ public class FileSystemProviderTest exte
         }
         finally
         {
-            File resultfile = new File( m_pagedir,
-                                        "%C5%E4Test.txt" );
-            try
-            {
+            File resultfile = new File(  props.getProperty( FileSystemProvider.PROP_PAGEDIR
), "%C5%E4Test.txt" );
+            try {
                 resultfile.delete();
-            }
-            catch(Exception e) {}
+            } catch(Exception e) {}
 
-            resultfile = new File( m_pagedir,
-                                   "%C5%E4Test.properties" );
-            try
-            {
+            resultfile = new File(  props.getProperty( FileSystemProvider.PROP_PAGEDIR ),
"%C5%E4Test.properties" );
+            try {
                 resultfile.delete();
-            }
-            catch(Exception e) {}
+            } catch(Exception e) {}
         }
     }
 
-    public void testNonExistantDirectory()
-        throws Exception
-    {
-        String tmpdir = m_pagedir;
+    public void testNonExistantDirectory() throws Exception {
+        String tmpdir =  props.getProperty( FileSystemProvider.PROP_PAGEDIR ) ;
         String dirname = "non-existant-directory";
 
         String newdir = tmpdir + File.separator + dirname;



Mime
View raw message