jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From juanpa...@apache.org
Subject svn commit: r1689764 - /jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/WikiEngineTest.java
Date Tue, 07 Jul 2015 22:48:54 GMT
Author: juanpablo
Date: Tue Jul  7 22:48:54 2015
New Revision: 1689764

URL: http://svn.apache.org/r1689764
Log:
testNonExistentDirectory searches inside ./target to avoid file permission related issues

lots of white space cleaning

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

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=1689764&r1=1689763&r2=1689764&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
22:48:54 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;
@@ -24,11 +24,6 @@ import java.util.Collection;
 import java.util.Iterator;
 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;
@@ -37,6 +32,11 @@ import org.apache.wiki.providers.FileSys
 import org.apache.wiki.providers.VerySimpleProvider;
 import org.apache.wiki.util.TextUtil;
 
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import net.sf.ehcache.CacheManager;
+
 public class WikiEngineTest extends TestCase
 {
     public static final String NAME1 = "Test1";
@@ -62,7 +62,8 @@ public class WikiEngineTest extends Test
         junit.textui.TestRunner.main(new String[] { WikiEngineTest.class.getName() } );
     }
 
-    public void setUp()
+    @Override
+	public void setUp()
         throws Exception
     {
         props.setProperty( WikiEngine.PROP_MATCHPLURALS, "true" );
@@ -70,10 +71,11 @@ public class WikiEngineTest extends Test
         CacheManager.getInstance().removeAllCaches();
 
         TestEngine.emptyWorkDir();
-        m_engine = new TestEngine(props);        
+        m_engine = new TestEngine(props);
     }
 
-    public void tearDown()
+    @Override
+	public void tearDown()
     {
         String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
 
@@ -86,11 +88,11 @@ public class WikiEngineTest extends Test
 
         TestEngine.emptyWorkDir();
     }
-    
+
     public void testNonExistentDirectory()
         throws Exception
     {
-        String tmpdir = System.getProperties().getProperty("java.io.tmpdir");
+        String tmpdir = "." + File.separator  + "target";
         String dirname = "non-existent-directory";
         String newdir = tmpdir + File.separator + dirname;
 
@@ -164,7 +166,7 @@ public class WikiEngineTest extends Test
         assertEquals( "singular mistake", "Foobars",
                       m_engine.getFinalPageName( "Foobar" ) );
     }
-    
+
     public void testPutPage()
         throws Exception
     {
@@ -260,7 +262,7 @@ public class WikiEngineTest extends Test
         String src="Foobar. [Foobar].  Frobozz.  [This is a link].";
 
         Object[] result = m_engine.scanWikiLinks( new WikiPage(m_engine, "Test"), src ).toArray();
-        
+
         assertEquals( "item 0", "Foobar", result[0] );
         assertEquals( "item 1", "This is a link", result[1] );
     }
@@ -331,7 +333,7 @@ public class WikiEngineTest extends Test
     public void testLatestGet()
         throws Exception
     {
-        props.setProperty( "jspwiki.pageProvider", 
+        props.setProperty( "jspwiki.pageProvider",
                            "org.apache.wiki.providers.VerySimpleProvider" );
         props.setProperty( "jspwiki.usePageCache", "false" );
 
@@ -349,7 +351,7 @@ public class WikiEngineTest extends Test
     public void testLatestGet2()
         throws Exception
     {
-        props.setProperty( "jspwiki.pageProvider", 
+        props.setProperty( "jspwiki.pageProvider",
                            "org.apache.wiki.providers.VerySimpleProvider" );
         props.setProperty( "jspwiki.usePageCache", "false" );
 
@@ -367,7 +369,7 @@ public class WikiEngineTest extends Test
     public void testLatestGet3()
         throws Exception
     {
-        props.setProperty( "jspwiki.pageProvider", 
+        props.setProperty( "jspwiki.pageProvider",
                            "org.apache.wiki.providers.VerySimpleProvider" );
         props.setProperty( "jspwiki.usePageCache", "false" );
 
@@ -385,7 +387,7 @@ public class WikiEngineTest extends Test
     public void testLatestGet4()
         throws Exception
     {
-        props.setProperty( "jspwiki.pageProvider", 
+        props.setProperty( "jspwiki.pageProvider",
                            "org.apache.wiki.providers.VerySimpleProvider" );
         props.setProperty( "jspwiki.usePageCache", "true" );
 
@@ -409,7 +411,7 @@ public class WikiEngineTest extends Test
     {
         ReferenceManager refMgr = m_engine.getReferenceManager();
         AttachmentManager attMgr = m_engine.getAttachmentManager();
-        
+
         m_engine.saveText( NAME1, "fooBar");
 
         Attachment att = new Attachment( m_engine, NAME1, "TestAtt.txt" );
@@ -417,23 +419,23 @@ public class WikiEngineTest extends Test
         attMgr.storeAttachment( att, m_engine.makeAttachmentFile() );
 
         try
-        {    
-            // and check post-conditions        
+        {
+            // and check post-conditions
             Collection c = refMgr.findUncreated();
-            assertTrue("attachment exists: "+c,            
+            assertTrue("attachment exists: "+c,
                        c==null || c.size()==0 );
-    
+
             c = refMgr.findUnreferenced();
             assertEquals( "unreferenced count", 2, c.size() );
             Iterator< String > i = c.iterator();
             String first = i.next();
             String second = i.next();
-            assertTrue( "unreferenced",            
+            assertTrue( "unreferenced",
                         (first.equals( NAME1 ) && second.equals( NAME1+"/TestAtt.txt"))
                         || (first.equals( NAME1+"/TestAtt.txt" ) && second.equals(
NAME1 )) );
         }
         finally
-        { 
+        {
             // do cleanup
             String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
             TestEngine.deleteAll( new File( files, NAME1+BasicAttachmentProvider.DIR_EXTENSION
) );
@@ -441,7 +443,7 @@ public class WikiEngineTest extends Test
     }
 
     /**
-     *  Is ReferenceManager updated properly if a page references 
+     *  Is ReferenceManager updated properly if a page references
      *  its own attachments?
      */
 
@@ -465,55 +467,55 @@ public class WikiEngineTest extends Test
     {
         ReferenceManager refMgr = m_engine.getReferenceManager();
         AttachmentManager attMgr = m_engine.getAttachmentManager();
-        
+
         m_engine.saveText( NAME1, "[TestAtt.txt]");
 
         // check a few pre-conditions
-        
+
         Collection c = refMgr.findReferrers( "TestAtt.txt" );
-        assertTrue( "normal, unexisting page", 
+        assertTrue( "normal, unexisting page",
                     c!=null && ((String)c.iterator().next()).equals( NAME1 ) );
-        
+
         c = refMgr.findReferrers( NAME1+"/TestAtt.txt" );
         assertTrue( "no attachment", c==null || c.size()==0 );
-        
+
         c = refMgr.findUncreated();
-        assertTrue( "unknown attachment", 
-                    c!=null && 
-                    c.size()==1 && 
+        assertTrue( "unknown attachment",
+                    c!=null &&
+                    c.size()==1 &&
                     ((String)c.iterator().next()).equals( "TestAtt.txt" ) );
-        
+
         // now we create the attachment
-            
+
         Attachment att = new Attachment( m_engine, NAME1, "TestAtt.txt" );
         att.setAuthor( "FirstPost" );
         attMgr.storeAttachment( att, m_engine.makeAttachmentFile() );
         try
-        {    
-            // and check post-conditions        
+        {
+            // and check post-conditions
             c = refMgr.findUncreated();
-            assertTrue( "attachment exists: ",            
+            assertTrue( "attachment exists: ",
                         c==null || c.size()==0 );
-    
+
             c = refMgr.findReferrers( "TestAtt.txt" );
             assertTrue( "no normal page", c==null || c.size()==0 );
-    
+
             c = refMgr.findReferrers( NAME1+"/TestAtt.txt" );
             assertTrue( "attachment exists now", c!=null && ((String)c.iterator().next()).equals(
NAME1 ) );
 
             c = refMgr.findUnreferenced();
-            assertTrue( "unreferenced",            
+            assertTrue( "unreferenced",
                         c.size()==1 && ((String)c.iterator().next()).equals( NAME1
));
         }
         finally
-        { 
+        {
             // do cleanup
             String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
             TestEngine.deleteAll( new File( files, NAME1+BasicAttachmentProvider.DIR_EXTENSION
) );
         }
     }
 
-    /** 
+    /**
      *  Checks, if ReferenceManager is informed if a link to an attachment is added.
      */
     public void testAttachmentRefs3()
@@ -521,7 +523,7 @@ public class WikiEngineTest extends Test
     {
         ReferenceManager refMgr = m_engine.getReferenceManager();
         AttachmentManager attMgr = m_engine.getAttachmentManager();
-        
+
         m_engine.saveText( NAME1, "fooBar");
 
         Attachment att = new Attachment( m_engine, NAME1, "TestAtt.txt" );
@@ -531,26 +533,26 @@ public class WikiEngineTest extends Test
         m_engine.saveText( NAME1, " ["+NAME1+"/TestAtt.txt] ");
 
         try
-        {    
-            // and check post-conditions        
+        {
+            // and check post-conditions
             Collection c = refMgr.findUncreated();
-            assertTrue( "attachment exists",            
+            assertTrue( "attachment exists",
                         c==null || c.size()==0 );
-    
+
             c = refMgr.findUnreferenced();
             assertEquals( "unreferenced count", c.size(), 1 );
-            assertTrue( "unreferenced",            
+            assertTrue( "unreferenced",
                         ((String)c.iterator().next()).equals( NAME1 ) );
         }
         finally
-        { 
+        {
             // do cleanup
             String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
             TestEngine.deleteAll( new File( files, NAME1+BasicAttachmentProvider.DIR_EXTENSION
) );
         }
     }
-    
-    /** 
+
+    /**
      *  Checks, if ReferenceManager is informed if a third page references an attachment.
      */
     public void testAttachmentRefs4()
@@ -558,7 +560,7 @@ public class WikiEngineTest extends Test
     {
         ReferenceManager refMgr = m_engine.getReferenceManager();
         AttachmentManager attMgr = m_engine.getAttachmentManager();
-        
+
         m_engine.saveText( NAME1, "[TestPage2]");
 
         Attachment att = new Attachment( m_engine, NAME1, "TestAtt.txt" );
@@ -568,28 +570,28 @@ public class WikiEngineTest extends Test
         m_engine.saveText( "TestPage2", "["+NAME1+"/TestAtt.txt]");
 
         try
-        {    
-            // and check post-conditions        
+        {
+            // and check post-conditions
             Collection c = refMgr.findUncreated();
-            assertTrue( "attachment exists",            
+            assertTrue( "attachment exists",
                         c==null || c.size()==0 );
-    
+
             c = refMgr.findUnreferenced();
             assertEquals( "unreferenced count", c.size(), 1 );
-            assertTrue( "unreferenced",            
+            assertTrue( "unreferenced",
                         ((String)c.iterator().next()).equals( NAME1 ) );
         }
         finally
-        { 
+        {
             // do cleanup
             String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
             TestEngine.deleteAll( new File( files, NAME1+BasicAttachmentProvider.DIR_EXTENSION
) );
             new File( files, "TestPage2"+FileSystemProvider.FILE_EXT ).delete();
         }
-    }    
+    }
+
 
 
-    
 
     public void testDeletePage()
         throws Exception
@@ -617,17 +619,17 @@ public class WikiEngineTest extends Test
         Attachment att = new Attachment( m_engine, NAME1, "TestAtt.txt" );
         att.setAuthor( "FirstPost" );
         m_engine.getAttachmentManager().storeAttachment( att, m_engine.makeAttachmentFile()
);
-        
+
         String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
         File saved = new File( files, NAME1+FileSystemProvider.FILE_EXT );
 
         String atts = props.getProperty( BasicAttachmentProvider.PROP_STORAGEDIR );
         File attfile = new File( atts, NAME1+"-att/TestAtt.txt-dir" );
-        
+
         assertTrue( "Didn't create it!", saved.exists() );
 
         assertTrue( "Attachment dir does not exist", attfile.exists() );
-        
+
         WikiPage page = m_engine.getPage( NAME1, WikiProvider.LATEST_VERSION );
 
         m_engine.deletePage( page.getName() );
@@ -644,40 +646,40 @@ public class WikiEngineTest extends Test
         Attachment att = new Attachment( m_engine, NAME1, "TestAtt.txt" );
         att.setAuthor( "FirstPost" );
         m_engine.getAttachmentManager().storeAttachment( att, m_engine.makeAttachmentFile()
);
-        
+
         String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
         File saved = new File( files, NAME1+FileSystemProvider.FILE_EXT );
 
         String atts = props.getProperty( BasicAttachmentProvider.PROP_STORAGEDIR );
         File attfile = new File( atts, NAME1+"-att/TestAtt.txt-dir" );
-        
+
         assertTrue( "Didn't create it!", saved.exists() );
 
         assertTrue( "Attachment dir does not exist", attfile.exists() );
-        
+
         WikiPage page = m_engine.getPage( NAME1, WikiProvider.LATEST_VERSION );
 
         assertNotNull( "page", page );
 
         att = m_engine.getAttachmentManager().getAttachmentInfo(NAME1+"/TestAtt.txt");
-        
+
         m_engine.deletePage(att.getName());
-        
+
         m_engine.deletePage( NAME1 );
-        
+
         assertNull( "Page not removed", m_engine.getPage(NAME1) );
         assertNull( "Att not removed", m_engine.getPage(NAME1+"/TestAtt.txt") );
-        
+
         Collection refs = m_engine.getReferenceManager().findReferrers(NAME1);
-        
+
         assertNull( "referrers", refs );
     }
-    
+
     public void testDeleteVersion()
         throws Exception
     {
         props.setProperty( "jspwiki.pageProvider", "VersioningFileProvider" );
-        
+
         TestEngine engine = new TestEngine( props );
         engine.saveText( NAME1, "Test1" );
         engine.saveText( NAME1, "Test2" );
@@ -686,11 +688,11 @@ public class WikiEngineTest extends Test
         WikiPage page = engine.getPage( NAME1, 3 );
 
         engine.deleteVersion( page );
-        
+
         assertNull( "got page", engine.getPage( NAME1, 3 ) );
-        
+
         String content = engine.getText( NAME1, WikiProvider.LATEST_VERSION );
-        
+
         assertEquals( "content", "Test2", content.trim() );
     }
 
@@ -698,22 +700,22 @@ public class WikiEngineTest extends Test
         throws Exception
     {
         props.setProperty( "jspwiki.pageProvider", "VersioningFileProvider" );
-    
+
         TestEngine engine = new TestEngine( props );
         engine.saveText( NAME1, "Test1" );
         engine.saveText( NAME1, "Test2" );
         engine.saveText( NAME1, "Test3" );
 
         WikiPage page = engine.getPage( NAME1, 1 );
-        
+
         engine.deleteVersion( page );
-        
+
         assertNull( "got page", engine.getPage( NAME1, 1 ) );
-        
+
         String content = engine.getText( NAME1, WikiProvider.LATEST_VERSION );
-        
+
         assertEquals( "content", "Test3", content.trim() );
-        
+
         assertEquals( "content1", "", engine.getText(NAME1, 1).trim() );
     }
 
@@ -724,34 +726,34 @@ public class WikiEngineTest extends Test
      */
     public void testOldVersionVars()
         throws Exception
-    {   
+    {
         Properties props = TestEngine.getTestProperties("/jspwiki-vers-custom.properties");
 
         props.setProperty( PageManager.PROP_USECACHE, "true" );
-        
+
         TestEngine engine = new TestEngine( props );
-        
+
         engine.saveText( NAME1, "[{SET foo=bar}]" );
-    
+
         engine.saveText( NAME1, "[{SET foo=notbar}]");
-    
+
         WikiPage v1 = engine.getPage( NAME1, 1 );
-        
+
         WikiPage v2 = engine.getPage( NAME1, 2 );
-        
+
         assertEquals( "V1", "bar", v1.getAttribute("foo") );
-        
+
         // FIXME: The following must run as well
         assertEquals( "V2", "notbar", v2.getAttribute("foo") );
-        
+
         engine.deletePage( NAME1 );
     }
-    
+
     public void testSpacedNames1()
         throws Exception
     {
         m_engine.saveText("This is a test", "puppaa");
-        
+
         assertEquals( "normal", "puppaa", m_engine.getText("This is a test").trim() );
     }
 
@@ -759,47 +761,47 @@ public class WikiEngineTest extends Test
     public void testParsedVariables() throws Exception
     {
         m_engine.saveText( "TestPage", "[{SET foo=bar}][{SamplePlugin text='{$foo}'}]");
-        
+
         String res = m_engine.getHTML( "TestPage" );
-        
+
         assertEquals( "bar\n", res );
     }
-    
+
     /**
      * Tests BugReferenceToRenamedPageNotCleared
-     * 
+     *
      * @throws Exception
      */
     public void testRename() throws Exception
     {
         m_engine.saveText( "RenameBugTestPage", "Mary had a little generic object" );
         m_engine.saveText( "OldNameTestPage", "Linked to RenameBugTestPage" );
-       
+
         Collection pages = m_engine.getReferenceManager().findReferrers( "RenameBugTestPage"
);
         assertEquals( "has one", "OldNameTestPage", pages.iterator().next() );
-        
+
         WikiContext ctx = new WikiContext( m_engine, m_engine.getPage("OldNameTestPage")
);
-        
+
         m_engine.renamePage( ctx, "OldNameTestPage", "NewNameTestPage", true );
-            
+
         assertFalse( "did not vanish", m_engine.pageExists( "OldNameTestPage") );
         assertTrue( "did not appear", m_engine.pageExists( "NewNameTestPage") );
-        
+
         pages = m_engine.getReferenceManager().findReferrers( "RenameBugTestPage" );
-        
+
         assertEquals( "wrong # of referrers", 1, pages.size() );
-        
-        assertEquals( "has wrong referrer", "NewNameTestPage", pages.iterator().next() );
       
+
+        assertEquals( "has wrong referrer", "NewNameTestPage", pages.iterator().next() );
     }
-    
+
     public void testChangeNoteOldVersion2() throws Exception
     {
         WikiPage p = new WikiPage( m_engine, NAME1 );
-    
+
         WikiContext context = new WikiContext(m_engine,p);
 
         context.getPage().setAttribute( WikiPage.CHANGENOTE, "Test change" );
-        
+
         m_engine.saveText( context, "test" );
 
         for( int i = 0; i < 5; i++ )
@@ -813,15 +815,15 @@ public class WikiEngineTest extends Test
         }
 
         WikiPage p3 = m_engine.getPage( NAME1, -1 );
-    
+
         assertEquals( null, p3.getAttribute(WikiPage.CHANGENOTE) );
     }
-    
-    public void testCreatePage() throws Exception 
+
+    public void testCreatePage() throws Exception
     {
         String text = "Foobar.\r\n";
         String name = "mrmyxpltz";
-        
+
         assertEquals( "page should not exist right now",
                       false,
                       m_engine.pageExists( name ) );
@@ -832,12 +834,12 @@ public class WikiEngineTest extends Test
                       true,
                       m_engine.pageExists( name ) );
     }
-    
-    public void testCreateEmptyPage() throws Exception 
+
+    public void testCreateEmptyPage() throws Exception
     {
         String text = "";
         String name = "mrmxyzptlk";
-        
+
         assertEquals( "page should not exist right now",
                       false,
                       m_engine.pageExists( name ) );
@@ -848,29 +850,29 @@ public class WikiEngineTest extends Test
                       false,
                       m_engine.pageExists( name ) );
     }
-    
-    public void testSaveExistingPageWithEmptyContent() throws Exception 
+
+    public void testSaveExistingPageWithEmptyContent() throws Exception
     {
         String text = "Foobar.\r\n";
         String name = NAME1;
-        
+
         m_engine.saveText( name, text );
 
         assertEquals( "page does not exist",
                       true,
                       m_engine.pageExists( name ) );
-        
+
         // saveText uses normalizePostData to assure it conforms to certain rules
         assertEquals( "wrong content",
                       TextUtil.normalizePostData( text ),
                       m_engine.getText( name ) );
-        
+
         m_engine.saveText( name, "" );
-        
+
         assertEquals( "wrong content",
-                      TextUtil.normalizePostData( "" ), 
+                      TextUtil.normalizePostData( "" ),
                       m_engine.getText( name ) );
-        
+
     }
 
 }



Mime
View raw message