Revision: 1316 http://stripes.svn.sourceforge.net/stripes/?rev=1316&view=rev Author: bengunter Date: 2010-11-10 16:55:54 +0000 (Wed, 10 Nov 2010)
Log Message: ----------- Applied fixes for locale-dependent tests (r1272) from 1.5.x branch to trunk. Modified Paths: -------------- trunk/tests/src/net/sourceforge/stripes/StripesTestFixture.java trunk/tests/src/net/sourceforge/stripes/controller/GenericsBindingTests.java trunk/tests/src/net/sourceforge/stripes/controller/GenericsBindingTests2.java trunk/tests/src/net/sourceforge/stripes/controller/MapBindingTests.java trunk/tests/src/net/sourceforge/stripes/validation/OneToManyTypeConverterTest.java Added Paths: ----------- trunk/tests/src/net/sourceforge/stripes/localization/MockLocalePicker.java Modified: trunk/tests/src/net/sourceforge/stripes/StripesTestFixture.java =================================================================== --- trunk/tests/src/net/sourceforge/stripes/StripesTestFixture.java 2010-11-10 16:40:55 UTC (rev 1315) +++ trunk/tests/src/net/sourceforge/stripes/StripesTestFixture.java 2010-11-10 16:55:54 UTC (rev 1316) @@ -1,6 +1,6 @@ package net.sourceforge.stripes; -import java.util.Collections; +import java.util.HashMap; import java.util.Map; import net.sourceforge.stripes.config.BootstrapPropertyResolver; @@ -56,6 +56,9 @@ /** Gets a map containing the default initialization parameters for StripesFilter */ public static Map<String, String> getDefaultFilterParams() { - return Collections.singletonMap("ActionResolver.Packages", "net.sourceforge.stripes"); + Map<String, String> map = new HashMap<String, String>(); + map.put("ActionResolver.Packages", "net.sourceforge.stripes"); + map.put("LocalePicker.Class", "net.sourceforge.stripes.localization.MockLocalePicker"); + return map; } } Modified: trunk/tests/src/net/sourceforge/stripes/controller/GenericsBindingTests.java =================================================================== --- trunk/tests/src/net/sourceforge/stripes/controller/GenericsBindingTests.java 2010-11-10 16:40:55 UTC (rev 1315) +++ trunk/tests/src/net/sourceforge/stripes/controller/GenericsBindingTests.java 2010-11-10 16:55:54 UTC (rev 1316) @@ -13,6 +13,7 @@ import java.util.Calendar; import java.util.Date; +import java.util.Locale; /** * @@ -40,6 +41,7 @@ @Test(groups="fast") public void testSimpleTypeVariable() throws Exception { MockRoundtrip trip = getRoundtrip(); + trip.getRequest().addLocale(Locale.ENGLISH); trip.addParameter("number", "123.4"); trip.execute(); @@ -51,6 +53,7 @@ @Test(groups="fast") public void testGenericBean() throws Exception { MockRoundtrip trip = getRoundtrip(); + trip.getRequest().addLocale(Locale.ENGLISH); trip.addParameter("genericBean.genericA", "123.4"); trip.addParameter("genericBean.genericB", "true"); trip.execute(); Modified: trunk/tests/src/net/sourceforge/stripes/controller/GenericsBindingTests2.java =================================================================== --- trunk/tests/src/net/sourceforge/stripes/controller/GenericsBindingTests2.java 2010-11-10 16:40:55 UTC (rev 1315) +++ trunk/tests/src/net/sourceforge/stripes/controller/GenericsBindingTests2.java 2010-11-10 16:55:54 UTC (rev 1316) @@ -2,6 +2,7 @@ import java.util.Calendar; import java.util.Date; +import java.util.Locale; import net.sourceforge.stripes.StripesTestFixture; import net.sourceforge.stripes.action.ActionBean; import net.sourceforge.stripes.action.ActionBeanContext; @@ -51,6 +52,7 @@ @Test(groups="fast") public void testSimpleTypeVariable() throws Exception { MockRoundtrip trip = getRoundtrip(); + trip.getRequest().addLocale(Locale.ENGLISH); trip.addParameter("number", "123.4"); trip.execute(); @@ -62,6 +64,7 @@ @Test(groups="fast") public void testGenericBean() throws Exception { MockRoundtrip trip = getRoundtrip(); + trip.getRequest().addLocale(Locale.ENGLISH); trip.addParameter("genericBean.genericA", "123.4"); trip.addParameter("genericBean.genericB", "true"); trip.execute(); Modified: trunk/tests/src/net/sourceforge/stripes/controller/MapBindingTests.java =================================================================== --- trunk/tests/src/net/sourceforge/stripes/controller/MapBindingTests.java 2010-11-10 16:40:55 UTC (rev 1315) +++ trunk/tests/src/net/sourceforge/stripes/controller/MapBindingTests.java 2010-11-10 16:55:54 UTC (rev 1316) @@ -15,6 +15,7 @@ import java.util.Calendar; import java.util.Date; import java.util.HashMap; +import java.util.Locale; import java.util.Map; /** @@ -64,11 +65,11 @@ public void setMapDateDate(Map<Date, Date> mapDateDate) { this.mapDateDate = mapDateDate; } /** A map completely lacking in type information!!. */ - @SuppressWarnings("unchecked") - private Map typelessMap; - @SuppressWarnings("unchecked") + @SuppressWarnings("rawtypes") + private Map typelessMap; + @SuppressWarnings("rawtypes") public Map getTypelessMap() { return typelessMap; } - @SuppressWarnings("unchecked") + @SuppressWarnings("rawtypes") public void setTypelessMap(Map typelessMap) { this.typelessMap = typelessMap; } /** Helper method to create a roundtrip with the TestActionBean class. */ @@ -230,6 +231,7 @@ @Test(groups="fast") public void bindDateKeysInMap() throws Exception { MockRoundtrip trip = getRoundtrip(); + trip.getRequest().addLocale(Locale.ENGLISH); trip.addParameter("mapDateDate['31-Dec-1999']", "01/01/2000"); trip.execute(); @@ -242,7 +244,7 @@ Assert.assertNotNull(bean.getMapDateDate().get(key)); } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) @Before(stages=LifecycleStage.BindingAndValidation) public void populateTypelessMap() { this.typelessMap = new HashMap(); Added: trunk/tests/src/net/sourceforge/stripes/localization/MockLocalePicker.java =================================================================== --- trunk/tests/src/net/sourceforge/stripes/localization/MockLocalePicker.java (rev 0) +++ trunk/tests/src/net/sourceforge/stripes/localization/MockLocalePicker.java 2010-11-10 16:55:54 UTC (rev 1316) @@ -0,0 +1,40 @@ +/* Copyright 2010 Marcus Krassmann + * + * 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 net.sourceforge.stripes.localization; + +import java.util.Locale; + +import javax.servlet.http.HttpServletRequest; + +import net.sourceforge.stripes.config.Configuration; + +/** + * Simple locale picker that just uses the locale of the passed HttpServletRequest. This should be + * used for locale dependent test cases. + * + * @author Marcus Krassmann + */ +public class MockLocalePicker implements LocalePicker { + public Locale pickLocale(HttpServletRequest request) { + return request.getLocale() == null ? Locale.getDefault() : request.getLocale(); + } + + public String pickCharacterEncoding(HttpServletRequest request, Locale locale) { + return "UTF-8"; + } + + public void init(Configuration configuration) throws Exception { + } +} \ No newline at end of file Modified: trunk/tests/src/net/sourceforge/stripes/validation/OneToManyTypeConverterTest.java =================================================================== --- trunk/tests/src/net/sourceforge/stripes/validation/OneToManyTypeConverterTest.java 2010-11-10 16:40:55 UTC (rev 1315) +++ trunk/tests/src/net/sourceforge/stripes/validation/OneToManyTypeConverterTest.java 2010-11-10 16:55:54 UTC (rev 1316) @@ -16,6 +16,7 @@ import java.util.Collection; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.Locale; /** * Unit tests that ensure that the OneToManyTypeConverter works in the context of the @@ -42,6 +43,7 @@ @Test(groups="fast") public void testListOfDate() throws Exception { MockRoundtrip trip = new MockRoundtrip(StripesTestFixture.getServletContext(), getClass()); + trip.getRequest().addLocale(Locale.ENGLISH); trip.addParameter("dates", "12/31/2005, 1/1/2006, 6/15/2008, 7/7/2007"); trip.execute(); OneToManyTypeConverterTest bean = trip.getActionBean(getClass()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ The Next 800 Companies to Lead America's Growth: New Video Whitepaper David G. Thomson, author of the best-selling book "Blueprint to a Billion" shares his insights and actions to help propel your business during the next growth cycle. Listen Now! http://p.sf.net/sfu/SAP-dev2dev _______________________________________________ Stripes-development mailing list Stripes-development@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/stripes-development