[struts] 02/10: WW-5334 Clean up VelocityStrutsUtil
This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch WW-5334-velocity-manager in repository https://gitbox.apache.org/repos/asf/struts.git commit f4daeb3ea4539e00037b00cb0cb768307132a138 Author: Kusal Kithul-Godage AuthorDate: Thu Aug 17 18:57:58 2023 +1000 WW-5334 Clean up VelocityStrutsUtil --- .../struts2/views/velocity/VelocityStrutsUtil.java | 16 +++- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityStrutsUtil.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityStrutsUtil.java index 853669226..9ecc598d8 100644 --- a/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityStrutsUtil.java +++ b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityStrutsUtil.java @@ -18,12 +18,7 @@ */ package org.apache.struts2.views.velocity; -import java.io.CharArrayWriter; -import java.io.IOException; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import com.opensymphony.xwork2.util.ValueStack; import org.apache.struts2.util.StrutsUtil; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.context.Context; @@ -31,7 +26,10 @@ import org.apache.velocity.exception.MethodInvocationException; import org.apache.velocity.exception.ParseErrorException; import org.apache.velocity.exception.ResourceNotFoundException; -import com.opensymphony.xwork2.util.ValueStack; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.CharArrayWriter; +import java.io.IOException; /** * Struts velocity related util. @@ -39,8 +37,8 @@ import com.opensymphony.xwork2.util.ValueStack; */ public class VelocityStrutsUtil extends StrutsUtil { -private Context ctx; -private VelocityEngine velocityEngine; +private final Context ctx; +private final VelocityEngine velocityEngine; public VelocityStrutsUtil(VelocityEngine engine, Context ctx, ValueStack stack, HttpServletRequest request, HttpServletResponse response) { super(stack, request, response);
[struts] 04/10: WW-5334 Clean up VelocityManager context creation
This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch WW-5334-velocity-manager in repository https://gitbox.apache.org/repos/asf/struts.git commit 2abf8677bf33d57b840fa56d35e1a2569a5d0df4 Author: Kusal Kithul-Godage AuthorDate: Thu Aug 17 18:59:10 2023 +1000 WW-5334 Clean up VelocityManager context creation --- .../struts2/views/velocity/VelocityManager.java| 130 + 1 file changed, 55 insertions(+), 75 deletions(-) diff --git a/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java index 939f23bec..8c8ee17bf 100644 --- a/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java +++ b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java @@ -47,12 +47,16 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Properties; -import java.util.Set; -import java.util.StringTokenizer; + +import static java.lang.String.format; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; +import static org.apache.struts2.views.util.ContextUtil.STRUTS; /** * Manages the environment for Velocity result types @@ -61,8 +65,6 @@ public class VelocityManager { private static final Logger LOG = LogManager.getLogger(VelocityManager.class); -public static final String STRUTS = "struts"; - private ObjectFactory objectFactory; public static final String KEY_VELOCITY_STRUTS_CONTEXT = ".KEY_velocity.struts2.context"; @@ -93,11 +95,8 @@ public class VelocityManager { @Inject public void setContainer(Container container) { -List list = new ArrayList<>(); -Set prefixes = container.getInstanceNames(TagLibraryDirectiveProvider.class); -for (String prefix : prefixes) { -list.add(container.getInstance(TagLibraryDirectiveProvider.class, prefix)); -} +List list = container.getInstanceNames(TagLibraryDirectiveProvider.class).stream() +.map(prefix -> container.getInstance(TagLibraryDirectiveProvider.class, prefix)).collect(toList()); this.tagLibraries = Collections.unmodifiableList(list); } @@ -130,33 +129,38 @@ public class VelocityManager { * @return a new StrutsVelocityContext */ public Context createContext(ValueStack stack, HttpServletRequest req, HttpServletResponse res) { -List chainedContexts = prepareChainedContexts(req, res, stack.getContext()); -StrutsVelocityContext context = new StrutsVelocityContext(chainedContexts, stack); -Map standardMap = ContextUtil.getStandardContext(stack, req, res); -for (Map.Entry entry : standardMap.entrySet()) { -context.put(entry.getKey(), entry.getValue()); +Context context = buildToolContext(); +if (context == null) { +context = buildContext(stack, req, res); } +req.setAttribute(KEY_VELOCITY_STRUTS_CONTEXT, context); +return context; +} + +protected Context buildContext(ValueStack stack, HttpServletRequest req, HttpServletResponse res) { +List chainedContexts = prepareChainedContexts(req, res, stack.getContext()); +Context context = new StrutsVelocityContext(chainedContexts, stack); +ContextUtil.getStandardContext(stack, req, res).forEach(context::put); context.put(STRUTS, new VelocityStrutsUtil(velocityEngine, context, stack, req, res)); +return context; +} -ServletContext ctx = null; +protected Context buildToolContext() { +if (toolboxManager == null) { +return null; +} +ServletContext ctx; try { ctx = ServletActionContext.getServletContext(); -} catch (NullPointerException npe) { -// in case this was used outside the lifecycle of struts servlet -LOG.debug("internal toolbox context ignored"); +} catch (NullPointerException e) { +return null; } - -Context result; -if (toolboxManager != null && ctx != null) { -ToolContext chained = new ToolContext(velocityEngine); - chained.addToolbox(toolboxManager.getToolboxFactory().createToolbox(ToolboxFactory.DEFAULT_SCOPE)); -result = chained; -} else { -result = context; +if (ctx == null) { +return null; } - -req.setAttribute(KEY_VELOCITY_STRUTS_CONTEXT, result); -return result; +ToolContext toolContext = new ToolContext(velocityEngine); + toolContext.addToolbox(toolboxManager.getToolboxFactory().createTo
[struts] branch WW-5334-velocity-manager updated (62318f9ac -> 22a6ae9d6)
This is an automated email from the ASF dual-hosted git repository. kusal pushed a change to branch WW-5334-velocity-manager in repository https://gitbox.apache.org/repos/asf/struts.git omit 62318f9ac WW-5334 Fix license for VelocityManagerTest omit f8aa54e65 WW-5334 Add basic unit tests for VelocityManager omit 32c0a01d8 WW-5334 Modernise VelocityResultTest omit 96d37269c WW-5334 Remove unused import XWorkTestCase omit 466360d2a WW-5334 Clean up VelocityManager context creation omit 77b7b8184 WW-5334 Clean up VelocityManager#applyDefaultConfiguration omit 7c70f2757 WW-5334 Clean up VelocityStrutsUtil omit 678c19509 WW-5334 Remove unused imports ContextUtil add ec4dfa3e9 WW-5332 Add validation for package name parsing add 9780e7064 WW-5332 Add additional test cases add 9bbf9c5dc Merge pull request #726 from atlassian/WW-5332-package-validation add 956a956ef WW-5327 Removes duplicated exclusion Refs #715 add fc0eae3ef WW-5327 Removes all duplicated excluded classes add 2e0764f9d Merge pull request #729 from apache/fix/WW-5327-removes-duplicate add 2db7c0439 Uses Java 17 to perform Code Quality check add f58d0f3cc Uses verify phase instead of just test to run integration tests add 433d9c429 Reverts to test phase only when running on JDK 8 & 11 to avoid integration tests clash add 44f0a1bcd Merge pull request #730 from apache/fix/code-quality-on-java17 add 824801796 WW-5334 Delete unneeded override (moved to StrutsPortletTestCaseTest) add ea124a475 Merge pull request #732 from apache/WW-5334-fix-cyclic new 2d6fe8430 WW-5334 Remove unused imports ContextUtil new f4daeb3ea WW-5334 Clean up VelocityStrutsUtil new 114b6e4f2 WW-5334 Clean up VelocityManager#applyDefaultConfiguration new 2abf8677b WW-5334 Clean up VelocityManager context creation new 6d9bfb6af WW-5334 Remove unused import XWorkTestCase new 225063960 WW-5334 Modernise VelocityResultTest new 2fa9d60a2 WW-5334 Add basic unit tests for VelocityManager new d70ad5b73 WW-5334 Fix license for VelocityManagerTest new 94c1b2a29 WW-5334 Add AssertJ as default plugin test dependency new 22a6ae9d6 WW-5334 Add further unit tests to VelocityManagerTest This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (62318f9ac) \ N -- N -- N refs/heads/WW-5334-velocity-manager (22a6ae9d6) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. The 10 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: .github/workflows/maven.yml| 6 +-- Jenkinsfile| 25 +- .../com/opensymphony/xwork2/ognl/OgnlUtil.java | 10 ++-- .../opensymphony/xwork2/util/TextParseUtil.java| 22 - .../src/main/resources/struts-excluded-classes.xml | 4 +- .../com/opensymphony/xwork2/ognl/OgnlUtilTest.java | 19 ++-- plugins/json/pom.xml | 6 --- .../apache/struts2/junit/StrutsTestCaseTest.java | 6 --- plugins/pom.xml| 5 ++ plugins/rest/pom.xml | 6 --- .../views/velocity/VelocityManagerTest.java| 55 +- .../main => velocity/src/test}/resources/tools.xml | 6 +-- 12 files changed, 96 insertions(+), 74 deletions(-) copy plugins/{tiles/src/main => velocity/src/test}/resources/tools.xml (84%)
[struts] 08/10: WW-5334 Fix license for VelocityManagerTest
This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch WW-5334-velocity-manager in repository https://gitbox.apache.org/repos/asf/struts.git commit d70ad5b737824dd17d14d30b67ed24fa03830d46 Author: Kusal Kithul-Godage AuthorDate: Sat Aug 19 13:01:12 2023 +1000 WW-5334 Fix license for VelocityManagerTest --- .../struts2/views/velocity/VelocityManagerTest.java| 18 ++ 1 file changed, 18 insertions(+) diff --git a/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/VelocityManagerTest.java b/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/VelocityManagerTest.java index 692d7d57b..b959dc345 100644 --- a/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/VelocityManagerTest.java +++ b/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/VelocityManagerTest.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.struts2.views.velocity; import com.opensymphony.xwork2.ActionContext;
[struts] 06/10: WW-5334 Modernise VelocityResultTest
This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch WW-5334-velocity-manager in repository https://gitbox.apache.org/repos/asf/struts.git commit 22506396053e3172f29402d5df0e2dba67134921 Author: Kusal Kithul-Godage AuthorDate: Fri Aug 18 10:47:48 2023 +1000 WW-5334 Modernise VelocityResultTest --- .../views/velocity/result/VelocityResultTest.java | 102 +++-- 1 file changed, 54 insertions(+), 48 deletions(-) diff --git a/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/result/VelocityResultTest.java b/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/result/VelocityResultTest.java index b027e928f..fe26dc025 100644 --- a/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/result/VelocityResultTest.java +++ b/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/result/VelocityResultTest.java @@ -18,93 +18,100 @@ */ package org.apache.struts2.views.velocity.result; -import com.opensymphony.xwork2.XWorkTestCase; -import junit.framework.TestCase; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.ActionProxy; +import com.opensymphony.xwork2.util.ValueStack; +import org.apache.struts2.junit.XWorkJUnit4TestCase; import org.apache.struts2.result.StrutsResultSupport; import org.apache.velocity.Template; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.exception.ParseErrorException; import org.apache.velocity.exception.ResourceNotFoundException; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; -import com.mockobjects.dynamic.Mock; -import com.opensymphony.xwork2.ActionContext; -import com.opensymphony.xwork2.ActionInvocation; -import com.opensymphony.xwork2.ActionProxy; -import com.opensymphony.xwork2.util.ValueStack; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.when; +public class VelocityResultTest extends XWorkJUnit4TestCase { -/** - * - */ -public class VelocityResultTest extends XWorkTestCase { +@Rule +public MockitoRule mockitoRule = MockitoJUnit.rule(); +@Mock ActionInvocation actionInvocation; -Mock mockActionProxy; +@Mock +ActionProxy actionProxy; ValueStack stack; String namespace; TestVelocityEngine velocity; -VelocityResult result; +VelocityResult velocityResult; +@Before +public void init() throws Exception { +namespace = "/html"; +velocityResult = new VelocityResult(); +stack = ActionContext.getContext().getValueStack(); +velocity = new TestVelocityEngine(); +when(actionProxy.getNamespace()).thenReturn(namespace); +when(actionInvocation.getProxy()).thenReturn(actionProxy); +when(actionInvocation.getStack()).thenReturn(stack); +} +@Test public void testCanResolveLocationUsingOgnl() throws Exception { -TestResult result = new TestResult(); +TestResult testResult = new TestResult(); String location = "/myaction.action"; Bean bean = new Bean(); bean.setLocation(location); -ValueStack stack = ActionContext.getContext().getValueStack(); stack.push(bean); -TestCase.assertEquals(location, stack.findValue("location")); +assertEquals(location, stack.findValue("location")); -result.setLocation("${location}"); -result.execute(actionInvocation); -TestCase.assertEquals(location, result.finalLocation); +testResult.setLocation("${location}"); +testResult.execute(actionInvocation); +assertEquals(location, testResult.finalLocation); } +@Test public void testCanResolveLocationUsingStaticExpression() throws Exception { TestResult result = new TestResult(); String location = "/any.action"; result.setLocation("${'" + location + "'}"); result.execute(actionInvocation); -TestCase.assertEquals(location, result.finalLocation); +assertEquals(location, result.finalLocation); } +@Test public void testResourcesFoundUsingAbsolutePath() throws Exception { String location = "/WEB-INF/views/registration.vm"; -Template template = result.getTemplate(stack, velocity, actionInvocation, location, "UTF-8"); -TestCase.assertNotNull(template); -TestCase.assertEquals("expect absolute locations to be handled as is", location, velocity.templateName); +Template template = velocityResult.getTemplate(stack, velocity, actionInvocation, location, "UTF-8"); +assertNotNull(template); +assertEquals("expect absolute locations to be handled as is", location, velocity.templateName); }
[struts] 01/10: WW-5334 Remove unused imports ContextUtil
This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch WW-5334-velocity-manager in repository https://gitbox.apache.org/repos/asf/struts.git commit 2d6fe8430158db33d54f457568821136b7c18132 Author: Kusal Kithul-Godage AuthorDate: Thu Aug 17 18:57:13 2023 +1000 WW-5334 Remove unused imports ContextUtil --- core/src/main/java/org/apache/struts2/views/util/ContextUtil.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/views/util/ContextUtil.java b/core/src/main/java/org/apache/struts2/views/util/ContextUtil.java index f021845d5..941321c4d 100644 --- a/core/src/main/java/org/apache/struts2/views/util/ContextUtil.java +++ b/core/src/main/java/org/apache/struts2/views/util/ContextUtil.java @@ -18,10 +18,8 @@ */ package org.apache.struts2.views.util; -import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.util.ValueStack; -import org.apache.struts2.StrutsConstants; import org.apache.struts2.util.StrutsUtil; import org.apache.struts2.views.jsp.ui.OgnlTool;
[struts] 09/10: WW-5334 Add AssertJ as default plugin test dependency
This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch WW-5334-velocity-manager in repository https://gitbox.apache.org/repos/asf/struts.git commit 94c1b2a29b09af5e03e130f462ce0a5a28576ae2 Author: Kusal Kithul-Godage AuthorDate: Sun Aug 20 20:38:35 2023 +1000 WW-5334 Add AssertJ as default plugin test dependency --- plugins/json/pom.xml | 6 -- plugins/pom.xml | 5 + plugins/rest/pom.xml | 6 -- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/plugins/json/pom.xml b/plugins/json/pom.xml index 89ae04411..be47bf6aa 100644 --- a/plugins/json/pom.xml +++ b/plugins/json/pom.xml @@ -83,12 +83,6 @@ spring-web test - - -org.assertj -assertj-core -test - diff --git a/plugins/pom.xml b/plugins/pom.xml index 267985dbe..2a6374a25 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -76,6 +76,11 @@ junit test + +org.assertj +assertj-core +test + org.mockito mockito-core diff --git a/plugins/rest/pom.xml b/plugins/rest/pom.xml index b8306c2cc..1ea0e631e 100644 --- a/plugins/rest/pom.xml +++ b/plugins/rest/pom.xml @@ -90,12 +90,6 @@ spring-core true - - -org.assertj -assertj-core -test -
[struts] 03/10: WW-5334 Clean up VelocityManager#applyDefaultConfiguration
This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch WW-5334-velocity-manager in repository https://gitbox.apache.org/repos/asf/struts.git commit 114b6e4f27480ed8f391772ca908ac5498e0b3b5 Author: Kusal Kithul-Godage AuthorDate: Thu Aug 17 18:58:36 2023 +1000 WW-5334 Clean up VelocityManager#applyDefaultConfiguration --- .../struts2/views/velocity/VelocityManager.java| 56 +++--- 1 file changed, 6 insertions(+), 50 deletions(-) diff --git a/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java index 9ea9d7a7f..939f23bec 100644 --- a/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java +++ b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java @@ -467,11 +467,11 @@ public class VelocityManager { // remove strutsfile from resource loader property String prop = properties.getProperty(Velocity.RESOURCE_LOADER); if (prop.contains("strutsfile,")) { -prop = replace(prop, "strutsfile,", ""); +prop = prop.replace("strutsfile,", ""); } else if (prop.contains(", strutsfile")) { -prop = replace(prop, ", strutsfile", ""); +prop = prop.replace(", strutsfile", ""); } else if (prop.contains("strutsfile")) { -prop = replace(prop, "strutsfile", ""); +prop = prop.replace("strutsfile", ""); } properties.setProperty(Velocity.RESOURCE_LOADER, prop); @@ -488,62 +488,18 @@ public class VelocityManager { properties.setProperty("strutsclass.resource.loader.cache", "true"); // components -StringBuilder sb = new StringBuilder(); - -for (TagLibraryDirectiveProvider tagLibrary : tagLibraries) { -List> directives = tagLibrary.getDirectiveClasses(); -for (Class directive : directives) { -addDirective(sb, directive); -} -} - -String directives = sb.toString(); +String directives = tagLibraries.stream().map(TagLibraryDirectiveProvider::getDirectiveClasses).flatMap( +Collection::stream).map(directive -> directive.getName() + ",").collect(joining()); String userdirective = properties.getProperty("userdirective"); -if ((userdirective == null) || userdirective.trim().equals("")) { +if (userdirective == null || userdirective.trim().isEmpty()) { userdirective = directives; } else { userdirective = userdirective.trim() + "," + directives; } - properties.setProperty("userdirective", userdirective); } -private void addDirective(StringBuilder sb, Class clazz) { -sb.append(clazz.getName()).append(","); -} - -private static String replace(String string, String oldString, String newString) { -if (string == null) { -return null; -} -// If the newString is null, just return the string since there's nothing to replace. -if (newString == null) { -return string; -} -int i = 0; -// Make sure that oldString appears at least once before doing any processing. -if ((i = string.indexOf(oldString, i)) >= 0) { -// Use char []'s, as they are more efficient to deal with. -char[] string2 = string.toCharArray(); -char[] newString2 = newString.toCharArray(); -int oLength = oldString.length(); -StringBuilder buf = new StringBuilder(string2.length); -buf.append(string2, 0, i).append(newString2); -i += oLength; -int j = i; -// Replace all remaining instances of oldString with newString. -while ((i = string.indexOf(oldString, i)) > 0) { -buf.append(string2, j, i - j).append(newString2); -i += oLength; -j = i; -} -buf.append(string2, j, string2.length - j); -return buf.toString(); -} -return string; -} - /** * @return the velocityProperties */
[struts] 05/10: WW-5334 Remove unused import XWorkTestCase
This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch WW-5334-velocity-manager in repository https://gitbox.apache.org/repos/asf/struts.git commit 6d9bfb6afec8eda860dcb4afad1b39913e6c6ff3 Author: Kusal Kithul-Godage AuthorDate: Fri Aug 18 10:46:52 2023 +1000 WW-5334 Remove unused import XWorkTestCase --- core/src/main/java/com/opensymphony/xwork2/XWorkTestCase.java | 7 +-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/XWorkTestCase.java b/core/src/main/java/com/opensymphony/xwork2/XWorkTestCase.java index 402af38e5..941a9e37c 100644 --- a/core/src/main/java/com/opensymphony/xwork2/XWorkTestCase.java +++ b/core/src/main/java/com/opensymphony/xwork2/XWorkTestCase.java @@ -22,14 +22,17 @@ import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.config.ConfigurationException; import com.opensymphony.xwork2.config.ConfigurationManager; import com.opensymphony.xwork2.config.ConfigurationProvider; -import com.opensymphony.xwork2.inject.*; +import com.opensymphony.xwork2.inject.Container; +import com.opensymphony.xwork2.inject.ContainerBuilder; +import com.opensymphony.xwork2.inject.Context; +import com.opensymphony.xwork2.inject.Factory; +import com.opensymphony.xwork2.inject.Scope; import com.opensymphony.xwork2.test.StubConfigurationProvider; import com.opensymphony.xwork2.util.XWorkTestCaseHelper; import com.opensymphony.xwork2.util.location.LocatableProperties; import junit.framework.TestCase; import org.apache.commons.lang3.ClassUtils; -import java.util.HashMap; import java.util.Locale; import java.util.Map;
[struts] 07/10: WW-5334 Add basic unit tests for VelocityManager
This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch WW-5334-velocity-manager in repository https://gitbox.apache.org/repos/asf/struts.git commit 2fa9d60a23a546bd70b2828f31f174066146bd6c Author: Kusal Kithul-Godage AuthorDate: Fri Aug 18 13:17:19 2023 +1000 WW-5334 Add basic unit tests for VelocityManager --- .../views/velocity/VelocityManagerTest.java| 65 ++ 1 file changed, 65 insertions(+) diff --git a/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/VelocityManagerTest.java b/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/VelocityManagerTest.java new file mode 100644 index 0..692d7d57b --- /dev/null +++ b/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/VelocityManagerTest.java @@ -0,0 +1,65 @@ +package org.apache.struts2.views.velocity; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.util.ValueStack; +import org.apache.struts2.junit.StrutsJUnit4TestCase; +import org.apache.struts2.views.jsp.ui.OgnlTool; +import org.apache.velocity.context.Context; +import org.junit.Before; +import org.junit.Test; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; + +public class VelocityManagerTest extends StrutsJUnit4TestCase { + +VelocityManager velocityManager = new VelocityManager(); + +@Before +public void inject() throws Exception { +container.inject(velocityManager); +} + +@Test +public void testProperties() { +Properties props = new Properties(); +velocityManager.setVelocityProperties(props); + +assertEquals(props, velocityManager.getVelocityProperties()); +} + +@Test +public void testInitSuccess() { +velocityManager.init(servletContext); + +assertNotNull(velocityManager.getVelocityEngine()); +} + +@Test +public void testCreateContext() { +velocityManager.init(servletContext); + +Context context = velocityManager.createContext(ActionContext.getContext().getValueStack(), request, response); + +assertNotNull(context); +assertTrue(context.get("struts") instanceof VelocityStrutsUtil); +assertTrue(context.get("ognl") instanceof OgnlTool); +assertTrue(context.get("stack") instanceof ValueStack); +assertTrue(context.get("request") instanceof HttpServletRequest); +assertTrue(context.get("response") instanceof HttpServletResponse); +} + +@Test +public void testInitFailsWithInvalidToolBoxLocation() { +velocityManager.setToolBoxLocation("nonexistent"); + +Exception e = assertThrows(Exception.class, () -> velocityManager.init(servletContext)); +assertTrue(e.getMessage().contains("Could not find any configuration at nonexistent")); +} +}
[struts] 10/10: WW-5334 Add further unit tests to VelocityManagerTest
This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch WW-5334-velocity-manager in repository https://gitbox.apache.org/repos/asf/struts.git commit 22a6ae9d63527fe11fd53ff24f38700854699157 Author: Kusal Kithul-Godage AuthorDate: Sun Aug 20 20:47:40 2023 +1000 WW-5334 Add further unit tests to VelocityManagerTest --- .../views/velocity/VelocityManagerTest.java| 55 +- plugins/velocity/src/test/resources/tools.xml | 20 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/VelocityManagerTest.java b/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/VelocityManagerTest.java index b959dc345..d550e9efb 100644 --- a/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/VelocityManagerTest.java +++ b/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/VelocityManagerTest.java @@ -20,9 +20,12 @@ package org.apache.struts2.views.velocity; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.util.ValueStack; +import org.apache.struts2.ServletActionContext; import org.apache.struts2.junit.StrutsJUnit4TestCase; import org.apache.struts2.views.jsp.ui.OgnlTool; import org.apache.velocity.context.Context; +import org.apache.velocity.tools.ToolContext; +import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -30,18 +33,25 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Properties; +import static org.apache.struts2.views.velocity.VelocityManager.KEY_VELOCITY_STRUTS_CONTEXT; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; public class VelocityManagerTest extends StrutsJUnit4TestCase { VelocityManager velocityManager = new VelocityManager(); @Before -public void inject() throws Exception { +public void inject() { container.inject(velocityManager); +ServletActionContext.setServletContext(servletContext); +} + +@After +public void reset() { +ServletActionContext.setServletContext(null); } @Test @@ -59,6 +69,24 @@ public class VelocityManagerTest extends StrutsJUnit4TestCase { assertNotNull(velocityManager.getVelocityEngine()); } +@Test +public void testInitWithToolbox() { +velocityManager.setToolBoxLocation("tools.xml"); + +velocityManager.init(servletContext); + +assertNotNull(velocityManager.getVelocityEngine()); +assertNotNull(velocityManager.getToolboxManager()); +} + +@Test +public void testInitFailsWithInvalidToolBoxLocation() { +velocityManager.setToolBoxLocation("invalid.xml"); + +Exception e = assertThrows(Exception.class, () -> velocityManager.init(servletContext)); +assertThat(e).hasMessageContaining("Could not find any configuration at invalid.xml"); +} + @Test public void testCreateContext() { velocityManager.init(servletContext); @@ -66,18 +94,23 @@ public class VelocityManagerTest extends StrutsJUnit4TestCase { Context context = velocityManager.createContext(ActionContext.getContext().getValueStack(), request, response); assertNotNull(context); -assertTrue(context.get("struts") instanceof VelocityStrutsUtil); -assertTrue(context.get("ognl") instanceof OgnlTool); -assertTrue(context.get("stack") instanceof ValueStack); -assertTrue(context.get("request") instanceof HttpServletRequest); -assertTrue(context.get("response") instanceof HttpServletResponse); + assertThat(context.get("struts")).isInstanceOf(VelocityStrutsUtil.class); +assertThat(context.get("ognl")).isInstanceOf(OgnlTool.class); +assertThat(context.get("stack")).isInstanceOf(ValueStack.class); + assertThat(context.get("request")).isInstanceOf(HttpServletRequest.class); + assertThat(context.get("response")).isInstanceOf(HttpServletResponse.class); +assertEquals(context, request.getAttribute(KEY_VELOCITY_STRUTS_CONTEXT)); } @Test -public void testInitFailsWithInvalidToolBoxLocation() { -velocityManager.setToolBoxLocation("nonexistent"); +public void testCreateToolboxContext() { +velocityManager.setToolBoxLocation("tools.xml"); +velocityManager.init(servletContext); -Exception e = assertThrows(Exception.class, () -> velocityManager.init(servletContext)); -assertTrue(e.getMessage().contains("Could not find any configuration at nonexistent")); +Context context = velocityManager.createContext(ActionContext.getContext().getValueStack(), request, response); + +
[struts] branch WW-5334-move-convention-test created (now dc43c891d)
This is an automated email from the ASF dual-hosted git repository. kusal pushed a change to branch WW-5334-move-convention-test in repository https://gitbox.apache.org/repos/asf/struts.git at dc43c891d WW-5334 Extract ConventionJUnit4Test into correct module This branch includes the following new commits: new dc43c891d WW-5334 Extract ConventionJUnit4Test into correct module The 1 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.
[struts] 01/01: WW-5334 Extract ConventionJUnit4Test into correct module
This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch WW-5334-move-convention-test in repository https://gitbox.apache.org/repos/asf/struts.git commit dc43c891da38f219835ed7b77b3eb0d19a1f5c78 Author: Kusal Kithul-Godage AuthorDate: Sun Aug 20 22:19:28 2023 +1000 WW-5334 Extract ConventionJUnit4Test into correct module --- plugins/convention/pom.xml| 15 +++ .../src/test/java/actions/MessageAction.java} | 5 +++-- .../apache/struts2/convention/ConventionJUnit4Test.java} | 11 +-- .../src/test/resources/message-success.ftl} | 0 .../test/resources/struts-convention-configuration.xml| 9 + plugins/junit/pom.xml | 14 -- pom.xml | 5 + 7 files changed, 29 insertions(+), 30 deletions(-) diff --git a/plugins/convention/pom.xml b/plugins/convention/pom.xml index 8c366cb64..35f4a63a5 100644 --- a/plugins/convention/pom.xml +++ b/plugins/convention/pom.xml @@ -59,11 +59,26 @@ + +org.apache.struts +struts2-junit-plugin +test + org.easymock easymock test + +org.apache.commons +commons-compress +test + + +org.springframework +spring-web +test + diff --git a/plugins/junit/src/test/java/actions/ViewAction.java b/plugins/convention/src/test/java/actions/MessageAction.java similarity index 85% rename from plugins/junit/src/test/java/actions/ViewAction.java rename to plugins/convention/src/test/java/actions/MessageAction.java index 30635a184..2482fdbc8 100644 --- a/plugins/junit/src/test/java/actions/ViewAction.java +++ b/plugins/convention/src/test/java/actions/MessageAction.java @@ -21,9 +21,10 @@ package actions; import com.opensymphony.xwork2.ActionSupport; /** - * Example action, which is called by the convention plugin test case + * Example action, called by {@link org.apache.struts2.convention.ConventionJUnit4Test}. + * Result defined by message-success.ftl. */ -public class ViewAction extends ActionSupport { +public class MessageAction extends ActionSupport { private String message; public String getMessage() { diff --git a/plugins/junit/src/test/java/org/apache/struts2/junit/convention/StrutsJUnit4ConventionTestCaseTest.java b/plugins/convention/src/test/java/org/apache/struts2/convention/ConventionJUnit4Test.java similarity index 86% rename from plugins/junit/src/test/java/org/apache/struts2/junit/convention/StrutsJUnit4ConventionTestCaseTest.java rename to plugins/convention/src/test/java/org/apache/struts2/convention/ConventionJUnit4Test.java index 6a6351ef7..5c97c9312 100644 --- a/plugins/junit/src/test/java/org/apache/struts2/junit/convention/StrutsJUnit4ConventionTestCaseTest.java +++ b/plugins/convention/src/test/java/org/apache/struts2/convention/ConventionJUnit4Test.java @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.struts2.junit.convention; +package org.apache.struts2.convention; -import actions.ViewAction; +import actions.MessageAction; import org.apache.struts2.junit.StrutsJUnit4TestCase; import org.junit.Test; @@ -28,17 +28,17 @@ import static org.junit.Assert.assertTrue; /** * Uses the convention plugin to execute actions */ -public class StrutsJUnit4ConventionTestCaseTest extends StrutsJUnit4TestCase { +public class ConventionJUnit4Test extends StrutsJUnit4TestCase { @Test public void testConventionUrl() throws Exception { // Output is filled out only for FreeMarker and Velocity templates // If you wanna use JSP check response.getForwardedUrl() -String output = executeAction("/view.action"); +String output = executeAction("/message.action"); assertTrue(output.contains("This is the view Hello World")); -ViewAction action = this.getAction(); +MessageAction action = this.getAction(); assertEquals("Hello World", action.getMessage()); } @@ -48,6 +48,5 @@ public class StrutsJUnit4ConventionTestCaseTest extends StrutsJUnit4TestCasehttps://struts.apache.org/dtds/struts-6.0.dtd";> - - - - - - - - + diff --git a/plugins/junit/pom.xml b/plugins/junit/pom.xml index 8b4c99436..0fae24db4 100644 --- a/plugins/junit/pom.xml +++ b/plugins/junit/pom.xml @@ -53,20 +53,6 @@ junit junit - - - -org.apache.struts -struts2-convention-plugin -test - - - -org.apache.commons -commons-compress -1.23.0 -test - diff --g
[struts] branch dependabot/maven/opensymphony-sitemesh-2.5.0 created (now f5e804617)
This is an automated email from the ASF dual-hosted git repository. github-bot pushed a change to branch dependabot/maven/opensymphony-sitemesh-2.5.0 in repository https://gitbox.apache.org/repos/asf/struts.git at f5e804617 Bump opensymphony:sitemesh from 2.4.2 to 2.5.0 No new revisions were added by this update.
[struts] branch dependabot/maven/opensymphony-sitemesh-2.4.4 deleted (was 73504a25f)
This is an automated email from the ASF dual-hosted git repository. github-bot pushed a change to branch dependabot/maven/opensymphony-sitemesh-2.4.4 in repository https://gitbox.apache.org/repos/asf/struts.git was 73504a25f Bump opensymphony:sitemesh from 2.4.2 to 2.4.4 The revisions that were on this branch are still contained in other references; therefore, this change does not discard any commits from the repository.