[3/3] struts git commit: WW-4737 Fixes issue with array of nulls
WW-4737 Fixes issue with array of nulls Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/4b96958b Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/4b96958b Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/4b96958b Branch: refs/heads/master Commit: 4b96958be90b45e959ef600b89af33833d51eb27 Parents: 533b236 26bc9cd Author: Lukasz Lenart Authored: Mon Feb 13 10:48:52 2017 +0100 Committer: Lukasz Lenart Committed: Mon Feb 13 10:48:52 2017 +0100 -- .../apache/struts2/dispatcher/Parameter.java| 16 +- .../struts2/dispatcher/ParameterTest.java | 32 2 files changed, 41 insertions(+), 7 deletions(-) --
[1/3] struts git commit: [WW-4737] preserve nulls instead of converting them to the string 'null'
Repository: struts Updated Branches: refs/heads/master 533b236fd -> 4b96958be [WW-4737] preserve nulls instead of converting them to the string 'null' - Also simplify if-else logic to be more readable and avoid double-negatives Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/58667e64 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/58667e64 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/58667e64 Branch: refs/heads/master Commit: 58667e64970c528461cf7c5835f9a253c969f737 Parents: 47a415a Author: antuarc Authored: Wed Feb 1 12:26:31 2017 +1000 Committer: antuarc Committed: Wed Feb 1 12:26:31 2017 +1000 -- .../org/apache/struts2/dispatcher/Parameter.java| 16 +--- 1 file changed, 9 insertions(+), 7 deletions(-) -- http://git-wip-us.apache.org/repos/asf/struts/blob/58667e64/core/src/main/java/org/apache/struts2/dispatcher/Parameter.java -- diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Parameter.java b/core/src/main/java/org/apache/struts2/dispatcher/Parameter.java index 30781a1..4e06ef6 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/Parameter.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/Parameter.java @@ -1,5 +1,7 @@ package org.apache.struts2.dispatcher; +import java.util.Objects; + import org.apache.commons.lang3.StringEscapeUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -42,23 +44,23 @@ public interface Parameter { } private String[] toStringArray() { -if (value != null && value.getClass().isArray()) { +if (value == null) { +LOG.trace("The value is null, empty array of string will be returned!"); +return new String[]{}; +} else if (value.getClass().isArray()) { LOG.trace("Converting value {} to array of strings", value); Object[] values = (Object[]) value; String[] strValues = new String[values.length]; int i = 0; for (Object v : values) { -strValues[i] = String.valueOf(v); +strValues[i] = Objects.toString(v, null); i++; } return strValues; -} else if (value != null) { -LOG.trace("Converting value {} to simple string", value); -return new String[]{ String.valueOf(value) }; } else { -LOG.trace("The value is null, empty array of string will be returned!"); -return new String[]{}; +LOG.trace("Converting value {} to simple string", value); +return new String[]{ value.toString() }; } }
[2/3] struts git commit: [WW-4737] add unit testing for parameters being converted to string arrays
[WW-4737] add unit testing for parameters being converted to string arrays Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/26bc9cd6 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/26bc9cd6 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/26bc9cd6 Branch: refs/heads/master Commit: 26bc9cd64bd9e69f7bf2e1076150806581c355f4 Parents: 58667e6 Author: antuarc Authored: Wed Feb 1 12:27:02 2017 +1000 Committer: antuarc Committed: Wed Feb 1 12:27:02 2017 +1000 -- .../struts2/dispatcher/ParameterTest.java | 32 1 file changed, 32 insertions(+) -- http://git-wip-us.apache.org/repos/asf/struts/blob/26bc9cd6/core/src/test/java/org/apache/struts2/dispatcher/ParameterTest.java -- diff --git a/core/src/test/java/org/apache/struts2/dispatcher/ParameterTest.java b/core/src/test/java/org/apache/struts2/dispatcher/ParameterTest.java new file mode 100644 index 000..25d9409 --- /dev/null +++ b/core/src/test/java/org/apache/struts2/dispatcher/ParameterTest.java @@ -0,0 +1,32 @@ +package org.apache.struts2.dispatcher; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import static org.testng.Assert.*; + +public class ParameterTest { + +private static final String PARAM_NAME = "param"; + +@DataProvider(name = "paramValues") +Object[][] paramValues() { +return new Object[][] { +{null, new String[0]}, +{"input", new String[] {"input"}}, +{Integer.valueOf(5), new String[] {"5"}}, +{new String[] {"foo"}, new String[] {"foo"}}, +{new Object[] {null}, new String[] {null}}, +}; +} + +@Test(dataProvider = "paramValues") +public void shouldConvertRequestValuesToStringArrays(Object input, String[] expected) { +Parameter.Request request = new Parameter.Request(PARAM_NAME, input); + +String[] result = request.getMultipleValues(); + +assertEquals(result, expected); +assertNotSame(result, input); +} +}
[2/3] struts git commit: [WW-4472] using improved AnnotationUtils to navigate around proxies
[WW-4472] using improved AnnotationUtils to navigate around proxies Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/301844bb Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/301844bb Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/301844bb Branch: refs/heads/master Commit: 301844bbaadf52b6c07914ca7a4b327af7856538 Parents: c84b796 Author: Yasser Zamani Authored: Wed Feb 8 00:07:13 2017 +0330 Committer: Yasser Zamani Committed: Wed Feb 8 00:07:13 2017 +0330 -- .../xwork2/interceptor/DefaultWorkflowInterceptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/struts/blob/301844bb/core/src/main/java/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.java -- diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.java index 271fa6d..a9f2565 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.java @@ -207,7 +207,7 @@ public class DefaultWorkflowInterceptor extends MethodFilterInterceptor { */ protected String processInputConfig(final Object action, final String method, final String currentResultName) throws Exception { String resultName = currentResultName; -InputConfig annotation = action.getClass().getMethod(method, EMPTY_CLASS_ARRAY).getAnnotation(InputConfig.class); +InputConfig annotation = AnnotationUtils.findAnnotation(action.getClass().getMethod(method, EMPTY_CLASS_ARRAY), InputConfig.class); if (annotation != null) { if (StringUtils.isNotEmpty(annotation.methodName())) { Method m = action.getClass().getMethod(annotation.methodName());
[1/3] struts git commit: [WW-4694] annotation processing improved in order to navigate around proxies, superclasses and interfaces
Repository: struts Updated Branches: refs/heads/master 4b96958be -> 534dfc6bd [WW-4694] annotation processing improved in order to navigate around proxies, superclasses and interfaces Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/c84b7967 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/c84b7967 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/c84b7967 Branch: refs/heads/master Commit: c84b7967e9eb2f6307466b1644977423831d2ef1 Parents: 0023d96 Author: Yasser Zamani Authored: Sun Feb 5 17:54:28 2017 +0330 Committer: Yasser Zamani Committed: Sun Feb 5 17:54:28 2017 +0330 -- .../xwork2/util/AnnotationUtils.java| 111 --- .../xwork2/util/AnnotationUtilsTest.java| 35 -- .../xwork2/util/annotation/DummyClass.java | 5 +- .../xwork2/util/annotation/DummyClassExt.java | 5 +- .../xwork2/util/annotation/DummyInterface.java | 7 ++ .../xwork2/util/annotation/MyAnnotationI.java | 8 ++ 6 files changed, 145 insertions(+), 26 deletions(-) -- http://git-wip-us.apache.org/repos/asf/struts/blob/c84b7967/core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java -- diff --git a/core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java b/core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java index ef0ee53..1c37918 100644 --- a/core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java +++ b/core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java @@ -122,7 +122,14 @@ public class AnnotationUtils { Collection toReturn = new HashSet<>(); for (Method m : clazz.getMethods()) { -if (ArrayUtils.isNotEmpty(annotation) && isAnnotatedBy(m, annotation)) { + boolean found = false; + for( Class c : annotation ){ + if( null != findAnnotation(m, c) ){ + found = true; + break; + } + } +if (found) { toReturn.add(m); } else if (ArrayUtils.isEmpty(annotation) && ArrayUtils.isNotEmpty(m.getAnnotations())) { toReturn.add(m); @@ -133,22 +140,100 @@ public class AnnotationUtils { } /** -* Varargs version of AnnotatedElement.isAnnotationPresent() - * @param annotatedElement element to check - * @param annotation the {@link Annotation}s to find - * @return true is element is annotated by one of the annotation -* @see AnnotatedElement +* Find a single {@link Annotation} of {@code annotationType} from the supplied +* {@link Method}, traversing its super methods (i.e., from superclasses and +* interfaces) if no annotation can be found on the given method itself. +* Annotations on methods are not inherited by default, so we need to handle +* this explicitly. +* @param method the method to look for annotations on +* @param annotationType the annotation type to look for +* @return the annotation found, or {@code null} if none */ - public static boolean isAnnotatedBy(AnnotatedElement annotatedElement, Class... annotation) { -if (ArrayUtils.isEmpty(annotation)) { -return false; -} + public static A findAnnotation(Method method, Class annotationType) { + A result = getAnnotation(method, annotationType); + Class clazz = method.getDeclaringClass(); + if (result == null) { + result = searchOnInterfaces(method, annotationType, clazz.getInterfaces()); + } + while (result == null) { + clazz = clazz.getSuperclass(); + if (clazz == null || clazz.equals(Object.class)) { + break; + } + try { + Method equivalentMethod = clazz.getDeclaredMethod(method.getName(), method.getParameterTypes()); + result = getAnnotation(equivalentMethod, annotationType); + } + catch (NoSuchMethodException ex) { + // No equivalent method found + } + if (result == null) { + result = searchOnInterfaces(method, annotationType, clazz.getInterfaces()); + } + } + return result; + } + + /** +* Get a single {@link Annotation} of {@code annotationType} from the supplied +* Method, Constructor
[3/3] struts git commit: WW-4694 WW-4472 Imroves annotation processing
WW-4694 WW-4472 Imroves annotation processing Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/534dfc6b Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/534dfc6b Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/534dfc6b Branch: refs/heads/master Commit: 534dfc6bd8840bc2aa64022570b2225977ece5f6 Parents: 4b96958 301844b Author: Lukasz Lenart Authored: Mon Feb 13 11:55:11 2017 +0100 Committer: Lukasz Lenart Committed: Mon Feb 13 11:55:11 2017 +0100 -- .../interceptor/DefaultWorkflowInterceptor.java | 2 +- .../xwork2/util/AnnotationUtils.java| 111 --- .../xwork2/util/AnnotationUtilsTest.java| 35 -- .../xwork2/util/annotation/DummyClass.java | 5 +- .../xwork2/util/annotation/DummyClassExt.java | 5 +- .../xwork2/util/annotation/DummyInterface.java | 7 ++ .../xwork2/util/annotation/MyAnnotationI.java | 8 ++ 7 files changed, 146 insertions(+), 27 deletions(-) --
[2/2] struts git commit: Drops code duplication
Drops code duplication Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/f22873e1 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/f22873e1 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/f22873e1 Branch: refs/heads/master Commit: f22873e127ca8c4de8b636415eb8097db77d79c6 Parents: 3dafd2a Author: Lukasz Lenart Authored: Mon Feb 13 12:00:59 2017 +0100 Committer: Lukasz Lenart Committed: Mon Feb 13 12:00:59 2017 +0100 -- ...nnotationValidationConfigurationBuilder.java | 32 ++-- 1 file changed, 2 insertions(+), 30 deletions(-) -- http://git-wip-us.apache.org/repos/asf/struts/blob/f22873e1/core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java -- diff --git a/core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java b/core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java index dc8d856..b587bf3 100644 --- a/core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java +++ b/core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java @@ -15,6 +15,7 @@ */ package com.opensymphony.xwork2.validator; +import com.opensymphony.xwork2.util.AnnotationUtils; import com.opensymphony.xwork2.validator.annotations.*; import org.apache.commons.lang3.StringUtils; @@ -24,8 +25,6 @@ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * AnnotationValidationConfigurationBuilder @@ -36,9 +35,6 @@ import java.util.regex.Pattern; */ public class AnnotationValidationConfigurationBuilder { -private static final Pattern SETTER_PATTERN = Pattern.compile("set([A-Z][A-Za-z0-9]*)$"); -private static final Pattern GETTER_PATTERN = Pattern.compile("(get|is|has)([A-Z][A-Za-z0-9]*)$"); - private ValidatorFactory validatorFactory; public AnnotationValidationConfigurationBuilder(ValidatorFactory fac) { @@ -61,7 +57,7 @@ public class AnnotationValidationConfigurationBuilder { if (o instanceof Method) { Method method = (Method) o; -fieldName = resolvePropertyName(method); +fieldName = AnnotationUtils.resolvePropertyName(method); methodName = method.getName(); annotations = method.getAnnotations(); @@ -874,28 +870,4 @@ public class AnnotationValidationConfigurationBuilder { } -/** - * Returns the property name for a method. - * This method is independant from property fields. - * - * @param method The method to get the property name for. - * @return the property name for given method; null if non could be resolved. - */ -public String resolvePropertyName(Method method) { - -Matcher matcher = SETTER_PATTERN.matcher(method.getName()); -if (matcher.matches() && method.getParameterTypes().length == 1) { -String raw = matcher.group(1); -return raw.substring(0, 1).toLowerCase() + raw.substring(1); -} - -matcher = GETTER_PATTERN.matcher(method.getName()); -if (matcher.matches() && method.getParameterTypes().length == 0) { -String raw = matcher.group(2); -return raw.substring(0, 1).toLowerCase() + raw.substring(1); -} - -return null; -} - }
[1/2] struts git commit: Reformats code
Repository: struts Updated Branches: refs/heads/master 534dfc6bd -> f22873e12 Reformats code Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/3dafd2a3 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/3dafd2a3 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/3dafd2a3 Branch: refs/heads/master Commit: 3dafd2a35665eb90e6d89256057dd8e1fabae1f4 Parents: 534dfc6 Author: Lukasz Lenart Authored: Mon Feb 13 11:58:57 2017 +0100 Committer: Lukasz Lenart Committed: Mon Feb 13 11:58:57 2017 +0100 -- .../xwork2/util/AnnotationUtils.java| 253 +-- 1 file changed, 125 insertions(+), 128 deletions(-) -- http://git-wip-us.apache.org/repos/asf/struts/blob/3dafd2a3/core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java -- diff --git a/core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java b/core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java index 1c37918..36166dd 100644 --- a/core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java +++ b/core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java @@ -48,8 +48,8 @@ public class AnnotationUtils { * Adds all fields with the specified Annotation of class clazz and its superclasses to allFields * * @param annotationClass the {@link Annotation}s to find - * @param clazz The {@link Class} to inspect - * @param allFields list of all fields + * @param clazz The {@link Class} to inspect + * @param allFields list of all fields */ public static void addAllFields(Class annotationClass, Class clazz, List allFields) { @@ -61,7 +61,7 @@ public class AnnotationUtils { for (Field field : fields) { Annotation ann = field.getAnnotation(annotationClass); -if (ann!=null) { +if (ann != null) { allFields.add(field); } } @@ -72,8 +72,8 @@ public class AnnotationUtils { * Adds all methods with the specified Annotation of class clazz and its superclasses to allFields * * @param annotationClass the {@link Annotation}s to find - * @param clazz The {@link Class} to inspect - * @param allMethods list of all methods + * @param clazz The {@link Class} to inspect + * @param allMethods list of all methods */ public static void addAllMethods(Class annotationClass, Class clazz, List allMethods) { @@ -85,7 +85,7 @@ public class AnnotationUtils { for (Method method : methods) { Annotation ann = method.getAnnotation(annotationClass); -if (ann!=null) { +if (ann != null) { allMethods.add(method); } } @@ -93,8 +93,7 @@ public class AnnotationUtils { } /** - * - * @param clazz The {@link Class} to inspect + * @param clazz The {@link Class} to inspect * @param allInterfaces list of all interfaces */ public static void addAllInterfaces(Class clazz, List allInterfaces) { @@ -107,134 +106,132 @@ public class AnnotationUtils { addAllInterfaces(clazz.getSuperclass(), allInterfaces); } - /** -* For the given Class get a collection of the the {@link AnnotatedElement}s -* that match the given annotations or if no annotations are -* specified then return all of the annotated elements of the given Class. -* Includes only the method level annotations. -* -* @param clazz The {@link Class} to inspect -* @param annotation the {@link Annotation}s to find -* @return A {@link Collection}<{@link AnnotatedElement}> containing all of the -* method {@link AnnotatedElement}s matching the specified {@link Annotation}s -*/ - public static Collection getAnnotatedMethods(Class clazz, Class... annotation){ +/** + * For the given Class get a collection of the the {@link AnnotatedElement}s + * that match the given annotations or if no annotations are + * specified then return all of the annotated elements of the given Class. + * Includes only the method level annotations. + * + * @param clazz The {@link Class} to inspect + * @param annotation the {@link Annotation}s to find + * @return A {@link Collection}<{@link AnnotatedElement}> containing all of the + * method {@link AnnotatedElement}s matching the specified {@link Annotation}s + */ +public static Collection getAnnotatedMethods(Class clazz, Class... annotation) { Collection toReturn = new HashSet<>(); for (Method m : clazz.getMethods()) { - boolea
struts git commit: WW-4743 NPE in StrutsTilesContainerFactory when resource isn't found
Repository: struts Updated Branches: refs/heads/master f22873e12 -> a399932ae WW-4743 NPE in StrutsTilesContainerFactory when resource isn't found Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/a399932a Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/a399932a Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/a399932a Branch: refs/heads/master Commit: a399932ae9903167d1ee647b141cc98fdf83ef6f Parents: f22873e Author: Aleksandr Mashchenko Authored: Mon Feb 13 20:15:18 2017 +0200 Committer: Aleksandr Mashchenko Committed: Mon Feb 13 20:15:18 2017 +0200 -- .../org/apache/struts2/tiles/StrutsTilesContainerFactory.java | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/struts/blob/a399932a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java -- diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java index f1c8bbb..b7564a9 100644 --- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java +++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java @@ -190,9 +190,13 @@ public class StrutsTilesContainerFactory extends BasicTilesContainerFactory { resources.addAll(applicationContext.getResources(definition)); } +if (resources.contains(null)) { +LOG.warn("Some resources were not found. Definitions: {}. Found resources: {}", definitions, resources); +} + List filteredResources = new ArrayList<>(); for (ApplicationResource resource : resources) { -if (Locale.ROOT.equals(resource.getLocale())) { +if (resource != null && Locale.ROOT.equals(resource.getLocale())) { filteredResources.add(resource); } }
[2/5] struts git commit: [WW-4528] correcting testTwoExcludesPropertiesChained unit test
[WW-4528] correcting testTwoExcludesPropertiesChained unit test Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/7140e019 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/7140e019 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/7140e019 Branch: refs/heads/master Commit: 7140e0192b537f1ff388fbf00758b591a9cdeb6f Parents: 0437efc Author: Yasser Zamani Authored: Fri Feb 3 02:37:17 2017 +0330 Committer: Yasser Zamani Committed: Fri Feb 3 02:37:17 2017 +0330 -- .../xwork2/interceptor/ChainingInterceptorTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- http://git-wip-us.apache.org/repos/asf/struts/blob/7140e019/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java -- diff --git a/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java b/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java index 8c18ee5..6fdcf78 100644 --- a/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java @@ -130,8 +130,9 @@ public class ChainingInterceptorTest extends XWorkTestCase { assertEquals(bean.getBirth(), action.getBirth()); assertEquals(null, action.getName()); assertEquals(0, action.getCount()); -assertEquals(interceptor.getExcludes().iterator().next(), "count"); -assertEquals(interceptor.getExcludes().iterator().next(), "name"); +Iterator it = interceptor.getExcludes().iterator(); +assertEquals(it.next(), "count"); +assertEquals(it.next(), "name"); } public void testNullCompoundRootElementAllowsProcessToContinue() throws Exception {
[1/5] struts git commit: [WW-4528] handling ChainingInterceptor excludes and includes lists as comma separated String like ParameterFilterInterceptor do
Repository: struts Updated Branches: refs/heads/master a399932ae -> 9fcf2dfca [WW-4528] handling ChainingInterceptor excludes and includes lists as comma separated String like ParameterFilterInterceptor do Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/0437efc6 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/0437efc6 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/0437efc6 Branch: refs/heads/master Commit: 0437efc6f91c2b78d84f673a63d45ef2765782db Parents: 0023d96 Author: Yasser Zamani Authored: Fri Feb 3 02:01:50 2017 +0330 Committer: Yasser Zamani Committed: Fri Feb 3 02:01:50 2017 +0330 -- .../xwork2/interceptor/ChainingInterceptor.java | 24 ++-- .../interceptor/ChainingInterceptorTest.java| 12 -- .../opensymphony/xwork2/ognl/OgnlUtilTest.java | 4 ++-- 3 files changed, 29 insertions(+), 11 deletions(-) -- http://git-wip-us.apache.org/repos/asf/struts/blob/0437efc6/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java -- diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java index 93bae6d..27a0f68 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java @@ -21,6 +21,7 @@ import com.opensymphony.xwork2.Result; import com.opensymphony.xwork2.Unchainable; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.CompoundRoot; +import com.opensymphony.xwork2.util.TextParseUtil; import com.opensymphony.xwork2.util.ValueStack; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; @@ -213,9 +214,18 @@ public class ChainingInterceptor extends AbstractInterceptor { /** * Sets the list of parameter names to exclude from copying (all others will be included). * + * @param excludes the excludes list as comma separated String + */ +public void setExcludes(String excludes) { +this.excludes = TextParseUtil.commaDelimitedStringToSet(excludes); +} + +/** + * Sets the list of parameter names to exclude from copying (all others will be included). + * * @param excludes the excludes list */ -public void setExcludes(Collection excludes) { +public void setExcludesCollection(Collection excludes) { this.excludes = excludes; } @@ -231,9 +241,19 @@ public class ChainingInterceptor extends AbstractInterceptor { /** * Sets the list of parameter names to include when copying (all others will be excluded). * + * @param includes the includes list as comma separated String + */ +public void setIncludes(String includes) { +this.includes = TextParseUtil.commaDelimitedStringToSet(includes); +} + + +/** + * Sets the list of parameter names to include when copying (all others will be excluded). + * * @param includes the includes list */ -public void setIncludes(Collection includes) { +public void setIncludesCollection(Collection includes) { this.includes = includes; } http://git-wip-us.apache.org/repos/asf/struts/blob/0437efc6/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java -- diff --git a/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java b/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java index 1b84209..8c18ee5 100644 --- a/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java @@ -103,8 +103,7 @@ public class ChainingInterceptorTest extends XWorkTestCase { interceptor.setCopyErrors("true"); interceptor.setCopyMessages("true"); -Collection excludes = new ArrayList<>(); -excludes.add("count"); +String excludes = "count"; interceptor.setExcludes(excludes); interceptor.intercept(invocation); @@ -112,7 +111,7 @@ public class ChainingInterceptorTest extends XWorkTestCase { assertEquals(bean.getBirth(), action.getBirth()); assertEquals(bean.getName(), action.getName()); assertEquals(0, action.getCount()); -assertEquals(excludes, interceptor.getExcludes()); +assertEquals(interceptor.getExcludes().iterator().next(), "count"); } public void testTwoExcludesPropertiesChained() throws Exception { @@ -125
[4/5] struts git commit: Add an Unit test to check if same issue as [WW-4528] has occurred
Add an Unit test to check if same issue as [WW-4528] has occurred Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/805cdd77 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/805cdd77 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/805cdd77 Branch: refs/heads/master Commit: 805cdd7754400149e166edc80b92fa2d67133d39 Parents: 51c0bcb Author: Yasser Zamani Authored: Tue Feb 14 01:35:46 2017 +0330 Committer: Yasser Zamani Committed: Tue Feb 14 01:35:46 2017 +0330 -- .../ChainingInterceptorWithConfigTest.java | 116 +++ 1 file changed, 116 insertions(+) -- http://git-wip-us.apache.org/repos/asf/struts/blob/805cdd77/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorWithConfigTest.java -- diff --git a/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorWithConfigTest.java b/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorWithConfigTest.java new file mode 100644 index 000..25a5ee1 --- /dev/null +++ b/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorWithConfigTest.java @@ -0,0 +1,116 @@ +/* + * Copyright 2002-2006,2009 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 com.opensymphony.xwork2.interceptor; + +import com.opensymphony.xwork2.*; +import com.opensymphony.xwork2.config.Configuration; +import com.opensymphony.xwork2.config.ConfigurationException; +import com.opensymphony.xwork2.config.ConfigurationProvider; +import com.opensymphony.xwork2.config.entities.ActionConfig; +import com.opensymphony.xwork2.config.entities.InterceptorConfig; +import com.opensymphony.xwork2.config.entities.InterceptorMapping; +import com.opensymphony.xwork2.config.entities.PackageConfig; +import com.opensymphony.xwork2.config.entities.ResultConfig; +import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider; +import com.opensymphony.xwork2.inject.ContainerBuilder; +import com.opensymphony.xwork2.util.location.LocatableProperties; + +import java.util.*; + +import org.apache.struts2.TestResult; + + +/** + * Unit test for {@link ChainingInterceptor} with a configuration provider. + * + */ +public class ChainingInterceptorWithConfigTest extends XWorkTestCase { + +static String CHAINED_ACTION = "chainedAction"; +static String CHAINTO_ACTION = "chaintoAction"; +ObjectFactory objectFactory; + +public void testTwoExcludesPropertiesChained() throws Exception { +assertNotNull(objectFactory); +ActionProxy proxy = actionProxyFactory.createActionProxy("", CHAINED_ACTION, null, null); +SimpleAction chainedAction = (SimpleAction) proxy.getAction(); +chainedAction.setBar(1); +chainedAction.setFoo(1); +chainedAction.setBlah("WW-4528"); +proxy.execute(); +} + +@Override +protected void setUp() throws Exception { +super.setUp(); +XmlConfigurationProvider provider = new XmlConfigurationProvider("xwork-default.xml"); +container.inject(provider); +this.objectFactory = container.getInstance(ObjectFactory.class); +loadConfigurationProviders(provider, new MockConfigurationProvider()); +} + + +private class MockConfigurationProvider implements ConfigurationProvider { +private Configuration config; + +public void init(Configuration configuration) throws ConfigurationException { +this.config = configuration; +} + +public boolean needsReload() { +return false; +} + +public void destroy() { } + + +public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException { +if (!builder.contains(ObjectFactory.class)) { +builder.factory(ObjectFactory.class); +} +if (!builder.contains(ActionProxyFactory.class)) { +builder.factory(ActionProxyFactory.class, DefaultActionProxyFactory.class); +} +} + +public void loadPackages() throws ConfigurationException { +HashMap interceptorParams = new HashMap<>(); +intercepto
[5/5] struts git commit: WW-4528 Supports includes/excludes as lists
WW-4528 Supports includes/excludes as lists Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/9fcf2dfc Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/9fcf2dfc Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/9fcf2dfc Branch: refs/heads/master Commit: 9fcf2dfca7fb7a4d95a83665030411fc0c65c85b Parents: a399932 805cdd7 Author: Lukasz Lenart Authored: Tue Feb 14 08:06:49 2017 +0100 Committer: Lukasz Lenart Committed: Tue Feb 14 08:06:49 2017 +0100 -- .../xwork2/interceptor/ChainingInterceptor.java | 24 +++- .../interceptor/ChainingInterceptorTest.java| 13 +-- .../ChainingInterceptorWithConfigTest.java | 116 +++ .../opensymphony/xwork2/ognl/OgnlUtilTest.java | 4 +- 4 files changed, 146 insertions(+), 11 deletions(-) --
[3/5] struts git commit: [WW-4528] improving testTwoExcludesPropertiesChained unit test
[WW-4528] improving testTwoExcludesPropertiesChained unit test Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/51c0bcbb Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/51c0bcbb Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/51c0bcbb Branch: refs/heads/master Commit: 51c0bcbb8bf4103a5c97be0f6372725f792f470e Parents: 7140e01 Author: Yasser Zamani Authored: Fri Feb 3 11:25:02 2017 +0330 Committer: Yasser Zamani Committed: Fri Feb 3 11:25:02 2017 +0330 -- .../xwork2/interceptor/ChainingInterceptorTest.java| 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- http://git-wip-us.apache.org/repos/asf/struts/blob/51c0bcbb/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java -- diff --git a/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java b/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java index 6fdcf78..1251612 100644 --- a/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java @@ -130,9 +130,9 @@ public class ChainingInterceptorTest extends XWorkTestCase { assertEquals(bean.getBirth(), action.getBirth()); assertEquals(null, action.getName()); assertEquals(0, action.getCount()); -Iterator it = interceptor.getExcludes().iterator(); -assertEquals(it.next(), "count"); -assertEquals(it.next(), "name"); +assertTrue(interceptor.getExcludes().contains("count")); +assertTrue(interceptor.getExcludes().contains("name")); +assertTrue(interceptor.getExcludes().size() == 2); } public void testNullCompoundRootElementAllowsProcessToContinue() throws Exception {