You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2019/10/12 17:12:10 UTC

[jspwiki] branch master updated (f07c919 -> 077e44f)

This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git.


    from f07c919  2.11.0-M6-git-02
     new c68a5f1  change awaitility condition so it checks the file is actually on disk; if the OS persists in setting the same time, change page names so the assertions pass and leave it documented on the test
     new d1a2adc  PageTimeComparator unit tests
     new b62d8cf  TestEngine will generate separate page, attachment and work directories, in order to allow each instance to work with a clean file installation - no version bump
     new 88af1a2  adapt test to latest TestEngine change
     new 077e44f  update ChangeLog

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 ChangeLog                                          |  3 ++
 .../src/test/java/org/apache/wiki/TestEngine.java  | 23 ++++++---
 .../apache/wiki/pages/PageTimeComparatorTest.java  | 52 +++++++++++++++++++++
 .../providers/BasicAttachmentProviderTest.java     | 54 +++++++++++++---------
 .../wiki/providers/VersioningFileProviderTest.java | 23 +++++----
 5 files changed, 116 insertions(+), 39 deletions(-)
 create mode 100644 jspwiki-main/src/test/java/org/apache/wiki/pages/PageTimeComparatorTest.java


[jspwiki] 03/05: TestEngine will generate separate page, attachment and work directories, in order to allow each instance to work with a clean file installation - no version bump

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit b62d8cfd1a1219f0f61a6e377db0b50fc1f36fec
Author: juanpablo <ju...@apache.org>
AuthorDate: Sat Oct 12 19:10:57 2019 +0200

    TestEngine will generate separate page, attachment and work directories, in order to allow each instance to work with a clean file installation - no version bump
---
 .../src/test/java/org/apache/wiki/TestEngine.java  | 23 ++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/jspwiki-main/src/test/java/org/apache/wiki/TestEngine.java b/jspwiki-main/src/test/java/org/apache/wiki/TestEngine.java
index f9cc932..9eef99e 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/TestEngine.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/TestEngine.java
@@ -445,14 +445,25 @@ public class TestEngine extends WikiEngine
      * @return the corrected/clean properties
      */
     private static Properties cleanTestProps( final Properties props ) {
-        final String pageDir = props.getProperty( "jspwiki.fileSystemProvider.pageDir" );
-        final String stripNumbers = pageDir.substring( pageDir.lastIndexOf( '/' ) );
-        final String testDir = pageDir.substring( 0, pageDir.lastIndexOf( '/' ) ) +
-                               stripNumbers.replaceAll( "\\d", StringUtils.EMPTY ) + System.currentTimeMillis();
+        long millis = System.currentTimeMillis();
         props.put( AuthenticationManager.PROP_LOGIN_THROTTLING, "false" );
-        props.setProperty( "jspwiki.fileSystemProvider.pageDir", testDir );
-        props.setProperty( "jspwiki.basicAttachmentProvider.storageDir", testDir );
+        props.setProperty( "jspwiki.fileSystemProvider.pageDir", cleanNewDirFrom( props.getProperty( "jspwiki.fileSystemProvider.pageDir" ), millis ) );
+        props.setProperty( "jspwiki.basicAttachmentProvider.storageDir", cleanNewDirFrom( props.getProperty( "jspwiki.basicAttachmentProvider.storageDir" ), millis ) );
+        props.setProperty( "jspwiki.workDir", cleanNewDirFrom( props.getProperty( "jspwiki.workDir" ), millis ) );
         return props;
     }
 
+    private static String cleanNewDirFrom( final String pageDir, final long millis ) {
+        if( StringUtils.isBlank( pageDir ) ) {
+            return "";
+        }
+        if( pageDir.lastIndexOf( '/' ) == -1 ) {
+            return "target/" + millis + "-" + pageDir;
+        }
+        final String stripNumbers = pageDir.substring( pageDir.lastIndexOf( '/' ) );
+        return pageDir.substring( 0, pageDir.lastIndexOf( '/' ) + 1 )
+             + millis // place all related tests' folders one next to the others
+             + stripNumbers.replaceAll( "\\d", StringUtils.EMPTY );
+    }
+
 }


[jspwiki] 05/05: update ChangeLog

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit 077e44fa0f03e36e9aa5efda16d6fc4c5d24ac33
Author: juanpablo <ju...@apache.org>
AuthorDate: Sat Oct 12 19:11:40 2019 +0200

    update ChangeLog
---
 ChangeLog | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 12ec2a2..78c21f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,9 @@
          TestEngine instances to be built as member of test classes, instead of rebuilding for every test and saving
          some time in the process.
 
+       * TestEngine will generate separate page, attachment and work directories, in order to allow each instance
+         to work with a clean file installation.
+
 2019-10-10  Juan Pablo Santos (juanpablo AT apache DOT org)
 
        * 2.11.0-M6-git-01


[jspwiki] 02/05: PageTimeComparator unit tests

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit d1a2adcea9dc86165531ca9863e2f8a4e0c5aac4
Author: juanpablo <ju...@apache.org>
AuthorDate: Sat Oct 12 19:09:39 2019 +0200

    PageTimeComparator unit tests
---
 .../apache/wiki/pages/PageTimeComparatorTest.java  | 52 ++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/jspwiki-main/src/test/java/org/apache/wiki/pages/PageTimeComparatorTest.java b/jspwiki-main/src/test/java/org/apache/wiki/pages/PageTimeComparatorTest.java
new file mode 100644
index 0000000..ccc86e0
--- /dev/null
+++ b/jspwiki-main/src/test/java/org/apache/wiki/pages/PageTimeComparatorTest.java
@@ -0,0 +1,52 @@
+package org.apache.wiki.pages;
+
+import org.apache.wiki.TestEngine;
+import org.apache.wiki.WikiPage;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.Date;
+
+
+/**
+ * Unit tests corresponding to {@link PageTimeComparator}.
+ */
+public class PageTimeComparatorTest {
+
+    TestEngine engine = TestEngine.build();
+    PageTimeComparator comparator = new PageTimeComparator();
+    WikiPage p1 = new WikiPage( engine, "A" );
+    WikiPage p2 = new WikiPage( engine, "B" );
+    WikiPage p3 = new WikiPage( engine, "A" );
+
+    @Test
+    void shouldCheckCompareByTimeGetsMoreRecentOnTop() {
+        p1.setLastModified( new Date( 0L ) );
+        p2.setLastModified( new Date( 1L ) );
+
+        Assertions.assertEquals( 1, comparator.compare( p1, p2 ) );
+        Assertions.assertEquals( -1, comparator.compare( p2, p1 ) );
+    }
+
+    @Test
+    void shouldCheckCompareByEqualsTimeUsesPageName() {
+        p1.setLastModified( new Date( 0L ) );
+        p2.setLastModified( new Date( 0L ) );
+
+        Assertions.assertEquals( -1, comparator.compare( p1, p2 ) );
+    }
+
+    @Test
+    void shouldCheckCompareByEqualsTimeAndNameUsesPageVersion() {
+        p1.setLastModified( new Date( 0L ) );
+        p3.setLastModified( new Date( 0L ) );
+        p1.setVersion( 1 );
+        p3.setVersion( 2 );
+
+        Assertions.assertEquals( -1, comparator.compare( p1, p3 ) );
+
+        p3.setVersion( 1 );
+        Assertions.assertEquals( 0, comparator.compare( p1, p3 ) );
+    }
+
+}


[jspwiki] 04/05: adapt test to latest TestEngine change

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit 88af1a20aee6636b9fec8c1aa76819a8a8f3bd98
Author: juanpablo <ju...@apache.org>
AuthorDate: Sat Oct 12 19:11:22 2019 +0200

    adapt test to latest TestEngine change
---
 .../wiki/providers/VersioningFileProviderTest.java | 23 +++++++++++-----------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/jspwiki-main/src/test/java/org/apache/wiki/providers/VersioningFileProviderTest.java b/jspwiki-main/src/test/java/org/apache/wiki/providers/VersioningFileProviderTest.java
index 1bca164..8d9da15 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/providers/VersioningFileProviderTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/providers/VersioningFileProviderTest.java
@@ -18,15 +18,7 @@
  */
 
 package org.apache.wiki.providers;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.Writer;
-import java.util.Collection;
-import java.util.List;
-import java.util.Properties;
-
+import net.sf.ehcache.CacheManager;
 import org.apache.wiki.TestEngine;
 import org.apache.wiki.WikiContext;
 import org.apache.wiki.WikiPage;
@@ -38,7 +30,14 @@ import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-import net.sf.ehcache.CacheManager;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
 
 // FIXME: Should this thingy go directly to the VersioningFileProvider,
 //        or should it rely on the WikiEngine API?
@@ -71,7 +70,7 @@ public class VersioningFileProviderTest
         TestEngine.emptyWorkDir(null);
 
         engine = new TestEngine(PROPS);
-        files = PROPS.getProperty( AbstractFileProvider.PROP_PAGEDIR );
+        files = engine.getWikiProperties().getProperty( AbstractFileProvider.PROP_PAGEDIR );
     }
 
     @AfterEach
@@ -284,7 +283,7 @@ public class VersioningFileProviderTest
         engine = new TestEngine(PROPS);
 
         // the new TestEngine will have assigned a new page directory
-        files = PROPS.getProperty( AbstractFileProvider.PROP_PAGEDIR );
+        files = engine.getWikiProperties().getProperty( AbstractFileProvider.PROP_PAGEDIR );
 
         // we cannot switch PageProviders within a single test, so the
         // initial FileSystemProvider wiki page must be faked.


[jspwiki] 01/05: change awaitility condition so it checks the file is actually on disk; if the OS persists in setting the same time, change page names so the assertions pass and leave it documented on the test

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit c68a5f181d1bac91f78c46547181542899c46a70
Author: juanpablo <ju...@apache.org>
AuthorDate: Sat Oct 12 19:09:06 2019 +0200

    change awaitility condition so it checks the file is actually on disk; if the OS persists in setting the same time, change page names so the assertions pass and leave it documented on the test
---
 .../providers/BasicAttachmentProviderTest.java     | 54 +++++++++++++---------
 1 file changed, 33 insertions(+), 21 deletions(-)

diff --git a/jspwiki-main/src/test/java/org/apache/wiki/providers/BasicAttachmentProviderTest.java b/jspwiki-main/src/test/java/org/apache/wiki/providers/BasicAttachmentProviderTest.java
index ca46cf6..282f2a5 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/providers/BasicAttachmentProviderTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/providers/BasicAttachmentProviderTest.java
@@ -20,10 +20,11 @@
 package org.apache.wiki.providers;
 
 import org.apache.wiki.TestEngine;
+import org.apache.wiki.api.exceptions.ProviderException;
 import org.apache.wiki.attachment.Attachment;
 import org.apache.wiki.util.FileUtil;
 import org.awaitility.Awaitility;
-import org.junit.jupiter.api.AfterEach;
+import org.awaitility.core.ConditionFactory;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -40,8 +41,8 @@ import java.util.concurrent.Callable;
 
 public class BasicAttachmentProviderTest {
 
-    public static final String NAME1 = "TestPage";
-    public static final String NAME2 = "TestPageToo";
+    public static final String NAME1 = "FirstTestPage";
+    public static final String NAME2 = "AfterFirstTestPage";
 
     Properties props = TestEngine.getTestProperties();
     TestEngine m_engine;
@@ -52,7 +53,6 @@ public class BasicAttachmentProviderTest {
 
     @BeforeEach
     public void setUp() throws Exception {
-        props.setProperty( BasicAttachmentProvider.PROP_STORAGEDIR, "target/test-classes/testrepository" + System.currentTimeMillis() );
         m_engine = new TestEngine( props );
 
         m_provider = new BasicAttachmentProvider();
@@ -62,14 +62,6 @@ public class BasicAttachmentProviderTest {
         m_engine.saveText( NAME2, "Foobar2" );
     }
 
-    @AfterEach
-    public void tearDown() throws Exception {
-        m_engine.deleteTestPage( NAME1 );
-        m_engine.deleteTestPage( NAME2 );
-        TestEngine.deleteAll( new File( m_engine.getRequiredProperty( props, BasicAttachmentProvider.PROP_STORAGEDIR ) ) );
-        TestEngine.emptyWorkDir();
-    }
-
     private File makeAttachmentFile() throws Exception {
         final File tmpFile = File.createTempFile("test-",".txt");
         return copyContents( tmpFile );
@@ -140,12 +132,32 @@ public class BasicAttachmentProviderTest {
         Assertions.assertEquals( att.getName(), a0.getName(), "name" );
     }
 
+    @Test
+    public void testGetAttachmentDataRaisesProviderExceptionIfInexistentFileOnDisk() {
+        final Attachment att = new Attachment( m_engine, NAME1, "test1.txt" );
+        Assertions.assertThrows( ProviderException.class, () -> m_provider.getAttachmentData( att ) );
+    }
+
+    ConditionFactory awaitility() {
+        return Awaitility.given().ignoreException( ProviderException.class );
+    }
+
+    /**
+     * Actual save on disk is OS-dependent, meaning the files of two consecutive attachment saves may end up having the
+     * same last modified date. As we'll check the order of {@link BasicAttachmentProvider#listAllChanged(Date)}, we must
+     * wait until the file saved is actually on disk.
+     *
+     * If after all, the next saves of two consecutive attachments end up with the same last modified date,
+     * {@link BasicAttachmentProvider#listAllChanged(Date)} will sort attachments using wiki page names and versions,
+     * so we're preparing attachment names too in order to not mangle with the assertions.
+     *
+     * @param att attachment to check
+     * @return {@code Callable< Boolean.TRUE >} or {@code ProviderException}.
+     */
     Callable< Boolean > attachmentIsSaved( final Attachment att ) {
         return () -> {
-            final List< Attachment > attachments = m_provider.listAllChanged( new Date( 0L ) );
-            return attachments.size() > 0
-                && attachments.get( 0 ).getLastModified().getTime() < System.currentTimeMillis()
-                && att.getName().equals( attachments.get( 0 ).getName() );
+            m_provider.getAttachmentData( att ).close(); // throws exception if file does not exist on disk
+            return true;
         };
     }
 
@@ -155,7 +167,7 @@ public class BasicAttachmentProviderTest {
         final Attachment att = new Attachment( m_engine, NAME1, "test1.txt" );
         m_provider.putAttachmentData( att, new FileInputStream(in) );
 
-        Awaitility.await( "testListAll" ).until( attachmentIsSaved( att ) );
+        awaitility().await( "testListAll" ).until( attachmentIsSaved( att ) );
 
         final Attachment att2 = new Attachment( m_engine, NAME2, "test2.txt" );
         m_provider.putAttachmentData( att2, new FileInputStream(in) );
@@ -184,7 +196,7 @@ public class BasicAttachmentProviderTest {
         final Attachment att = new Attachment( m_engine, NAME1, "test1.txt" );
         m_provider.putAttachmentData( att, new FileInputStream(in) );
 
-        Awaitility.await( "testListAllExtrafile" ).until( attachmentIsSaved( att ) );
+        awaitility().await( "testListAllExtrafile" ).until( attachmentIsSaved( att ) );
 
         final Attachment att2 = new Attachment( m_engine, NAME2, "test2.txt" );
         m_provider.putAttachmentData( att2, new FileInputStream(in) );
@@ -213,7 +225,7 @@ public class BasicAttachmentProviderTest {
         m_provider.putAttachmentData( att, new FileInputStream(in) );
         makeExtraFile( attDir, "ping.pong" );
 
-        Awaitility.await( "testListAllExtrafileInAttachmentDir" ).until( attachmentIsSaved( att ) );
+        awaitility().await( "testListAllExtrafileInAttachmentDir" ).until( attachmentIsSaved( att ) );
 
         final Attachment att2 = new Attachment( m_engine, NAME2, "test2.txt" );
 
@@ -245,7 +257,7 @@ public class BasicAttachmentProviderTest {
         final File extrafile = new File( attDir, "ping.pong" );
         extrafile.mkdir();
 
-        Awaitility.await( "testListAllExtradirInAttachmentDir" ).until( attachmentIsSaved( att ) );
+        awaitility().await( "testListAllExtradirInAttachmentDir" ).until( attachmentIsSaved( att ) );
 
         final Attachment att2 = new Attachment( m_engine, NAME2, "test2.txt" );
 
@@ -268,7 +280,7 @@ public class BasicAttachmentProviderTest {
         final Attachment att = new Attachment( m_engine, NAME1, "test1." );
         m_provider.putAttachmentData( att, new FileInputStream(in) );
 
-        Awaitility.await( "testListAllNoExtension" ).until( attachmentIsSaved( att ) );
+        awaitility().await( "testListAllNoExtension" ).until( attachmentIsSaved( att ) );
 
         final Attachment att2 = new Attachment( m_engine, NAME2, "test2." );
         m_provider.putAttachmentData( att2, new FileInputStream(in) );