struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject svn commit: r1469181 - in /struts/struts2/trunk: plugins/convention/src/test/java/org/apache/struts2/convention/ xwork-core/src/main/java/com/opensymphony/xwork2/ xwork-core/src/main/java/com/opensymphony/xwork2/ognl/ xwork-core/src/main/java/com/opens...
Date Thu, 18 Apr 2013 06:19:53 GMT
Author: lukaszlenart
Date: Thu Apr 18 06:19:52 2013
New Revision: 1469181

URL: http://svn.apache.org/r1469181
Log:
WW-4046 Solves failing test and uses ActionContext to create validators

Modified:
    struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionProvider.java
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/reflection/ReflectionProvider.java
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/DefaultValidatorFactory.java
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/DefaultValidatorFileParser.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/spring/SpringObjectFactoryTest.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilderTest.java

Modified: struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java?rev=1469181&r1=1469180&r2=1469181&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
(original)
+++ struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
Thu Apr 18 06:19:52 2013
@@ -760,9 +760,9 @@ public class PackageBasedActionConfigBui
                         public void setProperties(Map<String, ?> properties, Object
o) {
                         }
 
-                        public void setProperties(Map<String, String> properties, Object
o, Map<String, Object> context, boolean throwPropertyExceptions) throws ReflectionException
{
+                        public void setProperties(Map<String, ?> properties, Object
o, Map<String, Object> context, boolean throwPropertyExceptions) throws ReflectionException
{
                             if (o instanceof ActionChainResult) {
-                                ((ActionChainResult)o).setActionName(properties.get("actionName"));
+                                ((ActionChainResult)o).setActionName(String.valueOf(properties.get("actionName")));
                             }
                         }
 

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java?rev=1469181&r1=1469180&r2=1469181&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java
Thu Apr 18 06:19:52 2013
@@ -251,8 +251,8 @@ public class ObjectFactory implements Se
      * @param extraContext a Map of extra context which uses the same keys as the {@link
com.opensymphony.xwork2.ActionContext}
      */
     public Validator buildValidator(String className, Map<String, Object> params, Map<String,
Object> extraContext) throws Exception {
-        Validator validator = (Validator) buildBean(className, null);
-        reflectionProvider.setProperties(params, validator);
+        Validator validator = (Validator) buildBean(className, extraContext);
+        reflectionProvider.setProperties(params, validator, extraContext);
 
         return validator;
     }

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionProvider.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionProvider.java?rev=1469181&r1=1469180&r2=1469181&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionProvider.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionProvider.java
Thu Apr 18 06:19:52 2013
@@ -45,12 +45,11 @@ public class OgnlReflectionProvider impl
         }
     }
 
-    public void setProperties(Map<String, String> props, Object o, Map<String, Object>
context) {
+    public void setProperties(Map<String, ?> props, Object o, Map<String, Object>
context) {
         ognlUtil.setProperties(props, o, context);
     }
 
-    public void setProperties(Map<String, String> props, Object o, Map<String, Object>
context,
-            boolean throwPropertyExceptions) throws ReflectionException{
+    public void setProperties(Map<String, ?> props, Object o, Map<String, Object>
context, boolean throwPropertyExceptions) throws ReflectionException{
         ognlUtil.setProperties(props, o, context, throwPropertyExceptions);
         
     }

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/reflection/ReflectionProvider.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/reflection/ReflectionProvider.java?rev=1469181&r1=1469180&r2=1469181&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/reflection/ReflectionProvider.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/reflection/ReflectionProvider.java
Thu Apr 18 06:19:52 2013
@@ -23,7 +23,7 @@ public interface ReflectionProvider {
      * @param o       the object
      * @param context the action context
      */
-    void setProperties(Map<String, String> props, Object o, Map<String, Object>
context);
+    void setProperties(Map<String, ?> props, Object o, Map<String, Object> context);
 
     /**
      * Sets the object's properties using the default type converter.
@@ -34,7 +34,7 @@ public interface ReflectionProvider {
      * @param throwPropertyExceptions boolean which tells whether it should throw exceptions
for
      *                                problems setting the properties
      */
-    void setProperties(Map<String, String> props, Object o, Map<String, Object>
context, boolean throwPropertyExceptions) throws ReflectionException;
+    void setProperties(Map<String, ?> props, Object o, Map<String, Object> context,
boolean throwPropertyExceptions) throws ReflectionException;
     
     /**
      * Sets the properties on the object using the default context, defaulting to not throwing

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/DefaultValidatorFactory.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/DefaultValidatorFactory.java?rev=1469181&r1=1469180&r2=1469181&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/DefaultValidatorFactory.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/DefaultValidatorFactory.java
Thu Apr 18 06:19:52 2013
@@ -15,6 +15,7 @@
  */
 package com.opensymphony.xwork2.validator;
 
+import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ObjectFactory;
 import com.opensymphony.xwork2.XWorkException;
 import com.opensymphony.xwork2.config.ConfigurationException;
@@ -29,9 +30,14 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
 import java.net.URL;
-import java.util.*;
-import java.util.zip.ZipInputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
 
 
 /**
@@ -64,7 +70,7 @@ public class DefaultValidatorFactory imp
         try {
             // instantiate the validator, and set configured parameters
             //todo - can this use the ThreadLocal?
-            validator = objectFactory.buildValidator(className, cfg.getParams(), null); //
ActionContext.getContext().getContextMap());
+            validator = objectFactory.buildValidator(className, cfg.getParams(), ActionContext.getContext().getContextMap());
         } catch (Exception e) {
             final String msg = "There was a problem creating a Validator of type " + className
+ " : caused by " + e.getMessage();
             throw new XWorkException(msg, e, cfg);

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/DefaultValidatorFileParser.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/DefaultValidatorFileParser.java?rev=1469181&r1=1469180&r2=1469181&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/DefaultValidatorFileParser.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/DefaultValidatorFileParser.java
Thu Apr 18 06:19:52 2013
@@ -15,6 +15,7 @@
  */
 package com.opensymphony.xwork2.validator;
 
+import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ObjectFactory;
 import com.opensymphony.xwork2.config.ConfigurationException;
 import com.opensymphony.xwork2.config.providers.XmlHelper;
@@ -127,7 +128,7 @@ public class DefaultValidatorFileParser 
 
                 try {
                     // catch any problems here
-                    objectFactory.buildValidator(className, new HashMap<String, Object>(),
null);
+                    objectFactory.buildValidator(className, new HashMap<String, Object>(),
ActionContext.getContext().getContextMap());
                     validators.put(name, className);
                 } catch (Exception e) {
                     throw new ConfigurationException("Unable to load validator class " +
className, e, validatorElement);

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/spring/SpringObjectFactoryTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/spring/SpringObjectFactoryTest.java?rev=1469181&r1=1469180&r2=1469181&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/spring/SpringObjectFactoryTest.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/spring/SpringObjectFactoryTest.java
Thu Apr 18 06:19:52 2013
@@ -52,6 +52,7 @@ import org.springframework.context.Appli
 import org.springframework.context.support.StaticApplicationContext;
 
 import java.util.HashMap;
+import java.util.Map;
 
 // TODO: Document properly
 
@@ -114,7 +115,8 @@ public class SpringObjectFactoryTest ext
     }
 
     public void testFallsBackToDefaultObjectFactoryValidatorBuilding() throws Exception {
-        Validator validator = objectFactory.buildValidator(RequiredStringValidator.class.getName(),
new HashMap<String, Object>(), null);
+        Map<String,Object> extraContext = new HashMap<String, Object>();
+        Validator validator = objectFactory.buildValidator(RequiredStringValidator.class.getName(),
new HashMap<String, Object>(), extraContext);
 
         assertEquals(RequiredStringValidator.class, validator.getClass());
     }
@@ -150,7 +152,8 @@ public class SpringObjectFactoryTest ext
     public void testObtainValidatorBySpringName() throws Exception {
         sac.registerPrototype("expression-validator", ExpressionValidator.class, new MutablePropertyValues());
 
-        Validator validator = objectFactory.buildValidator("expression-validator", new HashMap<String,
Object>(), null);
+        Map<String, Object> extraContext = new HashMap<String, Object>();
+        Validator validator = objectFactory.buildValidator("expression-validator", new HashMap<String,
Object>(), extraContext);
 
         assertEquals(ExpressionValidator.class, validator.getClass());
     }

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilderTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilderTest.java?rev=1469181&r1=1469180&r2=1469181&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilderTest.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilderTest.java
Thu Apr 18 06:19:52 2013
@@ -1,5 +1,6 @@
 package com.opensymphony.xwork2.validator;
 
+import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionInvocation;
 import com.opensymphony.xwork2.ActionSupport;
 import com.opensymphony.xwork2.DefaultActionInvocation;
@@ -33,9 +34,8 @@ import com.opensymphony.xwork2.validator
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
+import java.util.Locale;
 
 /**
  * Simple test to check if validation Annotations match given validator class
@@ -44,7 +44,7 @@ public class AnnotationValidationConfigu
 
     public void testValidationAnnotation() throws Exception {
         // given
-        AnnotationActionValidatorManager manager = createValidationManager(AnnotationValidationAction.class);
+        AnnotationActionValidatorManager manager = createValidationManager(AnnotationValidationAction.class,
Locale.US);
 
         // when
         List<Validator> validators = manager.getValidators(AnnotationValidationAction.class,
null);
@@ -58,7 +58,7 @@ public class AnnotationValidationConfigu
 
     public void testValidationAnnotationExpParams() throws Exception {
         // given
-        AnnotationActionValidatorManager manager = createValidationManager(AnnotationValidationExpAction.class);
+        AnnotationActionValidatorManager manager = createValidationManager(AnnotationValidationExpAction.class,
Locale.US);
 
         // when
         List<Validator> validators = manager.getValidators(AnnotationValidationExpAction.class,
null);
@@ -265,7 +265,7 @@ public class AnnotationValidationConfigu
         assertTrue(Arrays.equals(new String[]{"one", "two", "three"}, validator.getMessageParameters()));
     }
 
-    private AnnotationActionValidatorManager createValidationManager(final Class<? extends
ActionSupport> actionClass) throws Exception {
+    private AnnotationActionValidatorManager createValidationManager(final Class<? extends
ActionSupport> actionClass, Locale locale) throws Exception {
         loadConfigurationProviders(new ConfigurationProvider() {
             public void destroy() {
 
@@ -290,10 +290,12 @@ public class AnnotationValidationConfigu
             }
         });
 
-        Map<String, Object> context = new HashMap<String, Object>();
-        ActionInvocation invocation = new DefaultActionInvocation(context, true);
+        // ActionContext is destroyed during rebuilding configuration
+        ActionContext.getContext().setLocale(locale);
+
+        ActionInvocation invocation = new DefaultActionInvocation(ActionContext.getContext().getContextMap(),
true);
         container.inject(invocation);
-        invocation.init(actionProxyFactory.createActionProxy("", "annotation", null, context));
+        invocation.init(actionProxyFactory.createActionProxy("", "annotation", null, ActionContext.getContext().getContextMap()));
 
         AnnotationActionValidatorManager manager = new AnnotationActionValidatorManager();
         container.inject(manager);



Mime
View raw message