Repository: tapestry-5 Updated Branches: refs/heads/master 6330f3093 -> 86bf0c034
TAP5-2238: fix redirection if context path is not empty Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/86bf0c03 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/86bf0c03 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/86bf0c03 Branch: refs/heads/master Commit: 86bf0c034c5e937c3820b0093fa3f680cfbe4ed4 Parents: 6330f30 Author: Jochen Kemnade <[email protected]> Authored: Fri Apr 15 08:34:23 2016 +0200 Committer: Jochen Kemnade <[email protected]> Committed: Fri Apr 15 08:34:23 2016 +0200 ---------------------------------------------------------------------- .../services/javascript/ModuleDispatcher.java | 2 +- .../javascript/ModuleDispatcherTests.groovy | 51 +++++++++++++++++--- 2 files changed, 45 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/86bf0c03/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleDispatcher.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleDispatcher.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleDispatcher.java index d011a8d..50a19b8 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleDispatcher.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleDispatcher.java @@ -89,7 +89,7 @@ public class ModuleDispatcher implements Dispatcher this.compress = compress; requestPrefix = pathConstructor.constructDispatchPath(compress ? prefix + ".gz" : prefix) + "/"; - stackPathPrefix = pathConstructor.constructDispatchPath(assetPrefix, RequestConstants.STACK_FOLDER) + "/"; + stackPathPrefix = pathConstructor.constructClientPath(assetPrefix, RequestConstants.STACK_FOLDER) + "/"; } public boolean dispatch(Request request, Response response) throws IOException http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/86bf0c03/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy index 86e555f..1a6bc9f 100644 --- a/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy +++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy @@ -1,10 +1,12 @@ package org.apache.tapestry5.services.javascript -import org.apache.tapestry5.internal.services.javascript.JavaScriptStackPathConstructor; +import javax.servlet.http.HttpServletResponse + +import org.apache.tapestry5.internal.services.javascript.JavaScriptStackPathConstructor import org.apache.tapestry5.internal.services.javascript.ModuleDispatcher import org.apache.tapestry5.ioc.internal.QuietOperationTracker import org.apache.tapestry5.ioc.test.TestBase -import org.apache.tapestry5.services.LocalizationSetter; +import org.apache.tapestry5.services.LocalizationSetter import org.apache.tapestry5.services.PathConstructor import org.apache.tapestry5.services.Request import org.apache.tapestry5.services.Response @@ -12,8 +14,6 @@ import org.easymock.EasyMock import org.testng.annotations.DataProvider import org.testng.annotations.Test -import javax.servlet.http.HttpServletResponse - class ModuleDispatcherTests extends TestBase { @Test(dataProvider = "unknownPaths") @@ -27,7 +27,7 @@ class ModuleDispatcherTests extends TestBase { expect(pc.constructDispatchPath("modules")).andReturn("/modules") - expect(pc.constructDispatchPath("assets", "stack")).andReturn("/assets/stack") + expect(pc.constructClientPath("assets", "stack")).andReturn("/assets/stack") expect(request.path).andReturn(path) expect(request.locale).andReturn(Locale.US) @@ -67,7 +67,7 @@ class ModuleDispatcherTests extends TestBase { expect(pc.constructDispatchPath("modules")).andReturn("/modules") - expect(pc.constructDispatchPath("assets", "stack")).andReturn("/assets/stack") + expect(pc.constructClientPath("assets", "stack")).andReturn("/assets/stack") expect(request.path).andReturn("/modules/foo/bar.js") expect(request.locale).andReturn(Locale.US) @@ -103,7 +103,7 @@ class ModuleDispatcherTests extends TestBase { expect(pc.constructDispatchPath("modules")).andReturn("/modules") - expect(pc.constructDispatchPath("assets", "stack")).andReturn("/assets/stack") + expect(pc.constructClientPath("assets", "stack")).andReturn("/assets/stack") expect(request.path).andReturn("/modules/foo/bar.js") expect(request.locale).andReturn(Locale.US) @@ -124,4 +124,41 @@ class ModuleDispatcherTests extends TestBase { verify() } + + @Test + //TAP5-2238 + void "redirect if module is part of a stack and context path is not empty"() { + + def manager = newMock ModuleManager + def request = newMock Request + def response = newMock Response + def pc = newMock PathConstructor + def stack = newMock JavaScriptStack + def javaScriptStackSource = newMock JavaScriptStackSource + def javaScriptStackPathConstructor = newMock JavaScriptStackPathConstructor + def localizationSetter = newMock LocalizationSetter + + + expect(pc.constructDispatchPath("modules")).andReturn("/modules") + expect(pc.constructClientPath("assets", "stack")).andReturn("/app/assets/stack") + + expect(request.path).andReturn("/modules/foo/bar.js") + expect(request.locale).andReturn(Locale.US) + + expect(javaScriptStackSource.getStackNames()).andReturn(["default"]) + expect(javaScriptStackSource.getStack("default")).andReturn(stack) + expect(stack.getModules()).andReturn(["foo/bar"]) + expect(localizationSetter.setNonPersistentLocaleFromLocaleName("en_US")) + expect(javaScriptStackPathConstructor.constructPathsForJavaScriptStack("default")).andReturn(["/app/assets/stack/default.js"]) + expect(response.sendRedirect("/app/assets/stack/default.js")) + + replay() + + def handler = new ModuleDispatcher(manager, null, new QuietOperationTracker(), pc, + javaScriptStackSource, javaScriptStackPathConstructor, localizationSetter, "modules", "assets", false) + + assert handler.dispatch(request, response) == true + + verify() + } }
