struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject svn commit: r1428072 - in /struts/struts2/trunk/xwork-core/src: main/java/com/opensymphony/xwork2/validator/ main/java/com/opensymphony/xwork2/validator/validators/ test/java/com/opensymphony/xwork2/config/providers/ test/java/com/opensymphony/xwork2/v...
Date Wed, 02 Jan 2013 21:41:26 GMT
Author: lukaszlenart
Date: Wed Jan  2 21:41:26 2013
New Revision: 1428072

URL: http://svn.apache.org/viewvc?rev=1428072&view=rev
Log:
WW-3890 improves support for generics and moves test values into the tests

Modified:
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/ValidationException.java
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/ValidatorSupport.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/providers/MockConfigurationProvider.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/DoubleRangeValidatorTest.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/ValidationAction.java

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/ValidationException.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/ValidationException.java?rev=1428072&r1=1428071&r2=1428072&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/ValidationException.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/ValidationException.java
Wed Jan  2 21:41:26 2013
@@ -37,4 +37,8 @@ public class ValidationException extends
     public ValidationException(String s) {
         super(s);
     }
+
+    public ValidationException(String message, Throwable cause) {
+        super(message, cause);
+    }
 }

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/ValidatorSupport.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/ValidatorSupport.java?rev=1428072&r1=1428071&r2=1428072&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/ValidatorSupport.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/ValidatorSupport.java
Wed Jan  2 21:41:26 2013
@@ -44,10 +44,10 @@ public abstract class ValidatorSupport i
     protected String messageKey;
     private ValidatorContext validatorContext;
     private boolean shortCircuit;
-    private boolean parse;
+    protected boolean parse;
     private String type;
     private String[] messageParameters;
-    private ValueStack stack;
+    protected ValueStack stack;
 
 
     public void setValueStack(ValueStack stack) {

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/providers/MockConfigurationProvider.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/providers/MockConfigurationProvider.java?rev=1428072&r1=1428071&r2=1428072&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/providers/MockConfigurationProvider.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/providers/MockConfigurationProvider.java
Wed Jan  2 21:41:26 2013
@@ -15,11 +15,19 @@
  */
 package com.opensymphony.xwork2.config.providers;
 
-import com.opensymphony.xwork2.*;
+import com.opensymphony.xwork2.Action;
+import com.opensymphony.xwork2.ActionChainResult;
+import com.opensymphony.xwork2.ModelDrivenAction;
+import com.opensymphony.xwork2.ObjectFactory;
+import com.opensymphony.xwork2.SimpleAction;
 import com.opensymphony.xwork2.config.Configuration;
 import com.opensymphony.xwork2.config.ConfigurationException;
 import com.opensymphony.xwork2.config.ConfigurationProvider;
-import com.opensymphony.xwork2.config.entities.*;
+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.inject.ContainerBuilder;
 import com.opensymphony.xwork2.inject.Inject;
 import com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor;
@@ -30,6 +38,7 @@ import com.opensymphony.xwork2.util.loca
 import com.opensymphony.xwork2.validator.ValidationInterceptor;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -50,6 +59,9 @@ public class MockConfigurationProvider i
     public static final String VALIDATION_ACTION_NAME = "validationInterceptorTest";
     public static final String VALIDATION_ALIAS_NAME = "validationAlias";
     public static final String VALIDATION_SUBPROPERTY_NAME = "subproperty";
+
+    private static final Map<String,String> EMPTY_STRING_MAP = Collections.emptyMap();
+
     private Configuration configuration;
     private Map<String,String> params;
     private ObjectFactory objectFactory;
@@ -77,11 +89,11 @@ public class MockConfigurationProvider i
     public void loadPackages() {
         
         PackageConfig.Builder defaultPackageContext = new PackageConfig.Builder("defaultPackage");
-        HashMap params = new HashMap();
+        Map<String, String> params = new HashMap<String, String>();
         params.put("bar", "5");
 
-        HashMap results = new HashMap();
-        HashMap successParams = new HashMap();
+        Map<String, ResultConfig> results = new HashMap<String, ResultConfig>();
+        Map<String, String> successParams = new HashMap<String, String>();
         successParams.put("actionName", "bar");
         results.put("success", new ResultConfig.Builder("success", ActionChainResult.class.getName()).addParams(successParams).build());
 
@@ -90,8 +102,8 @@ public class MockConfigurationProvider i
             .build();
         defaultPackageContext.addActionConfig(FOO_ACTION_NAME, fooActionConfig);
 
-        results = new HashMap();
-        successParams = new HashMap();
+        results = new HashMap<String, ResultConfig>();
+        successParams = new HashMap<String, String>();
         successParams.put("actionName", "bar");
         results.put("success", new ResultConfig.Builder("success", ActionChainResult.class.getName()).addParams(successParams).build());
 
@@ -106,9 +118,9 @@ public class MockConfigurationProvider i
 
         interceptors = new ArrayList<InterceptorMapping>();
         interceptors.add(new InterceptorMapping("model", 
-                objectFactory.buildInterceptor(new InterceptorConfig.Builder("model", ModelDrivenInterceptor.class.getName()).build(),
new HashMap())));
+                objectFactory.buildInterceptor(new InterceptorConfig.Builder("model", ModelDrivenInterceptor.class.getName()).build(),
EMPTY_STRING_MAP)));
         interceptors.add(new InterceptorMapping("params",
-                objectFactory.buildInterceptor(new InterceptorConfig.Builder("model", ParametersInterceptor.class.getName()).build(),
new HashMap())));
+                objectFactory.buildInterceptor(new InterceptorConfig.Builder("model", ParametersInterceptor.class.getName()).build(),
EMPTY_STRING_MAP)));
 
         ActionConfig modelParamActionConfig = new ActionConfig.Builder("defaultPackage",
MODEL_DRIVEN_PARAM_TEST, ModelDrivenAction.class.getName())
             .addInterceptors(interceptors)
@@ -122,28 +134,23 @@ public class MockConfigurationProvider i
         
 
         results = new HashMap<String, ResultConfig>();
-        successParams = new HashMap();
+        successParams = new HashMap<String, String>();
         successParams.put("actionName", "bar");
         results.put("success", new ResultConfig.Builder("success", ActionChainResult.class.getName()).addParams(successParams).build());
         results.put(Action.ERROR, new ResultConfig.Builder(Action.ERROR, MockResult.class.getName()).build());
 
         interceptors = new ArrayList<InterceptorMapping>();
         interceptors.add(new InterceptorMapping("staticParams", 
-                objectFactory.buildInterceptor(new InterceptorConfig.Builder("model", StaticParametersInterceptor.class.getName()).build(),
new HashMap())));
+                objectFactory.buildInterceptor(new InterceptorConfig.Builder("model", StaticParametersInterceptor.class.getName()).build(),
EMPTY_STRING_MAP)));
         interceptors.add(new InterceptorMapping("model", 
-                objectFactory.buildInterceptor(new InterceptorConfig.Builder("model", ModelDrivenInterceptor.class.getName()).build(),
new HashMap())));
+                objectFactory.buildInterceptor(new InterceptorConfig.Builder("model", ModelDrivenInterceptor.class.getName()).build(),
EMPTY_STRING_MAP)));
         interceptors.add(new InterceptorMapping("params", 
-                objectFactory.buildInterceptor(new InterceptorConfig.Builder("model", ParametersInterceptor.class.getName()).build(),
new HashMap())));
+                objectFactory.buildInterceptor(new InterceptorConfig.Builder("model", ParametersInterceptor.class.getName()).build(),
EMPTY_STRING_MAP)));
         interceptors.add(new InterceptorMapping("validation", 
-                objectFactory.buildInterceptor(new InterceptorConfig.Builder("model", ValidationInterceptor.class.getName()).build(),
new HashMap())));
+                objectFactory.buildInterceptor(new InterceptorConfig.Builder("model", ValidationInterceptor.class.getName()).build(),
EMPTY_STRING_MAP)));
 
         //Explicitly set an out-of-range date for DateRangeValidatorTest
-        params = new HashMap();
-        params.put("date", new java.util.Date(2002 - 1900, 11, 20));
-
-        //Explicitly set an out-of-range double for DoubleRangeValidatorTest
-        params.put("percentage", new Double(100.0123));
-
+        params = new HashMap<String, String>();
         ActionConfig validationActionConfig = new ActionConfig.Builder("defaultPackage",
VALIDATION_ACTION_NAME, SimpleAction.class.getName())
             .addInterceptors(interceptors)
             .addParams(params)
@@ -156,8 +163,7 @@ public class MockConfigurationProvider i
                 new ActionConfig.Builder(validationActionConfig).name(VALIDATION_SUBPROPERTY_NAME).build());
 
 
-        params = new HashMap();
-        params.put("percentage", new Double(1.234567));
+        params = new HashMap<String, String>();
         ActionConfig percentageActionConfig = new ActionConfig.Builder("defaultPackage",
"percentage", SimpleAction.class.getName())
                 .addParams(params)
                 .addResultConfigs(results)

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/DoubleRangeValidatorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/DoubleRangeValidatorTest.java?rev=1428072&r1=1428071&r2=1428072&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/DoubleRangeValidatorTest.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/DoubleRangeValidatorTest.java
Wed Jan  2 21:41:26 2013
@@ -6,6 +6,7 @@ import com.opensymphony.xwork2.config.pr
 import com.opensymphony.xwork2.util.ValueStack;
 import com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator;
 
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
@@ -22,11 +23,17 @@ public class DoubleRangeValidatorTest ex
     private DoubleRangeFieldValidator val;
 
     public void testRangeValidationWithError() throws Exception {
+        //Explicitly set an out-of-range double for DoubleRangeValidatorTest
+        Map<String, Object> context = new HashMap<String, Object>();
+        HashMap<String, Object> params = new HashMap<String, Object>();
+        params.put("percentage", 100.0123d);
+        context.put(ActionContext.PARAMETERS, params);
+
         // must set a locale to US as error message contains a locale dependent number (see
XW-490)
         Locale defLocale = Locale.getDefault();
         Locale.setDefault(Locale.US);
         
-        ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME,
null);
+        ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME,
context);
         proxy.execute();
         assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
 
@@ -45,7 +52,12 @@ public class DoubleRangeValidatorTest ex
     }
 
     public void testRangeValidationNoError() throws Exception {
-        ActionProxy proxy = actionProxyFactory.createActionProxy("", "percentage", null);
+        Map<String, Object> context = new HashMap<String, Object>();
+        HashMap<String, Object> params = new HashMap<String, Object>();
+        params.put("percentage", 1.234567d);
+        context.put(ActionContext.PARAMETERS, params);
+
+        ActionProxy proxy = actionProxyFactory.createActionProxy("", "percentage", context);
         proxy.execute();
         assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
 
@@ -183,6 +195,7 @@ public class DoubleRangeValidatorTest ex
         loadConfigurationProviders(provider,  new MockConfigurationProvider());
         val = new DoubleRangeFieldValidator();
         val.setValueStack(ActionContext.getContext().getValueStack());
+        ActionContext.getContext().setParameters(new HashMap<String, Object>());
     }
 
     @Override

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/ValidationAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/ValidationAction.java?rev=1428072&r1=1428071&r2=1428072&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/ValidationAction.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/ValidationAction.java
Wed Jan  2 21:41:26 2013
@@ -1,5 +1,7 @@
 package com.opensymphony.xwork2.validator.validators;
 
+import java.util.Date;
+
 public class ValidationAction {
 
     private Integer intRange;
@@ -14,6 +16,11 @@ public class ValidationAction {
     private Long longMinValue;
     private Long longMaxValue;
 
+    private Date dateRange;
+    private Date dateMinValue;
+    private Date dateMaxValue;
+    private String dateFormat;
+
     public Integer getIntRange() {
         return intRange;
     }
@@ -86,4 +93,35 @@ public class ValidationAction {
         this.longMaxValue = longMaxValue;
     }
 
+    public Date getDateRange() {
+        return dateRange;
+    }
+
+    public void setDateRange(Date dateRange) {
+        this.dateRange = dateRange;
+    }
+
+    public Date getDateMinValue() {
+        return dateMinValue;
+    }
+
+    public void setDateMinValue(Date dateMinValue) {
+        this.dateMinValue = dateMinValue;
+    }
+
+    public Date getDateMaxValue() {
+        return dateMaxValue;
+    }
+
+    public void setDateMaxValue(Date dateMaxValue) {
+        this.dateMaxValue = dateMaxValue;
+    }
+
+    public String getDateFormat() {
+        return dateFormat;
+    }
+
+    public void setDateFormat(String dateFormat) {
+        this.dateFormat = dateFormat;
+    }
 }



Mime
View raw message