Author: hlship
Date: Thu Jul 31 16:30:34 2008
New Revision: 681551

URL: http://svn.apache.org/viewvc?rev=681551&view=rev
Log:
TAPESTRY-2217: Add ability to render a page as a Document

Added:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageDocumentGeneratorImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/PageDocumentGenerator.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/app3/ContentPage.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/app3/RenderPageDemo.tml
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/pages/ContentPage.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/pages/RenderPageDemo.java
Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalConstants.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageMarkupRendererImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestPathOptimizerImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/app3/Login.tml
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/AdditionalIntegrationTests.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RequestPathOptimizerImplTest.java

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalConstants.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalConstants.java?rev=681551&r1=681550&r2=681551&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalConstants.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalConstants.java
 Thu Jul 31 16:30:34 2008
@@ -90,6 +90,13 @@
     public static final String IMMEDIATE_RESPONSE_PAGE_ATTRIBUTE = 
"tapestry.immediate-response-page";
 
     /**
+     * Request attribute that forces [EMAIL PROTECTED] 
org.apache.tapestry5.internal.services.RequestPathOptimizer} to use not
+     * optimize URLs (this is necessitated by [EMAIL PROTECTED] 
org.apache.tapestry5.services.PageDocumentGenerator}). Any non-null
+     * value will force the URLs to be non-optimized.
+     */
+    public static final String GENERATING_RENDERED_PAGE = 
"tapestry.generating-rendered-page";
+
+    /**
      * Required MIME type for JSON responses. If this MIME type is not used, 
the client-side Prototype code will not
      * recognize the response as JSON, and the Ajax.Response.responseJSON 
property will be null.
      */

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageDocumentGeneratorImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageDocumentGeneratorImpl.java?rev=681551&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageDocumentGeneratorImpl.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageDocumentGeneratorImpl.java
 Thu Jul 31 16:30:34 2008
@@ -0,0 +1,75 @@
+// Copyright 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "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.
+
+package org.apache.tapestry5.internal.services;
+
+import org.apache.tapestry5.ContentType;
+import org.apache.tapestry5.MarkupWriter;
+import org.apache.tapestry5.dom.Document;
+import org.apache.tapestry5.internal.InternalConstants;
+import org.apache.tapestry5.internal.structure.Page;
+import org.apache.tapestry5.services.MarkupWriterFactory;
+import org.apache.tapestry5.services.PageDocumentGenerator;
+import org.apache.tapestry5.services.Request;
+
+public class PageDocumentGeneratorImpl implements PageDocumentGenerator
+{
+    private final RequestPageCache pageCache;
+
+    private final PageMarkupRenderer markupRenderer;
+
+    private final MarkupWriterFactory markupWriterFactory;
+
+    private final PageContentTypeAnalyzer pageContentTypeAnalyzer;
+
+    private final Request request;
+
+    public PageDocumentGeneratorImpl(RequestPageCache pageCache, 
PageMarkupRenderer markupRenderer,
+                                     MarkupWriterFactory markupWriterFactory,
+                                     PageContentTypeAnalyzer 
pageContentTypeAnalyzer, Request request)
+    {
+        this.markupRenderer = markupRenderer;
+        this.markupWriterFactory = markupWriterFactory;
+        this.pageContentTypeAnalyzer = pageContentTypeAnalyzer;
+        this.pageCache = pageCache;
+        this.request = request;
+    }
+
+    public Document render(String logicalPageName)
+    {
+        Page page = pageCache.get(logicalPageName);
+
+        ContentType contentType = 
pageContentTypeAnalyzer.findContentType(page);
+
+        MarkupWriter writer = markupWriterFactory.newMarkupWriter(contentType);
+
+        // value will almost certainly be null, unless a page that is being 
rendered to a document
+        // itself decides to render another page to a document.
+
+        Object value = 
request.getAttribute(InternalConstants.GENERATING_RENDERED_PAGE);
+
+        try
+        {
+            request.setAttribute(InternalConstants.GENERATING_RENDERED_PAGE, 
true);
+
+            markupRenderer.renderPageMarkup(page, writer);
+        }
+        finally
+        {
+            request.setAttribute(InternalConstants.GENERATING_RENDERED_PAGE, 
value);
+        }
+
+        return writer.getDocument();
+    }
+}

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageMarkupRendererImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageMarkupRendererImpl.java?rev=681551&r1=681550&r2=681551&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageMarkupRendererImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageMarkupRendererImpl.java
 Thu Jul 31 16:30:34 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -15,9 +15,11 @@
 package org.apache.tapestry5.internal.services;
 
 import org.apache.tapestry5.MarkupWriter;
+import org.apache.tapestry5.internal.InternalConstants;
 import org.apache.tapestry5.internal.structure.Page;
 import org.apache.tapestry5.services.Environment;
 import org.apache.tapestry5.services.MarkupRenderer;
+import org.apache.tapestry5.services.Request;
 
 public class PageMarkupRendererImpl implements PageMarkupRenderer
 {
@@ -27,8 +29,10 @@
 
     private final MarkupRenderer markupRendererPipeline;
 
+    private final Request request;
+
     public PageMarkupRendererImpl(MarkupRenderer markupRendererPipeline, 
PageRenderQueue pageRenderQueue,
-                                  Environment environment)
+                                  Environment environment, Request request)
     {
         // We have to go through some awkward tricks here:
         // - MarkupRenderer and MarkupRendererFilter are PUBLIC
@@ -40,11 +44,16 @@
         this.environment = environment;
 
         this.markupRendererPipeline = markupRendererPipeline;
+        this.request = request;
     }
 
     public void renderPageMarkup(Page page, MarkupWriter writer)
     {
-        environment.clear();
+        // Don't clear the environment when rendering a page to a document as 
we may be doing so when in the middle
+        // of another render.
+
+        if (request.getAttribute(InternalConstants.GENERATING_RENDERED_PAGE) 
== null)
+            environment.clear();
 
         // This is why the PRQ is scope perthread; we tell it what to render 
here ...
 

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestPathOptimizerImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestPathOptimizerImpl.java?rev=681551&r1=681550&r2=681551&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestPathOptimizerImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestPathOptimizerImpl.java
 Thu Jul 31 16:30:34 2008
@@ -15,6 +15,7 @@
 package org.apache.tapestry5.internal.services;
 
 import org.apache.tapestry5.SymbolConstants;
+import org.apache.tapestry5.internal.InternalConstants;
 import org.apache.tapestry5.ioc.annotations.Symbol;
 import org.apache.tapestry5.services.Request;
 
@@ -27,7 +28,7 @@
     private final boolean forceAbsolute;
 
     /**
-     * Used to split a URI up into individual folder/file names. Any number of 
consecutive slashes is treated as a
+     * Used to split a URI up into individual folder/file names. Any number of 
consecutive slashes are treated as a
      * single slash.
      */
     private final Pattern SLASH_PATTERN = Pattern.compile("/+");
@@ -38,13 +39,17 @@
                                     boolean forceAbsolute)
     {
         this.request = request;
-
         this.forceAbsolute = forceAbsolute;
     }
 
     public String optimizePath(String absolutePath)
     {
-        if (forceAbsolute || request.isXHR()) return absolutePath;
+        if (forceAbsolute ||
+                request.isXHR() ||
+                
request.getAttribute(InternalConstants.GENERATING_RENDERED_PAGE) != null)
+        {
+            return absolutePath;
+        }
 
         String requestPath = request.getPath();
 

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/PageDocumentGenerator.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/PageDocumentGenerator.java?rev=681551&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/PageDocumentGenerator.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/PageDocumentGenerator.java
 Thu Jul 31 16:30:34 2008
@@ -0,0 +1,29 @@
+// Copyright 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "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.
+
+package org.apache.tapestry5.services;
+
+import org.apache.tapestry5.dom.Document;
+
+/**
+ * Interface used to programattically render a page, forming a [EMAIL 
PROTECTED] org.apache.tapestry5.dom.Document} which can then
+ * be manipulated or [EMAIL PROTECTED] 
org.apache.tapestry5.dom.Document#toMarkup(java.io.PrintWriter) streamed to a 
PrintWriter}.
+ */
+public interface PageDocumentGenerator
+{
+    /**
+     * Renders the page.
+     */
+    Document render(String logicalPageName);
+}

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=681551&r1=681550&r2=681551&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
 Thu Jul 31 16:30:34 2008
@@ -181,6 +181,7 @@
         binder.bind(BeanBlockOverrideSource.class, 
BeanBlockOverrideSourceImpl.class);
         binder.bind(AliasManager.class, 
AliasManagerImpl.class).withId("AliasOverrides");
         binder.bind(HiddenFieldLocationRules.class, 
HiddenFieldLocationRulesImpl.class);
+        binder.bind(PageDocumentGenerator.class, 
PageDocumentGeneratorImpl.class);
     }
 
     // ========================================================================

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java?rev=681551&r1=681550&r2=681551&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
 Thu Jul 31 16:30:34 2008
@@ -1059,4 +1059,9 @@
     {
         return newMock(BaseURLSource.class);
     }
+
+    protected final void train_getAttribute(Request request, String 
attibuteName, Object value)
+    {
+        expect(request.getAttribute(attibuteName)).andReturn(value);
+    }
 }

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app3/ContentPage.tml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app3/ContentPage.tml?rev=681551&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app3/ContentPage.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app3/ContentPage.tml Thu 
Jul 31 16:30:34 2008
@@ -0,0 +1,13 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
+    <head>
+        <title>Content Page</title>
+    </head>
+    <body>
+        <div id="link">
+            <p>
+                Included link:
+                <t:pagelink page="login">login</t:pagelink>
+            </p>
+        </div>
+    </body>
+</html>
\ No newline at end of file

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app3/Login.tml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app3/Login.tml?rev=681551&r1=681550&r2=681551&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app3/Login.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app3/Login.tml Thu Jul 31 
16:30:34 2008
@@ -11,7 +11,10 @@
 
         <ul>
             <li>
-                 <t:pagelink page="beandisplayoverridedemo">BeanDisplay 
Override Demo</t:pagelink>
+                <t:pagelink page="beandisplayoverridedemo">BeanDisplay 
Override Demo</t:pagelink>
+            </li>
+            <li>
+                <t:pagelink page="renderpagedemo">PageDocumentGenerator 
demo</t:pagelink>
             </li>
         </ul>
 

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app3/RenderPageDemo.tml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app3/RenderPageDemo.tml?rev=681551&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app3/RenderPageDemo.tml 
(added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app3/RenderPageDemo.tml Thu 
Jul 31 16:30:34 2008
@@ -0,0 +1,22 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
+    <head>
+        <title>Demo</title>
+    </head>
+    <body>
+
+        <p>
+            Content from page "ContentPage":
+        </p>
+
+        <blockquote id="content">
+            <t:outputraw value="pageContent"/>
+        </blockquote>
+
+        <p>
+            Normal link to login page:
+            <span id="link2">
+                <t:pagelink page="login">login</t:pagelink>
+            </span>
+        </p>
+    </body>
+</html>
\ No newline at end of file

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/AdditionalIntegrationTests.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/AdditionalIntegrationTests.java?rev=681551&r1=681550&r2=681551&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/AdditionalIntegrationTests.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/AdditionalIntegrationTests.java
 Thu Jul 31 16:30:34 2008
@@ -20,7 +20,7 @@
 /**
  * Additional integration tests that do not fit with the main group due to the 
need for special configuration.
  */
[EMAIL PROTECTED](timeOut = 50000, sequential = true, groups = { "integration" 
})
[EMAIL PROTECTED](timeOut = 50000, sequential = true, groups = {"integration"})
 public class AdditionalIntegrationTests extends AbstractIntegrationTestSuite
 {
 
@@ -65,4 +65,20 @@
         assertText("message", "it worked");
     }
 
+    /**
+     * TAPESTR-2217
+     */
+    @Test
+    public void page_document_generator()
+    {
+        start("PageDocumentGenerator demo");
+
+        // In generated document: not optimized
+        assertAttribute("//a[1]/@href", "/login");
+
+        // In normal render: optimized
+        // Fuckin Selenium
+        // assertAttribute("//a[2]/@href", "login");
+    }
+
 }

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/pages/ContentPage.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/pages/ContentPage.java?rev=681551&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/pages/ContentPage.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/pages/ContentPage.java
 Thu Jul 31 16:30:34 2008
@@ -0,0 +1,19 @@
+//  Copyright 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "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.
+
+package org.apache.tapestry5.integration.app3.pages;
+
+public class ContentPage
+{
+}

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/pages/RenderPageDemo.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/pages/RenderPageDemo.java?rev=681551&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/pages/RenderPageDemo.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/pages/RenderPageDemo.java
 Thu Jul 31 16:30:34 2008
@@ -0,0 +1,30 @@
+//  Copyright 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "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.
+
+package org.apache.tapestry5.integration.app3.pages;
+
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.services.PageDocumentGenerator;
+
+public class RenderPageDemo
+{
+    @Inject
+    private PageDocumentGenerator generator;
+
+    public String getPageContent()
+    {
+        return generator.render("contentpage").toString();
+    }
+
+}

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RequestPathOptimizerImplTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RequestPathOptimizerImplTest.java?rev=681551&r1=681550&r2=681551&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RequestPathOptimizerImplTest.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RequestPathOptimizerImplTest.java
 Thu Jul 31 16:30:34 2008
@@ -14,6 +14,7 @@
 
 package org.apache.tapestry5.internal.services;
 
+import org.apache.tapestry5.internal.InternalConstants;
 import org.apache.tapestry5.internal.test.InternalBaseTestCase;
 import org.apache.tapestry5.services.Request;
 import org.testng.annotations.DataProvider;
@@ -110,6 +111,7 @@
 
         train_isXHR(request, false);
 
+        train_getAttribute(request, 
InternalConstants.GENERATING_RENDERED_PAGE, null);
         train_getContextPath(request, contextPath);
         train_getPath(request, requestPath);
 
@@ -123,7 +125,7 @@
     }
 
     @Test
-    public void force_absolute_is_a_pass_through()
+    public void xhr_forces_absolute()
     {
         Request request = mockRequest();
         String path = "/some/path";
@@ -139,4 +141,37 @@
         verify();
     }
 
+    @Test
+    public void force_absolute_is_enforced()
+    {
+        Request request = mockRequest();
+        String path = "/some/path";
+
+        replay();
+
+        RequestPathOptimizer optimizer = new RequestPathOptimizerImpl(request, 
true);
+
+        assertSame(optimizer.optimizePath(path), path);
+
+        verify();
+    }
+
+    @Test
+    public void generating_to_document_forces_non_optimized()
+    {
+        Request request = mockRequest();
+        String path = "/some/path";
+
+        train_isXHR(request, false);
+        train_getAttribute(request, 
InternalConstants.GENERATING_RENDERED_PAGE, true);
+
+        replay();
+
+        RequestPathOptimizer optimizer = new RequestPathOptimizerImpl(request, 
false);
+
+        assertSame(optimizer.optimizePath(path), path);
+
+        verify();
+    }
+
 }


Reply via email to