struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [6/9] git commit: Updates tests to new version of methods without ServletContext
Date Mon, 17 Feb 2014 08:36:28 GMT
Updates tests to new version of methods without ServletContext


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/d4ddd74e
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/d4ddd74e
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/d4ddd74e

Branch: refs/heads/feature/WW-4292-dont-use-servletcontext
Commit: d4ddd74ebed3a68fab70ddb9bb86ce5efa9ea65b
Parents: 4a4d041
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Mon Feb 17 09:34:03 2014 +0100
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Mon Feb 17 09:34:03 2014 +0100

----------------------------------------------------------------------
 .../dispatcher/FilterDispatcherTest.java        |   4 +-
 .../apache/struts2/dispatcher/FilterTest.java   |   4 +-
 .../views/freemarker/FreeMarkerResultTest.java  | 204 +--------------
 .../freemarker/FreemarkerResultMockedTest.java  | 262 +++++++++++++++++++
 .../struts2/views/jsp/AbstractTagTest.java      |   3 +-
 .../apache/struts2/views/jsp/URLTagTest.java    |   3 +-
 6 files changed, 280 insertions(+), 200 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/d4ddd74e/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java b/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java
index 2c2d747..4449e40 100644
--- a/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java
+++ b/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java
@@ -122,7 +122,7 @@ public class FilterDispatcherTest extends StrutsInternalTestCase {
             return request;
         }
 
-        public void serviceAction(HttpServletRequest request, HttpServletResponse response,
ServletContext context, ActionMapping mapping) throws ServletException {
+        public void serviceAction(HttpServletRequest request, HttpServletResponse response,
ActionMapping mapping) throws ServletException {
             serviceRequest = true;
         }
 
@@ -152,7 +152,7 @@ public class FilterDispatcherTest extends StrutsInternalTestCase {
             return request;
         }
 
-        public void serviceAction(HttpServletRequest request, HttpServletResponse response,
ServletContext context, ActionMapping mapping) throws ServletException {
+        public void serviceAction(HttpServletRequest request, HttpServletResponse response,
ActionMapping mapping) throws ServletException {
             serviceRequest = true;
             // if we set the chracter encoding AFTER we do wrap request, we will get
             // a failing test

http://git-wip-us.apache.org/repos/asf/struts/blob/d4ddd74e/core/src/test/java/org/apache/struts2/dispatcher/FilterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/dispatcher/FilterTest.java b/core/src/test/java/org/apache/struts2/dispatcher/FilterTest.java
index 04b5c94..12f9a64 100644
--- a/core/src/test/java/org/apache/struts2/dispatcher/FilterTest.java
+++ b/core/src/test/java/org/apache/struts2/dispatcher/FilterTest.java
@@ -313,10 +313,10 @@ public class FilterTest extends StrutsInternalTestCase {
         }
 
         @Override
-        public void serviceAction(HttpServletRequest request, HttpServletResponse response,
ServletContext context, ActionMapping mapping) throws ServletException {
+        public void serviceAction(HttpServletRequest request, HttpServletResponse response,
ActionMapping mapping) throws ServletException {
             service = true;
         }
-        
+
         @Override
         public void cleanup() {
         	cleanUp = true;

http://git-wip-us.apache.org/repos/asf/struts/blob/d4ddd74e/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java
b/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java
index 62ab0ee..d721826 100644
--- a/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java
+++ b/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java
@@ -43,12 +43,14 @@ import javax.servlet.ServletContext;
 import java.io.File;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.util.HashMap;
 
 import static org.apache.struts2.views.jsp.AbstractUITagTest.normalize;
 
 /**
  * Test case for FreeMarkerResult.
- *
  */
 public class FreeMarkerResultTest extends StrutsInternalTestCase {
 
@@ -62,54 +64,6 @@ public class FreeMarkerResultTest extends StrutsInternalTestCase {
     private FreemarkerManager mgr;
     private MockHttpServletRequest request;
 
-    public void testActionThatThrowsExceptionTag() throws Exception {
-        //get fm config to use it in mock servlet context
-        FreemarkerManager freemarkerManager = container.getInstance(FreemarkerManager.class);
-        Configuration freemarkerConfig = freemarkerManager.getConfiguration(ServletActionContext.getServletContext());
-        freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
-
-        ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class);
-        File file = new File(FreeMarkerResultTest.class.getResource("callActionFreeMarker2.ftl").toURI());
-        EasyMock.expect(servletContext.getRealPath("/tutorial/org/apache/struts2/views/freemarker/callActionFreeMarker.ftl")).andReturn(file.getAbsolutePath());
-        file = new File(FreeMarkerResultTest.class.getResource("nested.ftl").toURI());
-        EasyMock.expect(servletContext.getRealPath("/tutorial/org/apache/struts2/views/freemarker/nested.ftl")).andReturn(file.getAbsolutePath());
-        EasyMock.expect(servletContext.getAttribute(FreemarkerManager.CONFIG_SERVLET_CONTEXT_KEY)).andReturn(freemarkerConfig).anyTimes();
-        EasyMock.replay(servletContext);
-
-        freemarkerConfig.setServletContextForTemplateLoading(servletContext, null);
-        ServletActionContext.setServletContext(servletContext);
-
-
-        request.setRequestURI("/tutorial/test2.action");
-        ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request,
configurationManager);
-        dispatcher.serviceAction(request, response, servletContext, mapping);
-        assertEquals("beforenestedafter", stringWriter.toString());
-    }
-
-     public void testActionThatSucceedsTag() throws Exception {
-        //get fm config to use it in mock servlet context
-        FreemarkerManager freemarkerManager = container.getInstance(FreemarkerManager.class);
-        Configuration freemarkerConfig = freemarkerManager.getConfiguration(ServletActionContext.getServletContext());
-        freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
-
-        ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class);
-        File file = new File(FreeMarkerResultTest.class.getResource("callActionFreeMarker2.ftl").toURI());
-        EasyMock.expect(servletContext.getRealPath("/tutorial/org/apache/struts2/views/freemarker/callActionFreeMarker2.ftl")).andReturn(file.getAbsolutePath());
-        file = new File(FreeMarkerResultTest.class.getResource("nested.ftl").toURI());
-        EasyMock.expect(servletContext.getRealPath("/tutorial/org/apache/struts2/views/freemarker/nested.ftl")).andReturn(file.getAbsolutePath());
-        EasyMock.expect(servletContext.getAttribute(FreemarkerManager.CONFIG_SERVLET_CONTEXT_KEY)).andReturn(freemarkerConfig).anyTimes();
-        EasyMock.replay(servletContext);
-
-        freemarkerConfig.setServletContextForTemplateLoading(servletContext, null); 
-        ServletActionContext.setServletContext(servletContext); 
-
-
-        request.setRequestURI("/tutorial/test5.action");
-        ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request,
configurationManager);
-        dispatcher.serviceAction(request, response, servletContext, mapping);
-        assertEquals("beforenestedafter", stringWriter.toString());
-    }
-
     public void testWriteIfCompleted() throws Exception {
         FreemarkerResult result = new FreemarkerResult();
         result.setLocation("someFreeMarkerFile.ftl");
@@ -138,21 +92,21 @@ public class FreeMarkerResultTest extends StrutsInternalTestCase {
     }
 
     public void testContentTypeIsNotOverwritten() throws Exception {
-         servletContext.setRealPath(new File(FreeMarkerResultTest.class.getResource(
-					"nested.ftl").toURI()).toURL().getFile());
+        servletContext.setRealPath(new File(FreeMarkerResultTest.class.getResource(
+                "nested.ftl").toURI()).toURL().getFile());
 
         FreemarkerResult result = new FreemarkerResult();
         result.setLocation("nested.ftl");
         result.setFreemarkerManager(mgr);
-                                   
-        response.setContentType("contenttype"); 
+
+        response.setContentType("contenttype");
         result.execute(invocation);
         assertEquals("contenttype", response.getContentType());
     }
 
     public void testDefaultContentType() throws Exception {
-         servletContext.setRealPath(new File(FreeMarkerResultTest.class.getResource(
-					"nested.ftl").toURI()).toURL().getFile());
+        servletContext.setRealPath(new File(FreeMarkerResultTest.class.getResource(
+                "nested.ftl").toURI()).toURL().getFile());
 
         FreemarkerResult result = new FreemarkerResult();
         result.setLocation("nested.ftl");
@@ -164,8 +118,8 @@ public class FreeMarkerResultTest extends StrutsInternalTestCase {
     }
 
     public void testContentTypeFromTemplate() throws Exception {
-         servletContext.setRealPath(new File(FreeMarkerResultTest.class.getResource(
-					"something.ftl").toURI()).toURL().getFile());
+        servletContext.setRealPath(new File(FreeMarkerResultTest.class.getResource(
+                "something.ftl").toURI()).toURL().getFile());
 
         FreemarkerResult result = new FreemarkerResult();
         result.setLocation("something.ftl");
@@ -176,140 +130,6 @@ public class FreeMarkerResultTest extends StrutsInternalTestCase {
         assertEquals("text/xml", response.getContentType());
     }
 
-    public void testDynamicAttributesSupport() throws Exception {
-        //get fm config to use it in mock servlet context
-        FreemarkerManager freemarkerManager = container.getInstance(FreemarkerManager.class);
-        Configuration freemarkerConfig = freemarkerManager.getConfiguration(ServletActionContext.getServletContext());
-        freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
-
-        ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class);
-
-        File file = new File(FreeMarkerResultTest.class.getResource("dynaAttributes.ftl").toURI());
-        EasyMock.expect(servletContext.getRealPath("/tutorial/org/apache/struts2/views/freemarker/dynaAttributes.ftl")).andReturn(file.getAbsolutePath());
-
-        file = new File(ClassLoaderUtil.getResource("template/simple/text.ftl", getClass()).toURI());
-        EasyMock.expect(servletContext.getRealPath("/template/simple/text.ftl")).andReturn(file.getAbsolutePath());
-
-        file = new File(ClassLoaderUtil.getResource("template/simple/css.ftl", getClass()).toURI());
-        EasyMock.expect(servletContext.getRealPath("/template/simple/css.ftl")).andReturn(file.getAbsolutePath());
-        EasyMock.expect(servletContext.getRealPath("/template/~~~simple/css.ftl")).andReturn(file.getAbsolutePath());
-
-        file = new File(ClassLoaderUtil.getResource("template/simple/scripting-events.ftl",
getClass()).toURI());
-        EasyMock.expect(servletContext.getRealPath("/template/simple/scripting-events.ftl")).andReturn(file.getAbsolutePath());
-        EasyMock.expect(servletContext.getRealPath("/template/~~~simple/scripting-events.ftl")).andReturn(file.getAbsolutePath());
-
-        file = new File(ClassLoaderUtil.getResource("template/simple/common-attributes.ftl",
getClass()).toURI());
-        EasyMock.expect(servletContext.getRealPath("/template/simple/common-attributes.ftl")).andReturn(file.getAbsolutePath());
-        EasyMock.expect(servletContext.getRealPath("/template/~~~simple/common-attributes.ftl")).andReturn(file.getAbsolutePath());
-
-        file = new File(ClassLoaderUtil.getResource("template/simple/dynamic-attributes.ftl",
getClass()).toURI());
-        EasyMock.expect(servletContext.getRealPath("/template/simple/dynamic-attributes.ftl")).andReturn(file.getAbsolutePath());
-        EasyMock.expect(servletContext.getRealPath("/template/~~~simple/dynamic-attributes.ftl")).andReturn(file.getAbsolutePath());
-
-        EasyMock.expect(servletContext.getAttribute(FreemarkerManager.CONFIG_SERVLET_CONTEXT_KEY)).andReturn(freemarkerConfig).anyTimes();
-        EasyMock.replay(servletContext);
-
-        freemarkerConfig.setServletContextForTemplateLoading(servletContext, null);
-        ServletActionContext.setServletContext(servletContext);
-
-
-        request.setRequestURI("/tutorial/test6.action");
-        ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request,
configurationManager);
-        dispatcher.serviceAction(request, response, servletContext, mapping);
-
-        // TODO lukaszlenart: remove expectedJDK15 and if() after switching to Java 1.6
-        String expectedJDK15 =
-                "<input type=\"text\" name=\"test\" value=\"\" id=\"test\" foo=\"bar\"
placeholder=\"input\"/>"
-                + "<input type=\"text\" name=\"test\" value=\"\" id=\"test\" foo=\"bar\"
placeholder=\"input\"/>"
-                + "<input type=\"text\" name=\"test\" value=\"\" id=\"test\" break=\"true\"/>";
-        String expectedJDK16 =
-                "<input type=\"text\" name=\"test\" value=\"\" id=\"test\" placeholder=\"input\"
foo=\"bar\"/>"
-                + "<input type=\"text\" name=\"test\" value=\"\" id=\"test\" placeholder=\"input\"
foo=\"bar\"/>"
-                + "<input type=\"text\" name=\"test\" value=\"\" id=\"test\" break=\"true\"/>"
-                + "<input type=\"text\" name=\"required\" value=\"\" id=\"required\" required=\"true\"/>";
-
-        String result = stringWriter.toString();
-
-        if (result.contains("foo=\"bar\" placeholder=\"input\"")) {
-            assertEquals(expectedJDK15, result);
-        } else {
-            assertEquals(expectedJDK16, result);
-        }
-    }
-
-    public void testManualListInTemplate() throws Exception {
-        FreemarkerManager freemarkerManager = container.getInstance(FreemarkerManager.class);
-        Configuration freemarkerConfig = freemarkerManager.getConfiguration(ServletActionContext.getServletContext());
-        freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
-
-        ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class);
-
-        File file = new File(FreeMarkerResultTest.class.getResource("manual-list.ftl").toURI());
-        EasyMock.expect(servletContext.getRealPath("/tutorial/org/apache/struts2/views/freemarker/manual-list.ftl")).andReturn(file.getAbsolutePath());
-
-        file = new File(ClassLoaderUtil.getResource("template/simple/radiomap.ftl", getClass()).toURI());
-        EasyMock.expect(servletContext.getRealPath("/template/simple/radiomap.ftl")).andReturn(file.getAbsolutePath());
-
-        file = new File(ClassLoaderUtil.getResource("template/simple/css.ftl", getClass()).toURI());
-        EasyMock.expect(servletContext.getRealPath("/template/simple/css.ftl")).andReturn(file.getAbsolutePath());
-        EasyMock.expect(servletContext.getRealPath("/template/~~~simple/css.ftl")).andReturn(file.getAbsolutePath());
-
-        file = new File(ClassLoaderUtil.getResource("template/simple/scripting-events.ftl",
getClass()).toURI());
-        EasyMock.expect(servletContext.getRealPath("/template/simple/scripting-events.ftl")).andReturn(file.getAbsolutePath());
-        EasyMock.expect(servletContext.getRealPath("/template/~~~simple/scripting-events.ftl")).andReturn(file.getAbsolutePath());
-
-        file = new File(ClassLoaderUtil.getResource("template/simple/common-attributes.ftl",
getClass()).toURI());
-        EasyMock.expect(servletContext.getRealPath("/template/simple/common-attributes.ftl")).andReturn(file.getAbsolutePath());
-        EasyMock.expect(servletContext.getRealPath("/template/~~~simple/common-attributes.ftl")).andReturn(file.getAbsolutePath());
-
-        file = new File(ClassLoaderUtil.getResource("template/simple/dynamic-attributes.ftl",
getClass()).toURI());
-        EasyMock.expect(servletContext.getRealPath("/template/simple/dynamic-attributes.ftl")).andReturn(file.getAbsolutePath());
-        EasyMock.expect(servletContext.getRealPath("/template/~~~simple/dynamic-attributes.ftl")).andReturn(file.getAbsolutePath());
-
-        EasyMock.expect(servletContext.getAttribute(FreemarkerManager.CONFIG_SERVLET_CONTEXT_KEY)).andReturn(freemarkerConfig).anyTimes();
-        EasyMock.replay(servletContext);
-
-        freemarkerConfig.setServletContextForTemplateLoading(servletContext, null);
-        ServletActionContext.setServletContext(servletContext);
-
-
-        request.setRequestURI("/tutorial/test7.action");
-        ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request,
configurationManager);
-        dispatcher.serviceAction(request, response, servletContext, mapping);
-        String expected = "<input type=\"radio\" name=\"client\" id=\"client_foo\" value=\"foo\"/><label
for=\"client_foo\">foo</label>\n"
-                + "<input type=\"radio\" name=\"client\" id=\"client_bar\" value=\"bar\"/><label
for=\"client_bar\">bar</label>\n"
-                + "\n"
-                + "<input type=\"radio\" name=\"car\" id=\"carford\" value=\"ford\"/><label
for=\"carford\">Ford Motor Co</label>\n"
-                + "<input type=\"radio\" name=\"car\" id=\"cartoyota\" value=\"toyota\"/><label
for=\"cartoyota\">Toyota</label>\n";
-        assertEquals(normalize(expected), normalize(stringWriter.toString()));
-    }
-
-    public void testDynamicAttributesInTheme() throws Exception {
-        FreemarkerManager freemarkerManager = container.getInstance(FreemarkerManager.class);
-        Configuration freemarkerConfig = freemarkerManager.getConfiguration(ServletActionContext.getServletContext());
-        freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
-
-        ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class);
-
-        File file = new File(FreeMarkerResultTest.class.getResource("customTextField.ftl").toURI());
-        EasyMock.expect(servletContext.getRealPath("/tutorial/org/apache/struts2/views/freemarker/customTextField.ftl")).andReturn(file.getAbsolutePath());
-
-        file = new File(ClassLoaderUtil.getResource("template/test/text.ftl", getClass()).toURI());
-        EasyMock.expect(servletContext.getRealPath("/template/test/text.ftl")).andReturn(file.getAbsolutePath());
-
-        EasyMock.expect(servletContext.getAttribute(FreemarkerManager.CONFIG_SERVLET_CONTEXT_KEY)).andReturn(freemarkerConfig).anyTimes();
-        EasyMock.replay(servletContext);
-
-        freemarkerConfig.setServletContextForTemplateLoading(servletContext, null);
-        ServletActionContext.setServletContext(servletContext);
-
-        request.setRequestURI("/tutorial/test8.action");
-        ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request,
configurationManager);
-        dispatcher.serviceAction(request, response, servletContext, mapping);
-        String expected = "<input type=\"text\"autofocus=\"autofocus\"/>";
-        assertEquals(expected, stringWriter.toString());
-    }
-
     protected void setUp() throws Exception {
         super.setUp();
         mgr = new FreemarkerManager();
@@ -345,7 +165,7 @@ public class FreeMarkerResultTest extends StrutsInternalTestCase {
         invocation.setStack(stack);
         invocation.setInvocationContext(context);
         servletContext.setRealPath(new File(FreeMarkerResultTest.class.getResource(
-					"someFreeMarkerFile.ftl").toURI()).toURL().getFile());
+                "someFreeMarkerFile.ftl").toURI()).toURL().getFile());
     }
 
     protected void tearDown() throws Exception {

http://git-wip-us.apache.org/repos/asf/struts/blob/d4ddd74e/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerResultMockedTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerResultMockedTest.java
b/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerResultMockedTest.java
new file mode 100644
index 0000000..9a9584a
--- /dev/null
+++ b/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerResultMockedTest.java
@@ -0,0 +1,262 @@
+package org.apache.struts2.views.freemarker;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.mock.MockActionInvocation;
+import com.opensymphony.xwork2.util.ClassLoaderUtil;
+import com.opensymphony.xwork2.util.ValueStack;
+import com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory;
+import freemarker.template.Configuration;
+import freemarker.template.TemplateExceptionHandler;
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.StrutsInternalTestCase;
+import org.apache.struts2.StrutsStatics;
+import org.apache.struts2.dispatcher.mapper.ActionMapper;
+import org.apache.struts2.dispatcher.mapper.ActionMapping;
+import org.apache.struts2.views.jsp.StrutsMockHttpServletResponse;
+import org.easymock.EasyMock;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+import javax.servlet.ServletContext;
+import java.io.File;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+
+import static org.apache.struts2.views.jsp.AbstractUITagTest.normalize;
+
+public class FreemarkerResultMockedTest extends StrutsInternalTestCase {
+
+    ValueStack stack;
+    MockActionInvocation invocation;
+    ActionContext context;
+    StrutsMockHttpServletResponse response;
+    PrintWriter writer;
+    StringWriter stringWriter;
+    ServletContext servletContext;
+    FreemarkerManager mgr;
+    MockHttpServletRequest request;
+
+    public void testActionThatThrowsExceptionTag() throws Exception {
+        //get fm config to use it in mock servlet context
+        FreemarkerManager freemarkerManager = container.getInstance(FreemarkerManager.class);
+        Configuration freemarkerConfig = freemarkerManager.getConfiguration(ServletActionContext.getServletContext());
+        freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
+
+        servletContext = EasyMock.createNiceMock(ServletContext.class);
+        File file = new File(FreeMarkerResultTest.class.getResource("callActionFreeMarker2.ftl").toURI());
+        EasyMock.expect(servletContext.getRealPath("/tutorial/org/apache/struts2/views/freemarker/callActionFreeMarker.ftl")).andReturn(file.getAbsolutePath());
+        file = new File(FreeMarkerResultTest.class.getResource("nested.ftl").toURI());
+        EasyMock.expect(servletContext.getRealPath("/tutorial/org/apache/struts2/views/freemarker/nested.ftl")).andReturn(file.getAbsolutePath());
+        EasyMock.expect(servletContext.getAttribute(FreemarkerManager.CONFIG_SERVLET_CONTEXT_KEY)).andReturn(freemarkerConfig).anyTimes();
+        EasyMock.replay(servletContext);
+
+        freemarkerConfig.setServletContextForTemplateLoading(servletContext, null);
+        ServletActionContext.setServletContext(servletContext);
+
+        init();
+
+        request.setRequestURI("/tutorial/test2.action");
+        ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request,
configurationManager);
+        dispatcher.serviceAction(request, response, mapping);
+        assertEquals("beforenestedafter", stringWriter.toString());
+    }
+
+    public void testActionThatSucceedsTag() throws Exception {
+        //get fm config to use it in mock servlet context
+        FreemarkerManager freemarkerManager = container.getInstance(FreemarkerManager.class);
+        Configuration freemarkerConfig = freemarkerManager.getConfiguration(ServletActionContext.getServletContext());
+        freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
+
+        servletContext = EasyMock.createNiceMock(ServletContext.class);
+        File file = new File(FreeMarkerResultTest.class.getResource("callActionFreeMarker2.ftl").toURI());
+        EasyMock.expect(servletContext.getRealPath("/tutorial/org/apache/struts2/views/freemarker/callActionFreeMarker2.ftl")).andReturn(file.getAbsolutePath());
+        file = new File(FreeMarkerResultTest.class.getResource("nested.ftl").toURI());
+        EasyMock.expect(servletContext.getRealPath("/tutorial/org/apache/struts2/views/freemarker/nested.ftl")).andReturn(file.getAbsolutePath());
+        EasyMock.expect(servletContext.getAttribute(FreemarkerManager.CONFIG_SERVLET_CONTEXT_KEY)).andReturn(freemarkerConfig).anyTimes();
+        EasyMock.replay(servletContext);
+
+        freemarkerConfig.setServletContextForTemplateLoading(servletContext, null);
+        ServletActionContext.setServletContext(servletContext);
+
+        init();
+
+        request.setRequestURI("/tutorial/test5.action");
+        ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request,
configurationManager);
+        dispatcher.serviceAction(request, response, mapping);
+        assertEquals("beforenestedafter", stringWriter.toString());
+    }
+
+    public void testDynamicAttributesSupport() throws Exception {
+        //get fm config to use it in mock servlet context
+        FreemarkerManager freemarkerManager = container.getInstance(FreemarkerManager.class);
+        Configuration freemarkerConfig = freemarkerManager.getConfiguration(ServletActionContext.getServletContext());
+        freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
+
+        servletContext = EasyMock.createNiceMock(ServletContext.class);
+
+        File file = new File(FreeMarkerResultTest.class.getResource("dynaAttributes.ftl").toURI());
+        EasyMock.expect(servletContext.getRealPath("/tutorial/org/apache/struts2/views/freemarker/dynaAttributes.ftl")).andReturn(file.getAbsolutePath());
+
+        file = new File(ClassLoaderUtil.getResource("template/simple/text.ftl", getClass()).toURI());
+        EasyMock.expect(servletContext.getRealPath("/template/simple/text.ftl")).andReturn(file.getAbsolutePath());
+
+        file = new File(ClassLoaderUtil.getResource("template/simple/css.ftl", getClass()).toURI());
+        EasyMock.expect(servletContext.getRealPath("/template/simple/css.ftl")).andReturn(file.getAbsolutePath());
+        EasyMock.expect(servletContext.getRealPath("/template/~~~simple/css.ftl")).andReturn(file.getAbsolutePath());
+
+        file = new File(ClassLoaderUtil.getResource("template/simple/scripting-events.ftl",
getClass()).toURI());
+        EasyMock.expect(servletContext.getRealPath("/template/simple/scripting-events.ftl")).andReturn(file.getAbsolutePath());
+        EasyMock.expect(servletContext.getRealPath("/template/~~~simple/scripting-events.ftl")).andReturn(file.getAbsolutePath());
+
+        file = new File(ClassLoaderUtil.getResource("template/simple/common-attributes.ftl",
getClass()).toURI());
+        EasyMock.expect(servletContext.getRealPath("/template/simple/common-attributes.ftl")).andReturn(file.getAbsolutePath());
+        EasyMock.expect(servletContext.getRealPath("/template/~~~simple/common-attributes.ftl")).andReturn(file.getAbsolutePath());
+
+        file = new File(ClassLoaderUtil.getResource("template/simple/dynamic-attributes.ftl",
getClass()).toURI());
+        EasyMock.expect(servletContext.getRealPath("/template/simple/dynamic-attributes.ftl")).andReturn(file.getAbsolutePath());
+        EasyMock.expect(servletContext.getRealPath("/template/~~~simple/dynamic-attributes.ftl")).andReturn(file.getAbsolutePath());
+
+        EasyMock.expect(servletContext.getAttribute(FreemarkerManager.CONFIG_SERVLET_CONTEXT_KEY)).andReturn(freemarkerConfig).anyTimes();
+        EasyMock.replay(servletContext);
+
+        freemarkerConfig.setServletContextForTemplateLoading(servletContext, null);
+        ServletActionContext.setServletContext(servletContext);
+
+        init();
+
+        request.setRequestURI("/tutorial/test6.action");
+        ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request,
configurationManager);
+        dispatcher.serviceAction(request, response, mapping);
+
+        // TODO lukaszlenart: remove expectedJDK15 and if() after switching to Java 1.6
+        String expectedJDK15 =
+                "<input type=\"text\" name=\"test\" value=\"\" id=\"test\" foo=\"bar\"
placeholder=\"input\"/>"
+                        + "<input type=\"text\" name=\"test\" value=\"\" id=\"test\" foo=\"bar\"
placeholder=\"input\"/>"
+                        + "<input type=\"text\" name=\"test\" value=\"\" id=\"test\" break=\"true\"/>";
+        String expectedJDK16 =
+                "<input type=\"text\" name=\"test\" value=\"\" id=\"test\" placeholder=\"input\"
foo=\"bar\"/>"
+                        + "<input type=\"text\" name=\"test\" value=\"\" id=\"test\" placeholder=\"input\"
foo=\"bar\"/>"
+                        + "<input type=\"text\" name=\"test\" value=\"\" id=\"test\" break=\"true\"/>"
+                        + "<input type=\"text\" name=\"required\" value=\"\" id=\"required\"
required=\"true\"/>";
+
+        String result = stringWriter.toString();
+
+        if (result.contains("foo=\"bar\" placeholder=\"input\"")) {
+            assertEquals(expectedJDK15, result);
+        } else {
+            assertEquals(expectedJDK16, result);
+        }
+    }
+
+    public void testManualListInTemplate() throws Exception {
+        FreemarkerManager freemarkerManager = container.getInstance(FreemarkerManager.class);
+        Configuration freemarkerConfig = freemarkerManager.getConfiguration(ServletActionContext.getServletContext());
+        freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
+
+        servletContext = EasyMock.createNiceMock(ServletContext.class);
+
+        File file = new File(FreeMarkerResultTest.class.getResource("manual-list.ftl").toURI());
+        EasyMock.expect(servletContext.getRealPath("/tutorial/org/apache/struts2/views/freemarker/manual-list.ftl")).andReturn(file.getAbsolutePath());
+
+        file = new File(ClassLoaderUtil.getResource("template/simple/radiomap.ftl", getClass()).toURI());
+        EasyMock.expect(servletContext.getRealPath("/template/simple/radiomap.ftl")).andReturn(file.getAbsolutePath());
+
+        file = new File(ClassLoaderUtil.getResource("template/simple/css.ftl", getClass()).toURI());
+        EasyMock.expect(servletContext.getRealPath("/template/simple/css.ftl")).andReturn(file.getAbsolutePath());
+        EasyMock.expect(servletContext.getRealPath("/template/~~~simple/css.ftl")).andReturn(file.getAbsolutePath());
+
+        file = new File(ClassLoaderUtil.getResource("template/simple/scripting-events.ftl",
getClass()).toURI());
+        EasyMock.expect(servletContext.getRealPath("/template/simple/scripting-events.ftl")).andReturn(file.getAbsolutePath());
+        EasyMock.expect(servletContext.getRealPath("/template/~~~simple/scripting-events.ftl")).andReturn(file.getAbsolutePath());
+
+        file = new File(ClassLoaderUtil.getResource("template/simple/common-attributes.ftl",
getClass()).toURI());
+        EasyMock.expect(servletContext.getRealPath("/template/simple/common-attributes.ftl")).andReturn(file.getAbsolutePath());
+        EasyMock.expect(servletContext.getRealPath("/template/~~~simple/common-attributes.ftl")).andReturn(file.getAbsolutePath());
+
+        file = new File(ClassLoaderUtil.getResource("template/simple/dynamic-attributes.ftl",
getClass()).toURI());
+        EasyMock.expect(servletContext.getRealPath("/template/simple/dynamic-attributes.ftl")).andReturn(file.getAbsolutePath());
+        EasyMock.expect(servletContext.getRealPath("/template/~~~simple/dynamic-attributes.ftl")).andReturn(file.getAbsolutePath());
+
+        EasyMock.expect(servletContext.getAttribute(FreemarkerManager.CONFIG_SERVLET_CONTEXT_KEY)).andReturn(freemarkerConfig).anyTimes();
+        EasyMock.replay(servletContext);
+
+        freemarkerConfig.setServletContextForTemplateLoading(servletContext, null);
+        ServletActionContext.setServletContext(servletContext);
+
+        init();
+
+        request.setRequestURI("/tutorial/test7.action");
+        ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request,
configurationManager);
+        dispatcher.serviceAction(request, response, mapping);
+        String expected = "<input type=\"radio\" name=\"client\" id=\"client_foo\" value=\"foo\"/><label
for=\"client_foo\">foo</label>\n"
+                + "<input type=\"radio\" name=\"client\" id=\"client_bar\" value=\"bar\"/><label
for=\"client_bar\">bar</label>\n"
+                + "\n"
+                + "<input type=\"radio\" name=\"car\" id=\"carford\" value=\"ford\"/><label
for=\"carford\">Ford Motor Co</label>\n"
+                + "<input type=\"radio\" name=\"car\" id=\"cartoyota\" value=\"toyota\"/><label
for=\"cartoyota\">Toyota</label>\n";
+        assertEquals(normalize(expected), normalize(stringWriter.toString()));
+    }
+
+    public void testDynamicAttributesInTheme() throws Exception {
+        FreemarkerManager freemarkerManager = container.getInstance(FreemarkerManager.class);
+        Configuration freemarkerConfig = freemarkerManager.getConfiguration(ServletActionContext.getServletContext());
+        freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
+
+        servletContext = EasyMock.createNiceMock(ServletContext.class);
+
+        File file = new File(FreeMarkerResultTest.class.getResource("customTextField.ftl").toURI());
+        EasyMock.expect(servletContext.getRealPath("/tutorial/org/apache/struts2/views/freemarker/customTextField.ftl")).andReturn(file.getAbsolutePath());
+
+        file = new File(ClassLoaderUtil.getResource("template/test/text.ftl", getClass()).toURI());
+        EasyMock.expect(servletContext.getRealPath("/template/test/text.ftl")).andReturn(file.getAbsolutePath());
+
+        EasyMock.expect(servletContext.getAttribute(FreemarkerManager.CONFIG_SERVLET_CONTEXT_KEY)).andReturn(freemarkerConfig).anyTimes();
+        EasyMock.replay(servletContext);
+
+        freemarkerConfig.setServletContextForTemplateLoading(servletContext, null);
+        ServletActionContext.setServletContext(servletContext);
+
+        init();
+
+        request.setRequestURI("/tutorial/test8.action");
+        ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request,
configurationManager);
+        dispatcher.serviceAction(request, response, mapping);
+        String expected = "<input type=\"text\"autofocus=\"autofocus\"/>";
+        assertEquals(expected, stringWriter.toString());
+    }
+
+    private void init() throws MalformedURLException, URISyntaxException {
+        mgr = new FreemarkerManager();
+        mgr.setEncoding("UTF-8");
+
+        DefaultFileManagerFactory factory = new DefaultFileManagerFactory();
+        container.inject(factory);
+        mgr.setFileManagerFactory(factory);
+
+        FreemarkerThemeTemplateLoader themeLoader = new FreemarkerThemeTemplateLoader();
+        container.inject(themeLoader);
+        mgr.setThemeTemplateLoader(themeLoader);
+
+        stringWriter = new StringWriter();
+        writer = new PrintWriter(stringWriter);
+        response = new StrutsMockHttpServletResponse();
+        response.setWriter(writer);
+        request = new MockHttpServletRequest();
+        stack = ActionContext.getContext().getValueStack();
+
+        context = new ActionContext(stack.getContext());
+        context.put(StrutsStatics.HTTP_RESPONSE, response);
+        context.put(StrutsStatics.HTTP_REQUEST, request);
+        context.put(StrutsStatics.SERVLET_CONTEXT, servletContext);
+
+        ServletActionContext.setServletContext(servletContext);
+        ServletActionContext.setRequest(request);
+        ServletActionContext.setResponse(response);
+        servletContext.setAttribute(FreemarkerManager.CONFIG_SERVLET_CONTEXT_KEY, null);
+
+        invocation = new MockActionInvocation();
+        invocation.setStack(stack);
+        invocation.setInvocationContext(context);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/struts/blob/d4ddd74e/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java
index 98eadb6..36b04fa 100644
--- a/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java
+++ b/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java
@@ -120,8 +120,7 @@ public abstract class AbstractTagTest extends StrutsInternalTestCase {
                 session,
                 new ApplicationMap(pageContext.getServletContext()),
                 request,
-                response,
-                pageContext.getServletContext());
+                response);
         // let's not set the locale -- there is a test that checks if Dispatcher actually
picks this up...
         // ... but generally we want to just use no locale (let it stay system default)
         extraContext.remove(ActionContext.LOCALE);

http://git-wip-us.apache.org/repos/asf/struts/blob/d4ddd74e/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java
index 1a970ee..50bf576 100644
--- a/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java
+++ b/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java
@@ -555,8 +555,7 @@ public class URLTagTest extends AbstractUITagTest {
                 session,
                 new ApplicationMap(pageContext.getServletContext()),
                 request,
-                response,
-                pageContext.getServletContext());
+                response);
         // let's not set the locale -- there is a test that checks if Dispatcher actually
picks this up...
         // ... but generally we want to just use no locale (let it stay system default)
         extraContext.remove(ActionContext.LOCALE);


Mime
View raw message