You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2020/04/21 18:42:35 UTC

[struts] 01/01: Reverse merges master

This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch action-context-boost
in repository https://gitbox.apache.org/repos/asf/struts.git

commit f071c9d0edd1bd7f6a5f0b3068996a88248a5806
Merge: 2f27e45 230a300
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Tue Apr 21 20:42:15 2020 +0200

    Reverse merges master

 Jenkinsfile                                        |  63 ++++++---
 apps/rest-showcase/pom.xml                         |   2 +-
 apps/showcase/pom.xml                              |   6 +-
 .../xwork2/conversion/impl/DateConverter.java      |   6 +-
 .../xwork2/conversion/impl/NumberConverter.java    |  18 +--
 .../conversion/impl/XWorkBasicConverter.java       |  16 +--
 .../conversion/TypeConversionException.java        |   2 +-
 .../xwork2/conversion/impl/DateConverterTest.java  | 118 +++++++++++++++++
 .../conversion/impl/NumberConverterTest.java       | 143 +++++++++++++++++++++
 .../conversion/impl/XWorkBasicConverterTest.java   |  90 ++++++++++++-
 plugins/bean-validation/pom.xml                    |   6 +-
 plugins/cdi/pom.xml                                |   2 +-
 pom.xml                                            |  88 +++++++------
 13 files changed, 472 insertions(+), 88 deletions(-)

diff --cc core/src/test/java/com/opensymphony/xwork2/conversion/impl/NumberConverterTest.java
index 2b6f34b,049e740..b0271ea
--- a/core/src/test/java/com/opensymphony/xwork2/conversion/impl/NumberConverterTest.java
+++ b/core/src/test/java/com/opensymphony/xwork2/conversion/impl/NumberConverterTest.java
@@@ -18,8 -18,10 +18,9 @@@
   */
  package com.opensymphony.xwork2.conversion.impl;
  
 -import com.opensymphony.xwork2.ActionContext;
  import com.opensymphony.xwork2.SimpleFooAction;
  import com.opensymphony.xwork2.XWorkTestCase;
+ import org.apache.struts2.conversion.TypeConversionException;
  import org.apache.commons.lang3.StringUtils;
  
  import java.math.BigDecimal;
@@@ -27,7 -30,17 +28,17 @@@ import java.util.Locale
  import java.util.Map;
  
  public class NumberConverterTest extends XWorkTestCase {
 -    
 +
+     private final static String FLOAT_OUT_OF_RANGE = "3.5028235E38";
+     private final static String DOUBLE_OUT_OF_RANGE = "1.7976931348623157E309";
+     private final static String INTEGER_OUT_OF_RANGE = "2147483648";
+     private final static String MSG_OUT_OF_RANGE_CASTING = "Overflow or underflow casting";
+     private final static String MSG_OUT_OF_RANGE_CONVERTING = "Overflow or underflow converting";
+     private final static String MSG_UNPARSEABLE_NUMBER = "Unparseable number";
+     private final static String MSG_TEST_FAILS_OUT_OF_RANGE = "TypeConversionException expected when OUT OF RANGE";
+     private final static String MSG_TEST_FAILS_UNPARSEABLE_NUMBER = "TypeConversionException expected when UNPARSEABLE NUMBER";
+     private final static Locale LOCALE_MEXICO = new Locale("es_MX", "MX");
+ 
      public void testStringToNumberConversionPL() throws Exception {
          // given
          NumberConverter converter = new NumberConverter();
@@@ -157,6 -179,146 +168,138 @@@
          // then
          assertEquals(1234.4F, value);
      }
 -    
 +
+     public void testExceptionWhenPrimitiveIsOutOfRange() {
+         // given
+         NumberConverter converter = new NumberConverter();
 -        Map<String, Object> context = new HashMap<>();
 -        context.put(ActionContext.LOCALE, LOCALE_MEXICO);
 -        
++        Map<String, Object> context = createContextWithLocale(LOCALE_MEXICO);
++
+         // when
+         try {
+             Object value = converter.convertValue(context, null, null, null, INTEGER_OUT_OF_RANGE, int.class);
+             fail(MSG_TEST_FAILS_OUT_OF_RANGE);
+         } catch (Exception ex) {
+             // then
+             assertEquals(TypeConversionException.class, ex.getClass());
+             assertTrue(ex.getMessage().startsWith(MSG_OUT_OF_RANGE_CASTING));
+         }
+     }
 -    
++
+     public void testExceptionWhenANotPrimitiveIsUnparsable() {
+         // given
+         NumberConverter converter = new NumberConverter();
 -        Map<String, Object> context = new HashMap<>();
++        Map<String, Object> context = createContextWithLocale(LOCALE_MEXICO);
+         String strValue = "1.2";
 -        context.put(ActionContext.LOCALE, LOCALE_MEXICO);
 -        
++
+         // when
+         try {
+             Object value = converter.convertValue(context, null, null, null, strValue, Byte.class);
+             fail(MSG_TEST_FAILS_UNPARSEABLE_NUMBER);
+         } catch (Exception ex) {
+             // then
+             assertEquals(TypeConversionException.class, ex.getClass());
+             assertTrue(ex.getMessage().startsWith(MSG_UNPARSEABLE_NUMBER));
+         }
+     }
 -    
++
+     public void testExceptionWhenANotPrimitiveIsOutOfRange() {
+         // given
+         NumberConverter converter = new NumberConverter();
 -        Map<String, Object> context = new HashMap<>();
++        Map<String, Object> context = createContextWithLocale(LOCALE_MEXICO);
+         String strValue = "129";
 -        context.put(ActionContext.LOCALE, LOCALE_MEXICO);
 -        
++
+         // when
+         try {
+             Object value = converter.convertValue(context, null, null, null, strValue, Byte.class);
+             fail(MSG_TEST_FAILS_OUT_OF_RANGE);
+         } catch (Exception ex) {
+             // then
+             assertEquals(TypeConversionException.class, ex.getClass());
+             assertTrue(ex.getMessage().startsWith(MSG_OUT_OF_RANGE_CASTING));
+         }
+     }
 -    
++
+     public void testExceptionWhenUnparseableInConvertToBigDecimal() {
+         // given
+         NumberConverter converter = new NumberConverter();
 -        Map<String, Object> context = new HashMap<>();
++        Map<String, Object> context = createContextWithLocale(LOCALE_MEXICO);
+         String strValue = "1-23";
 -        context.put(ActionContext.LOCALE, LOCALE_MEXICO);
 -        
++
+         // when
+         try {
+             Object value = converter.convertValue(context, null, null, null, strValue, BigDecimal.class);
+             fail(MSG_TEST_FAILS_UNPARSEABLE_NUMBER);
+         } catch (Exception ex) {
+             // then
+             assertEquals(TypeConversionException.class, ex.getClass());
+             assertTrue(ex.getMessage().startsWith(MSG_UNPARSEABLE_NUMBER));
+         }
+     }
 -    
++
+     public void testExceptionWhenUnparseableInConvertToDouble() {
+         // given
+         NumberConverter converter = new NumberConverter();
 -        Map<String, Object> context = new HashMap<>();
++        Map<String, Object> context = createContextWithLocale(LOCALE_MEXICO);
+         String strValue = "1-23";
 -        context.put(ActionContext.LOCALE, LOCALE_MEXICO);
 -        
++
+         // when
+         try {
+             Object value = converter.convertValue(context, null, null, null, strValue, Double.class);
+             fail(MSG_TEST_FAILS_UNPARSEABLE_NUMBER);
+         } catch (Exception ex) {
+             // then
+             assertEquals(TypeConversionException.class, ex.getClass());
+             assertTrue(ex.getMessage().startsWith(MSG_UNPARSEABLE_NUMBER));
+         }
+     }
 -    
++
+     public void testExceptionWhenOutOfRangeInConvertToDouble() {
+         // given
+         NumberConverter converter = new NumberConverter();
 -        Map<String, Object> context = new HashMap<>();
 -        context.put(ActionContext.LOCALE, LOCALE_MEXICO);
 -        
++        Map<String, Object> context = createContextWithLocale(LOCALE_MEXICO);
++
+         // when
+         try {
+             Object value = converter.convertValue(context, null, null, null, DOUBLE_OUT_OF_RANGE, Double.class);
+             fail(MSG_TEST_FAILS_OUT_OF_RANGE);
+         } catch (Exception ex) {
+             // then
+             assertEquals(TypeConversionException.class, ex.getClass());
+             assertTrue(ex.getMessage().startsWith(MSG_OUT_OF_RANGE_CONVERTING));
+         }
+     }
 -    
++
+     public void testExceptionWhenOutOfRangeInConvertToFloat() {
+         // given
+         NumberConverter converter = new NumberConverter();
 -        Map<String, Object> context = new HashMap<>();
 -        context.put(ActionContext.LOCALE, LOCALE_MEXICO);
 -        
++        Map<String, Object> context = createContextWithLocale(LOCALE_MEXICO);
++
+         // when
+         try {
+             Object value = converter.convertValue(context, null, null, null, FLOAT_OUT_OF_RANGE, Float.class);
+             fail(MSG_TEST_FAILS_OUT_OF_RANGE);
+         } catch (Exception ex) {
+             // then
+             assertEquals(TypeConversionException.class, ex.getClass());
+             assertTrue(ex.getMessage().startsWith(MSG_OUT_OF_RANGE_CONVERTING));
+         }
+     }
 -    
++
+     public void testExceptionWhenUnparseableInConvertToFloat() {
+         // given
+         NumberConverter converter = new NumberConverter();
 -        Map<String, Object> context = new HashMap<>();
++        Map<String, Object> context = createContextWithLocale(LOCALE_MEXICO);
+         String strValue = "1-23";
 -        context.put(ActionContext.LOCALE, LOCALE_MEXICO);
 -        
++
+         // when
+         try {
+             Object value = converter.convertValue(context, null, null, null, strValue, Float.class);
+             fail(MSG_TEST_FAILS_UNPARSEABLE_NUMBER);
+         } catch (Exception ex) {
+             // then
+             assertEquals(TypeConversionException.class, ex.getClass());
+             assertTrue(ex.getMessage().startsWith(MSG_UNPARSEABLE_NUMBER));
+         }
+     }
 -    
 +
  }
diff --cc core/src/test/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverterTest.java
index 5c67924,33fea83..4209da1
--- a/core/src/test/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverterTest.java
+++ b/core/src/test/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverterTest.java
@@@ -295,8 -391,7 +382,7 @@@ public class XWorkBasicConverterTest ex
      @Override
      protected void tearDown() throws Exception {
          super.tearDown();
 -        ActionContext.setContext(null);
 +        ActionContext.clear();
      }
- 
- 
+     
  }