jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajaqu...@apache.org
Subject svn commit: r910057 - in /incubator/jspwiki/trunk: src/java/org/apache/wiki/ui/stripes/ tests/java/org/apache/wiki/ui/stripes/
Date Sun, 14 Feb 2010 18:34:44 GMT
Author: ajaquith
Date: Sun Feb 14 18:34:43 2010
New Revision: 910057

URL: http://svn.apache.org/viewvc?rev=910057&view=rev
Log:
Renamed ShortUrlRedirectFilter to ShortUrlFilter.

Added:
    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/ShortUrlFilter.java
      - copied, changed from r897361, incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/ShortUrlRedirectFilter.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/ShortUrlFilterTest.java
      - copied, changed from r905900, incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/ShortUrlRedirectFilterTest.java
Removed:
    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/ShortUrlRedirectFilter.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/ShortUrlRedirectFilterTest.java
Modified:
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/AllTests.java

Copied: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/ShortUrlFilter.java (from
r897361, incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/ShortUrlRedirectFilter.java)
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/ShortUrlFilter.java?p2=incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/ShortUrlFilter.java&p1=incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/ShortUrlRedirectFilter.java&r1=897361&r2=910057&rev=910057&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/ShortUrlRedirectFilter.java
(original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/ShortUrlFilter.java Sun Feb
14 18:34:43 2010
@@ -50,15 +50,16 @@
  * configuration from <code>web.xml</code>.
  * </p>
  */
-public class ShortUrlRedirectFilter implements Filter
+public class ShortUrlFilter implements Filter
 {
-
     private String m_urlPrefix = null;
 
     private String m_urlPrefixNoTrailingSlash = null;
 
     private WikiEngine m_engine = null;
 
+    private boolean m_initialized = false;
+
     /**
      * {@inheritDoc}
      */
@@ -84,6 +85,11 @@
                                                                                         
      throws IOException,
                                                                                         
          ServletException
     {
+        if ( !m_initialized )
+        {
+            lazyInit( ((HttpServletRequest)request).getSession().getServletContext() );
+        }
+        
         // Reconstruct the path (not including the host, scheme or webapp
         // context)
         HttpServletRequest httpRequest = (HttpServletRequest) request;
@@ -128,12 +134,16 @@
     }
 
     /**
-     * Initializes the filter.
+     * Initializes the filter. Does nothing.
      */
     public void init( FilterConfig filterConfig ) throws ServletException
     {
+        // No-op.
+    }
+
+    private void lazyInit( ServletContext servletContext )
+    {
         // Look up the Short URL prefix
-        ServletContext servletContext = filterConfig.getServletContext();
         WikiEngine engine = WikiEngine.getInstance( servletContext, null );
         m_engine = engine;
 
@@ -155,6 +165,7 @@
         // Add the servlet context
         m_urlPrefix = "/" + servletContext.getServletContextName() + m_urlPrefix;
         m_urlPrefixNoTrailingSlash = m_urlPrefix.substring( 0, m_urlPrefix.length() - 1 );
+        
+        m_initialized = true;
     }
-
 }

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/AllTests.java?rev=910057&r1=910056&r2=910057&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/AllTests.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/AllTests.java Sun Feb 14
18:34:43 2010
@@ -34,7 +34,7 @@
         suite.addTest( HandlerInfoTest.suite() );
         suite.addTest( IsOneOfTest.suite() );
         suite.addTest( LineDelimitedTypeConverterTest.suite() );
-        suite.addTest( ShortUrlRedirectFilterTest.suite() );
+        suite.addTest( ShortUrlFilterTest.suite() );
         suite.addTest( SpamInterceptorTest.suite() );
 
         return suite;

Copied: incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/ShortUrlFilterTest.java
(from r905900, incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/ShortUrlRedirectFilterTest.java)
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/ShortUrlFilterTest.java?p2=incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/ShortUrlFilterTest.java&p1=incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/ShortUrlRedirectFilterTest.java&r1=905900&r2=910057&rev=910057&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/ShortUrlRedirectFilterTest.java
(original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/ShortUrlFilterTest.java
Sun Feb 14 18:34:43 2010
@@ -20,53 +20,48 @@
  */
 package org.apache.wiki.ui.stripes;
 
+import java.util.Properties;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 import net.sourceforge.stripes.mock.MockRoundtrip;
-import net.sourceforge.stripes.mock.MockServletContext;
 
 import org.apache.wiki.TestEngine;
-import org.apache.wiki.WikiEngine;
 import org.apache.wiki.action.ViewActionBean;
 
-
-public class ShortUrlRedirectFilterTest extends TestCase
+public class ShortUrlFilterTest extends TestCase
 {
-    private MockServletContext m_servletContext = null;
+    private TestEngine m_engine = null;
 
-    public void setUp()
+    public void setUp() throws Exception
     {
-        // Configure the filter and servlet
-        MockServletContext servletContext = new MockServletContext( "test" );
-        TestEngine.initMockContext( servletContext );
-        servletContext.addFilter( ShortUrlRedirectFilter.class, "Redirect filter", null );
-
-        // Set the configured servlet context
-        m_servletContext = servletContext;
+        super.setUp();
+        Properties props = new Properties();
+        props.load( TestEngine.findTestProperties() );
+        m_engine = new TestEngine( props );
     }
 
     protected void tearDown() throws Exception
     {
         super.tearDown();
-        WikiEngine engine = WikiEngine.getInstance( m_servletContext, null );
-        engine.shutdown();
+        m_engine.shutdown();
     }
-    
+
     public void testRedirectEdit() throws Exception
     {
         // Inverse test for ShortURLConstructorTest#testEditURL1
-        MockRoundtrip trip = new MockRoundtrip( m_servletContext, "/wiki/Foo?do=Edit" );
+        MockRoundtrip trip = m_engine.guestTrip( "/wiki/Foo?do=Edit" );
         trip.execute();
         ViewActionBean bean = trip.getActionBean( ViewActionBean.class );
         assertNull( bean );
         assertEquals( "/Edit.jsp?edit=&page=Foo", trip.getDestination() );
     }
-    
+
     public void testRedirectView() throws Exception
     {
         // Inverse test for ShortURLConstructorTest#testViewURL1
-        MockRoundtrip trip = new MockRoundtrip( m_servletContext, "/wiki/Foo" );
+        MockRoundtrip trip = m_engine.guestTrip( "/wiki/Foo" );
         trip.execute();
         ViewActionBean bean = trip.getActionBean( ViewActionBean.class );
         assertNull( bean );
@@ -76,7 +71,7 @@
     public void testRedirectViewNoPage() throws Exception
     {
         // Inverse test for ShortURLConstructorTest#testViewURL4
-        MockRoundtrip trip = new MockRoundtrip( m_servletContext, "/wiki" );
+        MockRoundtrip trip = m_engine.guestTrip( "/wiki" );
         trip.execute();
         ViewActionBean bean = trip.getActionBean( ViewActionBean.class );
         assertNull( bean );
@@ -85,6 +80,6 @@
 
     public static Test suite()
     {
-        return new TestSuite( ShortUrlRedirectFilterTest.class );
+        return new TestSuite( ShortUrlFilterTest.class );
     }
 }



Mime
View raw message