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/09/08 18:40:13 UTC

[jspwiki] branch master updated (d982553 -> 37ffcba)

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 d982553  2.11.0-M5-git-17: no version bump;  rerun test suite
     new ca1bf0a  code format and fix some warnings from IntelliJ
     new 1800df5  overwrite deletePage method to add some log if an exception happens; add default constructor which uses getTestProperties internally
     new 1b7f6e4  remove deletion of page not being created on test + code format and fix IntelliJ warnings
     new 37ffcba  code format

The 4 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:
 .../src/main/java/org/apache/wiki/WikiEngine.java  | 67 +++++++-----------
 .../src/test/java/org/apache/wiki/TestEngine.java  | 45 ++++++------
 .../org/apache/wiki/ui/CommandResolverTest.java    | 81 ++++++----------------
 .../java/org/apache/wiki/ui/PageCommandTest.java   | 22 ++----
 4 files changed, 76 insertions(+), 139 deletions(-)


[jspwiki] 04/04: code format

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 37ffcba5592f5b52eb2beb20f1d11187d8540659
Author: juanpablo <ju...@apache.org>
AuthorDate: Sun Sep 8 20:39:45 2019 +0200

    code format
---
 .../java/org/apache/wiki/ui/PageCommandTest.java   | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/jspwiki-main/src/test/java/org/apache/wiki/ui/PageCommandTest.java b/jspwiki-main/src/test/java/org/apache/wiki/ui/PageCommandTest.java
index 68af498..937a3f4 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/ui/PageCommandTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/ui/PageCommandTest.java
@@ -22,8 +22,6 @@
  */
 package org.apache.wiki.ui;
 
-import java.util.Properties;
-
 import org.apache.wiki.TestEngine;
 import org.apache.wiki.WikiPage;
 import org.apache.wiki.auth.permissions.PermissionFactory;
@@ -32,30 +30,25 @@ import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-public class PageCommandTest
-{
-    TestEngine     testEngine;
+public class PageCommandTest {
 
+    TestEngine     testEngine;
     WikiPage       testPage;
 
     @BeforeEach
-    public void setUp() throws Exception
-    {
-        Properties props = TestEngine.getTestProperties();
-        testEngine = new TestEngine( props );
+    public void setUp() throws Exception {
+        testEngine = new TestEngine();
         testEngine.saveText( "TestPage", "This is a test." );
         testPage = testEngine.getPage( "TestPage" );
     }
 
     @AfterEach
-    public void tearDown() throws Exception
-    {
+    public void tearDown() throws Exception {
         testEngine.deletePage( "TestPage" );
     }
 
     @Test
-    public void testStaticCommand()
-    {
+    public void testStaticCommand() {
         Command a = PageCommand.VIEW;
         Assertions.assertEquals( "view", a.getRequestContext() );
         Assertions.assertEquals( "Wiki.jsp", a.getJSP() );
@@ -85,8 +78,7 @@ public class PageCommandTest
     }
 
     @Test
-    public void testTargetedCommand()
-    {
+    public void testTargetedCommand() {
         // Get view command
         Command a = PageCommand.VIEW;
 


[jspwiki] 01/04: code format and fix some warnings from IntelliJ

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 ca1bf0ad378ecb7c8dac50aa3607af83447d3495
Author: juanpablo <ju...@apache.org>
AuthorDate: Sun Sep 8 20:36:21 2019 +0200

    code format and fix some warnings from IntelliJ
---
 .../src/main/java/org/apache/wiki/WikiEngine.java  | 67 ++++++++--------------
 1 file changed, 24 insertions(+), 43 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
index bbefc84..b34386c 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
@@ -89,7 +89,6 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
 import java.util.Enumeration;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -1990,7 +1989,7 @@ public class WikiEngine
      *  @since 2.2
      */
 
-    public String getRedirectURL( WikiContext context )
+    public String getRedirectURL( final WikiContext context )
     {
         return context.getRedirectURL();
     }
@@ -2006,18 +2005,14 @@ public class WikiEngine
      *  @see org.apache.wiki.ui.Command
      *  @since 2.1.15.
      */
-    // FIXME: We need to have a version which takes a fixed page
-    //        name as well, or check it elsewhere.
-    public WikiContext createContext( HttpServletRequest request,
-                                      String requestContext )
-    {
-        if( !m_isConfigured )
-        {
-            throw new InternalWikiException("WikiEngine has not been properly started.  It is likely that the configuration is faulty.  Please check all logs for the possible reason.");
+    // FIXME: We need to have a version which takes a fixed page name as well, or check it elsewhere.
+    public WikiContext createContext( final HttpServletRequest request, final String requestContext ) {
+        if( !m_isConfigured ) {
+            throw new InternalWikiException( "WikiEngine has not been properly started.  It is likely that the configuration is faulty.  Please check all logs for the possible reason." );
         }
 
         // Build the wiki context
-        Command command = m_commandResolver.findCommand( request, requestContext );
+        final Command command = m_commandResolver.findCommand( request, requestContext );
         return new WikiContext( this, request, command );
     }
 
@@ -2028,30 +2023,21 @@ public class WikiEngine
      * @param pageName The name of the page.
      * @throws ProviderException If something goes wrong.
      */
-    public void deletePage( String pageName )
-        throws ProviderException
-    {
-        WikiPage p = getPage( pageName );
-
-        if( p != null )
-        {
-            if( p instanceof Attachment )
-            {
-                m_attachmentManager.deleteAttachment( (Attachment) p );
-            }
-            else
-            {
-                Collection<String> refTo = m_referenceManager.findRefersTo(pageName);
-                //May return null, if the page does not exist or has not been indexed yet.
-
-                if (m_attachmentManager.hasAttachments( p ))
-                {
-                    List< Attachment > attachments = m_attachmentManager.listAttachments( p );
-                    for( Iterator< Attachment > atti = attachments.iterator(); atti.hasNext(); )
-                    {
-                        Attachment attachment = atti.next();
-
-                        if( refTo != null ) refTo.remove(attachment.getName());
+    public void deletePage( final String pageName ) throws ProviderException {
+        final WikiPage p = getPage( pageName );
+        if( p != null ) {
+            if( p instanceof Attachment ) {
+                m_attachmentManager.deleteAttachment( ( Attachment )p );
+            } else {
+                final Collection< String > refTo = m_referenceManager.findRefersTo( pageName );
+                // May return null, if the page does not exist or has not been indexed yet.
+
+                if( m_attachmentManager.hasAttachments( p ) ) {
+                    final List< Attachment > attachments = m_attachmentManager.listAttachments( p );
+                    for( final Attachment attachment : attachments ) {
+                        if( refTo != null ) {
+                            refTo.remove( attachment.getName() );
+                        }
 
                         m_attachmentManager.deleteAttachment( attachment );
                     }
@@ -2068,15 +2054,10 @@ public class WikiEngine
      *  @param page The page object.
      *  @throws ProviderException If something goes wrong.
      */
-    public void deleteVersion( WikiPage page )
-        throws ProviderException
-    {
-        if( page instanceof Attachment )
-        {
+    public void deleteVersion( final WikiPage page ) throws ProviderException {
+        if( page instanceof Attachment ) {
             m_attachmentManager.deleteVersion( (Attachment) page );
-        }
-        else
-        {
+        } else {
             m_pageManager.deleteVersion( page );
         }
     }


[jspwiki] 02/04: overwrite deletePage method to add some log if an exception happens; add default constructor which uses getTestProperties internally

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 1800df5efa5f49bdf5ed442aa812881c5f85931f
Author: juanpablo <ju...@apache.org>
AuthorDate: Sun Sep 8 20:38:03 2019 +0200

    overwrite deletePage method to add some log if an exception happens; add default constructor which uses getTestProperties internally
---
 .../src/test/java/org/apache/wiki/TestEngine.java  | 45 +++++++++++-----------
 1 file changed, 23 insertions(+), 22 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 ac3f099..71de8c0 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/TestEngine.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/TestEngine.java
@@ -113,16 +113,16 @@ public class TestEngine extends WikiEngine
             // Set up a test Janne session
             HttpServletRequest request = newHttpRequest();
             m_janneWikiSession = WikiSession.getWikiSession( this, request );
-            this.getAuthenticationManager().login( m_janneWikiSession, request,
-                    Users.JANNE,
-                    Users.JANNE_PASS );
+            this.getAuthenticationManager().login( m_janneWikiSession, request, Users.JANNE, Users.JANNE_PASS );
         }
         return m_janneWikiSession;
     }
 
-    public TestEngine( Properties props )
-        throws WikiException
-    {
+    public TestEngine() throws WikiException {
+        this( getTestProperties() );
+    }
+
+    public TestEngine( Properties props ) throws WikiException {
         super( new MockServletContext( "test" ), "test", cleanTestProps( props ) );
 
         // Stash the WikiEngine in the servlet context
@@ -261,29 +261,32 @@ public class TestEngine extends WikiEngine
     /**
      *  Copied from FileSystemProvider
      */
-    protected static String mangleName( String pagename )
-        throws IOException
-    {
-        Properties properties = new Properties();
-        String m_encoding = properties.getProperty( WikiEngine.PROP_ENCODING,
-                                                    AbstractFileProvider.DEFAULT_ENCODING );
+    protected static String mangleName( String pagename ) {
+        final Properties properties = new Properties();
+        final String m_encoding = properties.getProperty( WikiEngine.PROP_ENCODING, AbstractFileProvider.DEFAULT_ENCODING );
 
         pagename = TextUtil.urlEncode( pagename, m_encoding );
         pagename = TextUtil.replaceString( pagename, "/", "%2F" );
         return pagename;
     }
 
+    public void deletePage( final String pageName ) throws ProviderException {
+        try {
+            super.deletePage( pageName );
+        } catch( final ProviderException | RuntimeException e ) {
+            log.error( e.getMessage(), e );
+            throw e;
+        }
+    }
+
     /**
      *  Removes a page, but not any auxiliary information.  Works only
      *  with FileSystemProvider.
      */
-    public void deleteTestPage( String name )
-    {
-        Properties properties = getTestProperties();
-
-        try
-        {
-            String files = properties.getProperty( FileSystemProvider.PROP_PAGEDIR );
+    public void deleteTestPage( final String name ) {
+        final Properties properties = getTestProperties();
+        try {
+            final String files = properties.getProperty( FileSystemProvider.PROP_PAGEDIR );
 
             File f = new File( files, mangleName(name)+FileSystemProvider.FILE_EXT );
 
@@ -298,9 +301,7 @@ public class TestEngine extends WikiEngine
 
             deleteAttachments( name );
             firePageEvent( WikiPageEvent.PAGE_DELETED, name );
-        }
-        catch( Exception e )
-        {
+        } catch( final Exception e ) {
             log.error("Couldn't delete "+name, e );
         }
     }


[jspwiki] 03/04: remove deletion of page not being created on test + code format and fix IntelliJ warnings

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 1b7f6e49edd8cc703b7bd53781ab5a8126bbad5d
Author: juanpablo <ju...@apache.org>
AuthorDate: Sun Sep 8 20:39:12 2019 +0200

    remove deletion of page not being created on test + code format and fix IntelliJ warnings
---
 .../org/apache/wiki/ui/CommandResolverTest.java    | 81 ++++++----------------
 1 file changed, 22 insertions(+), 59 deletions(-)

diff --git a/jspwiki-main/src/test/java/org/apache/wiki/ui/CommandResolverTest.java b/jspwiki-main/src/test/java/org/apache/wiki/ui/CommandResolverTest.java
index f7aa727..7212058 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/ui/CommandResolverTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/ui/CommandResolverTest.java
@@ -22,8 +22,7 @@
  */
 package org.apache.wiki.ui;
 
-import java.util.Properties;
-
+import net.sourceforge.stripes.mock.MockHttpServletRequest;
 import org.apache.wiki.TestEngine;
 import org.apache.wiki.WikiContext;
 import org.apache.wiki.WikiEngine;
@@ -34,18 +33,16 @@ import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-import net.sourceforge.stripes.mock.MockHttpServletRequest;
+import java.util.Properties;
 
 
-public class CommandResolverTest
-{
+public class CommandResolverTest {
     TestEngine m_engine;
     CommandResolver resolver;
 
     @BeforeEach
-    public void setUp() throws Exception
-    {
-        Properties props = TestEngine.getTestProperties();
+    public void setUp() throws Exception {
+        final Properties props = TestEngine.getTestProperties();
         props.setProperty( WikiEngine.PROP_MATCHPLURALS, "yes" );
         m_engine = new TestEngine( props );
         resolver = m_engine.getCommandResolver();
@@ -54,20 +51,15 @@ public class CommandResolverTest
     }
 
     @AfterEach
-    public void tearDown() throws Exception
-    {
-        m_engine.deletePage( "TestPage" );
+    public void tearDown() throws Exception {
         m_engine.deletePage( "SinglePage" );
         m_engine.deletePage( "PluralPage" );
     }
 
     @Test
-    public void testFindStaticWikiAction()
-    {
-        Command a;
-
+    public void testFindStaticWikiAction() {
         // If we look for action with "edit" request context, we get EDIT action
-        a = CommandResolver.findCommand( WikiContext.EDIT );
+        Command a = CommandResolver.findCommand( WikiContext.EDIT );
         Assertions.assertEquals( PageCommand.EDIT, a );
         Assertions.assertEquals( WikiContext.EDIT, a.getRequestContext() );
 
@@ -82,25 +74,15 @@ public class CommandResolverTest
         Assertions.assertEquals( WikiContext.VIEW_GROUP, a.getRequestContext() );
 
         // Looking for non-existent context; should result in exception
-        try
-        {
-            a = CommandResolver.findCommand( "nonExistentContext" );
-            Assertions.fail( "Context supported, strangely..." );
-        }
-        catch ( IllegalArgumentException e )
-        {
-            // Good; this is what we expect
-        }
+        Assertions.assertThrows( IllegalArgumentException.class, () -> CommandResolver.findCommand( "nonExistentContext" ) );
     }
 
     @Test
-    public void testFindWikiActionNoParams()
-    {
-        Command a;
+    public void testFindWikiActionNoParams() {
         MockHttpServletRequest request = m_engine.newHttpRequest( "" );
 
         // Passing an EDIT request with no explicit page params means the EDIT action
-        a = resolver.findCommand( request, WikiContext.EDIT );
+        Command a = resolver.findCommand( request, WikiContext.EDIT );
         Assertions.assertEquals( PageCommand.EDIT, a );
         Assertions.assertEquals( "EditContent.jsp", a.getContentTemplate() );
         Assertions.assertEquals( "Edit.jsp", a.getJSP() );
@@ -117,16 +99,7 @@ public class CommandResolverTest
         Assertions.assertEquals( GroupCommand.VIEW_GROUP, a );
         Assertions.assertNull( a.getTarget() );
 
-        // Looking for non-existent context; should result in exception
-        try
-        {
-            a = resolver.findCommand( request, "nonExistentContext" );
-            Assertions.fail( "Context supported, strangely..." );
-        }
-        catch ( IllegalArgumentException e )
-        {
-            // Good; this is what we expect
-        }
+        Assertions.assertThrows( IllegalArgumentException.class, () -> resolver.findCommand( m_engine.newHttpRequest( "" ), "nonExistentContext" ) );
 
         // Request for "UserPreference.jsp" should resolve to PREFS action
         request = m_engine.newHttpRequest( "/UserPreferences.jsp" );
@@ -150,15 +123,13 @@ public class CommandResolverTest
     }
 
     @Test
-    public void testFindWikiActionWithParams() throws Exception
-    {
-        Command a;
-        WikiPage page = m_engine.getPage( "SinglePage" );
+    public void testFindWikiActionWithParams() {
+        final WikiPage page = m_engine.getPage( "SinglePage" );
 
         // Passing an EDIT request with page param yields a wrapped action
         MockHttpServletRequest request = m_engine.newHttpRequest( "/Edit.jsp?page=SinglePage" );
         request.getParameterMap().put( "page", new String[]{ "SinglePage" } );
-        a = resolver.findCommand( request, WikiContext.EDIT );
+        Command a = resolver.findCommand( request, WikiContext.EDIT );
         Assertions.assertNotSame( PageCommand.EDIT, a );
         Assertions.assertEquals( "EditContent.jsp", a.getContentTemplate() );
         Assertions.assertEquals( "Edit.jsp", a.getJSP() );
@@ -187,14 +158,10 @@ public class CommandResolverTest
     }
 
     @Test
-    public void testFindWikiActionWithPath()
-    {
-        MockHttpServletRequest request;
-        Command a;
-
+    public void testFindWikiActionWithPath() {
         // Passing an EDIT request with View JSP yields EDIT of the Front page
-        request = m_engine.newHttpRequest( "/Wiki.jsp" );
-        a = resolver.findCommand( request, WikiContext.EDIT );
+        MockHttpServletRequest request = m_engine.newHttpRequest( "/Wiki.jsp" );
+        Command a = resolver.findCommand( request, WikiContext.EDIT );
         Assertions.assertNotNull( a.getTarget() );
         Assertions.assertEquals( ((WikiPage)a.getTarget()).getName(), m_engine.getFrontPage() );
 
@@ -212,10 +179,8 @@ public class CommandResolverTest
     }
 
     @Test
-    public void testFinalPageName() throws Exception
-    {
-        String page;
-        page = resolver.getFinalPageName( "SinglePage" );
+    public void testFinalPageName() throws Exception {
+        String page = resolver.getFinalPageName( "SinglePage" );
         Assertions.assertEquals( "SinglePage", page );
         page = resolver.getFinalPageName( "SinglePages" );
         Assertions.assertEquals( "SinglePage", page );
@@ -230,10 +195,8 @@ public class CommandResolverTest
     }
 
     @Test
-    public void testSpecialPageReference()
-    {
-        String url;
-        url = resolver.getSpecialPageReference( "RecentChanges" );
+    public void testSpecialPageReference() {
+        String url = resolver.getSpecialPageReference( "RecentChanges" );
         Assertions.assertEquals( "/test/RecentChanges.jsp", url );
 
         url = resolver.getSpecialPageReference( "Search" );