mirror of
https://github.com/apache/struts.git
synced 2026-08-07 07:37:20 +00:00
WW-4049 Removes Locale.setDefault() from tests
This commit is contained in:
@@ -34,14 +34,13 @@ import junit.framework.TestCase;
|
||||
public class DefaultBeanSelectionProviderTest extends TestCase {
|
||||
|
||||
public void testRegister() {
|
||||
Locale.setDefault(Locale.US); // force to US locale as we also have _de and _da properties
|
||||
|
||||
LocalizedTextUtil.clearDefaultResourceBundles();
|
||||
LocalizedTextUtil.addDefaultResourceBundle("org/apache/struts2/struts-messages");
|
||||
assertEquals("The form has already been processed or no token was supplied, please try again.", LocalizedTextUtil.findDefaultText("struts.messages.invalid.token", Locale.getDefault()));
|
||||
|
||||
LocatableProperties props = new LocatableProperties();
|
||||
props.setProperty(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES, "testmessages,testmessages2");
|
||||
props.setProperty(StrutsConstants.STRUTS_LOCALE, "US");
|
||||
|
||||
new DefaultBeanSelectionProvider().register(new ContainerBuilder(), props);
|
||||
|
||||
|
||||
@@ -56,8 +56,6 @@ import java.util.Map;
|
||||
public class DispatcherTest extends StrutsInternalTestCase {
|
||||
|
||||
public void testDefaultResurceBundlePropertyLoaded() throws Exception {
|
||||
Locale.setDefault(Locale.US); // force to US locale as we also have _de and _da properties
|
||||
|
||||
// some i18n messages from xwork-messages.properties
|
||||
assertEquals(
|
||||
LocalizedTextUtil.findDefaultText("xwork.error.action.execution", Locale.US),
|
||||
|
||||
-1
@@ -319,7 +319,6 @@ public class OValValidationInterceptorTest extends XWorkTestCase {
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
Locale.setDefault(Locale.US);
|
||||
super.setUp();
|
||||
loadConfigurationProviders(new XmlConfigurationProvider("oval-test.xml"));
|
||||
}
|
||||
|
||||
@@ -202,6 +202,11 @@
|
||||
<artifactId>easymock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- SLF4J support -->
|
||||
<dependency>
|
||||
|
||||
@@ -16,9 +16,11 @@
|
||||
package com.opensymphony.xwork2.config.impl;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.DefaultLocaleProvider;
|
||||
import com.opensymphony.xwork2.DefaultTextProvider;
|
||||
import com.opensymphony.xwork2.FileManager;
|
||||
import com.opensymphony.xwork2.FileManagerFactory;
|
||||
import com.opensymphony.xwork2.LocaleProvider;
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.TextProvider;
|
||||
import com.opensymphony.xwork2.XWorkConstants;
|
||||
@@ -335,6 +337,7 @@ public class DefaultConfiguration implements Configuration {
|
||||
|
||||
builder.factory(TextParser.class, OgnlTextParser.class, Scope.SINGLETON);
|
||||
builder.factory(TextProvider.class, "system", DefaultTextProvider.class, Scope.SINGLETON);
|
||||
builder.factory(LocaleProvider.class, DefaultLocaleProvider.class, Scope.SINGLETON);
|
||||
|
||||
builder.factory(ObjectTypeDeterminer.class, DefaultObjectTypeDeterminer.class, Scope.SINGLETON);
|
||||
builder.factory(PropertyAccessor.class, CompoundRoot.class.getName(), CompoundRootAccessor.class, Scope.SINGLETON);
|
||||
|
||||
+14
-5
@@ -31,7 +31,9 @@
|
||||
package com.opensymphony.xwork2.conversion.impl;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.LocaleProvider;
|
||||
import com.opensymphony.xwork2.conversion.TypeConverter;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.ognl.XWorkTypeConverterWrapper;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
@@ -50,7 +52,7 @@ import java.util.Map;
|
||||
* @author Luke Blanshard (blanshlu@netscape.net)
|
||||
* @author Drew Davidson (drew@ognl.org)
|
||||
*/
|
||||
public class DefaultTypeConverter implements TypeConverter {
|
||||
public abstract class DefaultTypeConverter implements TypeConverter {
|
||||
|
||||
protected static String MILLISECOND_FORMAT = ".SSS";
|
||||
|
||||
@@ -58,6 +60,8 @@ public class DefaultTypeConverter implements TypeConverter {
|
||||
|
||||
private static final Map<Class, Object> primitiveDefaults;
|
||||
|
||||
private LocaleProvider localeProvider;
|
||||
|
||||
static {
|
||||
Map<Class, Object> map = new HashMap<Class, Object>();
|
||||
map.put(Boolean.TYPE, Boolean.FALSE);
|
||||
@@ -73,6 +77,11 @@ public class DefaultTypeConverter implements TypeConverter {
|
||||
primitiveDefaults = Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setLocaleProvider(LocaleProvider localeProvider) {
|
||||
this.localeProvider = localeProvider;
|
||||
}
|
||||
|
||||
public Object convertValue(Map<String, Object> context, Object value, Class toType) {
|
||||
return convertValue(value, toType);
|
||||
}
|
||||
@@ -332,12 +341,12 @@ public class DefaultTypeConverter implements TypeConverter {
|
||||
}
|
||||
|
||||
protected Locale getLocale(Map<String, Object> context) {
|
||||
if (context == null) {
|
||||
return Locale.getDefault();
|
||||
Locale locale = null;
|
||||
if (context != null) {
|
||||
locale = (Locale) context.get(ActionContext.LOCALE);
|
||||
}
|
||||
Locale locale = (Locale) context.get(ActionContext.LOCALE);
|
||||
if (locale == null) {
|
||||
locale = Locale.getDefault();
|
||||
locale = localeProvider.getLocale();
|
||||
}
|
||||
return locale;
|
||||
}
|
||||
|
||||
@@ -333,9 +333,6 @@ public class OgnlUtilTest extends XWorkTestCase {
|
||||
}
|
||||
|
||||
public void testSetPropertiesDate() {
|
||||
Locale orig = Locale.getDefault();
|
||||
Locale.setDefault(Locale.US);
|
||||
|
||||
Foo foo = new Foo();
|
||||
|
||||
Map context = ognlUtil.createDefaultContext(foo);
|
||||
@@ -353,10 +350,11 @@ public class OgnlUtilTest extends XWorkTestCase {
|
||||
|
||||
assertEquals(cal.getTime(), foo.getBirthday());
|
||||
|
||||
Locale.setDefault(Locale.UK);
|
||||
//UK style test
|
||||
props.put("event", "18/10/2006 14:23:45");
|
||||
props.put("meeting", "09/09/2006 14:30");
|
||||
context.put(ActionContext.LOCALE, Locale.UK);
|
||||
|
||||
ognlUtil.setProperties(props, foo, context);
|
||||
|
||||
cal = Calendar.getInstance();
|
||||
@@ -380,10 +378,6 @@ public class OgnlUtilTest extends XWorkTestCase {
|
||||
|
||||
assertEquals(cal.getTime(), foo.getMeeting());
|
||||
|
||||
Locale.setDefault(orig);
|
||||
|
||||
Locale.setDefault(orig);
|
||||
|
||||
//test RFC 3339 date format for JSON
|
||||
props.put("event", "1996-12-19T16:39:57Z");
|
||||
ognlUtil.setProperties(props, foo, context);
|
||||
|
||||
@@ -223,17 +223,10 @@ public class LocalizedTextUtilTest extends XWorkTestCase {
|
||||
// Before this fix loading the bundle for Germany failed since Italy have previously failed and thus the misses cache
|
||||
// contained a false entry
|
||||
|
||||
// Set default Locale to Locale.US
|
||||
Locale defaultLocale = Locale.getDefault();
|
||||
Locale.setDefault(Locale.US);
|
||||
|
||||
ResourceBundle rbFrance = LocalizedTextUtil.findResourceBundle("com/opensymphony/xwork2/util/XW404", Locale.FRANCE);
|
||||
ResourceBundle rbItaly = LocalizedTextUtil.findResourceBundle("com/opensymphony/xwork2/util/XW404", Locale.ITALY);
|
||||
ResourceBundle rbGermany = LocalizedTextUtil.findResourceBundle("com/opensymphony/xwork2/util/XW404", Locale.GERMANY);
|
||||
|
||||
// Reset to previous default Locale
|
||||
Locale.setDefault(defaultLocale);
|
||||
|
||||
assertNotNull(rbFrance);
|
||||
assertEquals("Bonjour", rbFrance.getString("hello"));
|
||||
|
||||
|
||||
@@ -38,9 +38,6 @@ import java.util.Map;
|
||||
*/
|
||||
public class DateRangeValidatorTest extends XWorkTestCase {
|
||||
|
||||
private Locale origLocale;
|
||||
|
||||
|
||||
/**
|
||||
* Tests whether the date range validation is working. Should produce an validation error,
|
||||
* because the action config sets date to 12/20/2002 while expected range is Dec 22-25.
|
||||
@@ -81,14 +78,11 @@ public class DateRangeValidatorTest extends XWorkTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
origLocale = Locale.getDefault();
|
||||
Locale.setDefault(Locale.US);
|
||||
loadConfigurationProviders(new MockConfigurationProvider());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
Locale.setDefault(origLocale);
|
||||
}
|
||||
}
|
||||
|
||||
-12
@@ -29,10 +29,6 @@ public class DoubleRangeValidatorTest extends XWorkTestCase {
|
||||
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, context);
|
||||
proxy.execute();
|
||||
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
|
||||
@@ -46,8 +42,6 @@ public class DoubleRangeValidatorTest extends XWorkTestCase {
|
||||
String errorMessage = errorMessages.get(0);
|
||||
assertNotNull("Expecting: percentage must be between 0.1 and 10.1, current value is 100.0123.", errorMessage);
|
||||
assertEquals("percentage must be between 0.1 and 10.1, current value is 100.0123.", errorMessage);
|
||||
|
||||
Locale.setDefault(defLocale);
|
||||
}
|
||||
|
||||
public void testRangeValidationNoError() throws Exception {
|
||||
@@ -193,10 +187,6 @@ public class DoubleRangeValidatorTest extends XWorkTestCase {
|
||||
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.EXPRESSION_VALIDATION_ACTION, context);
|
||||
proxy.execute();
|
||||
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
|
||||
@@ -209,8 +199,6 @@ public class DoubleRangeValidatorTest extends XWorkTestCase {
|
||||
String errorMessage = errorMessages.get(0);
|
||||
assertNotNull("Expecting: percentage must be between 0.1 and 10.1, current value is 100.0123.", errorMessage);
|
||||
assertEquals("percentage must be between 0.1 and 10.1, current value is 100.0123.", errorMessage);
|
||||
|
||||
Locale.setDefault(defLocale);
|
||||
}
|
||||
|
||||
public void testExpressionParams() throws Exception {
|
||||
|
||||
-9
@@ -33,9 +33,6 @@ import java.util.*;
|
||||
*/
|
||||
public class SimpleActionValidationTest extends XWorkTestCase {
|
||||
|
||||
private Locale origLocale;
|
||||
|
||||
|
||||
public void testAliasValidation() {
|
||||
HashMap<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("baz", "10");
|
||||
@@ -225,16 +222,10 @@ public class SimpleActionValidationTest extends XWorkTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
origLocale = Locale.getDefault();
|
||||
Locale.setDefault(Locale.US);
|
||||
|
||||
XmlConfigurationProvider provider = new XmlConfigurationProvider("xwork-test-beans.xml");
|
||||
container.inject(provider);
|
||||
loadConfigurationProviders(provider, new MockConfigurationProvider());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
Locale.setDefault(origLocale);
|
||||
}
|
||||
}
|
||||
|
||||
-6
@@ -33,15 +33,10 @@ import org.easymock.EasyMock;
|
||||
public class VisitorFieldValidatorModelTest extends XWorkTestCase {
|
||||
|
||||
protected VisitorValidatorModelAction action;
|
||||
private Locale origLocale;
|
||||
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
origLocale = Locale.getDefault();
|
||||
Locale.setDefault(Locale.US);
|
||||
|
||||
action = new VisitorValidatorModelAction();
|
||||
|
||||
TestBean bean = action.getBean();
|
||||
@@ -125,6 +120,5 @@ public class VisitorFieldValidatorModelTest extends XWorkTestCase {
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
ActionContext.setContext(null);
|
||||
Locale.setDefault(origLocale);
|
||||
}
|
||||
}
|
||||
|
||||
-5
@@ -34,14 +34,10 @@ import org.easymock.IAnswer;
|
||||
public class VisitorFieldValidatorTest extends XWorkTestCase {
|
||||
|
||||
protected VisitorValidatorTestAction action;
|
||||
private Locale origLocale;
|
||||
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
origLocale = Locale.getDefault();
|
||||
Locale.setDefault(Locale.US);
|
||||
|
||||
action = new VisitorValidatorTestAction();
|
||||
|
||||
@@ -209,7 +205,6 @@ public class VisitorFieldValidatorTest extends XWorkTestCase {
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
ActionContext.setContext(null);
|
||||
Locale.setDefault(origLocale);
|
||||
}
|
||||
|
||||
private void validate(String context) throws ValidationException {
|
||||
|
||||
+2
-10
@@ -1,5 +1,6 @@
|
||||
package com.opensymphony.xwork2.validator.validators;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.XWorkTestCase;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import com.opensymphony.xwork2.util.ValueStackFactory;
|
||||
@@ -12,8 +13,6 @@ import java.util.Locale;
|
||||
|
||||
public class DateRangeFieldValidatorTest extends XWorkTestCase {
|
||||
|
||||
private Locale copy;
|
||||
|
||||
public void testPassValidation() throws Exception {
|
||||
// given
|
||||
ValidationAction action = prepareAction(createDate(2013, 6, 6));
|
||||
@@ -88,14 +87,7 @@ public class DateRangeFieldValidatorTest extends XWorkTestCase {
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
copy = Locale.getDefault();
|
||||
Locale.setDefault(new Locale("DE"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
Locale.setDefault(copy);
|
||||
ActionContext.getContext().setLocale(new Locale("DE"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,6 @@
|
||||
log4j.rootLogger = WARN, stdout
|
||||
log4j.rootLogger = INFO, stdout
|
||||
|
||||
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.Threshold = WARN
|
||||
log4j.appender.stdout.Target = System.out
|
||||
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern = %d{ISO8601} %-5p [%F:%L] : %m%n
|
||||
|
||||
# set to info to let the code be executed when doing unit test for this interceptor
|
||||
log4j.category.com.opensymphony.xwork2.interceptor.LoggingInterceptor=INFO
|
||||
log4j.category.com.opensymphony.xwork2.interceptor.TimerInterceptor=INFO
|
||||
|
||||
# set to debug to let the code be executed when doing unit test for this interceptor
|
||||
log4j.category.com.opensymphony.xwork2.interceptor.ParametersInterceptor=DEBUG
|
||||
|
||||
# set to debug for testing timer interceptor with custom log category
|
||||
log4j.category.com.mycompany.myapp.actiontiming=DEBUG
|
||||
|
||||
Reference in New Issue
Block a user