You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/04/03 20:39:21 UTC

svn commit: r1088376 - in /tapestry/tapestry5/trunk: tapestry-core/src/main/java/org/apache/tapestry5/util/ tapestry-core/src/main/resources/org/apache/tapestry5/util/ tapestry-core/src/test/java/org/apache/tapestry5/root/ tapestry-core/src/test/java/o...

Author: hlship
Date: Sun Apr  3 18:39:21 2011
New Revision: 1088376

URL: http://svn.apache.org/viewvc?rev=1088376&view=rev
Log:
TAP5-98: Move StringToEnumCoercion from tapestry-core to tapestry-ioc

Added:
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/util/
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/util/StringToEnumCoercion.java
      - copied, changed from r1087941, tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/StringToEnumCoercion.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/util/
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/util/Stooge.java
      - copied, changed from r1087941, tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/root/Stooge.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/util/StringToEnumCoercionTest.java
      - copied, changed from r1087941, tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/util/StringToEnumCoercionTest.java
Removed:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/StringToEnumCoercion.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/root/Stooge.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/util/StringToEnumCoercionTest.java
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/PublicUtilMessages.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/util/PublicUtilStrings.properties
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/util/EnumSelectModelTest.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/conf/testng.xml

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/PublicUtilMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/PublicUtilMessages.java?rev=1088376&r1=1088375&r2=1088376&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/PublicUtilMessages.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/PublicUtilMessages.java Sun Apr  3 18:39:21 2011
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -33,9 +33,4 @@ final class PublicUtilMessages
     {
         return MESSAGES.format("missing-value", value, InternalUtils.joinSorted(values));
     }
-
-    static String missingEnumValue(String value, Class enumClass, Collection<String> values)
-    {
-        return MESSAGES.format("missing-enum-value", value, enumClass.getName(), InternalUtils.joinSorted(values));
-    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/util/PublicUtilStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/util/PublicUtilStrings.properties?rev=1088376&r1=1088375&r2=1088376&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/util/PublicUtilStrings.properties (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/util/PublicUtilStrings.properties Sun Apr  3 18:39:21 2011
@@ -1,4 +1,4 @@
-# Copyright 2007 The Apache Software Foundation
+# Copyright 2007, 2011 The Apache Software Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -14,4 +14,3 @@
 
 duplicate-key=Key %s may not be added with value %s, as an existing value, %s, is already present.
 missing-value=Key for value %s not found. Available values: %s
-missing-enum-value=Input '%s' does not identify a value from enumerated type %s. Available values: %s.

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/util/EnumSelectModelTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/util/EnumSelectModelTest.java?rev=1088376&r1=1088375&r2=1088376&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/util/EnumSelectModelTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/util/EnumSelectModelTest.java Sun Apr  3 18:39:21 2011
@@ -1,10 +1,10 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2011 The Apache Software Foundation
 //
 // 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
+// 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,
@@ -17,7 +17,6 @@ package org.apache.tapestry5.util;
 import org.apache.tapestry5.OptionModel;
 import org.apache.tapestry5.SelectModel;
 import org.apache.tapestry5.ioc.Messages;
-import org.apache.tapestry5.root.Stooge;
 import org.apache.tapestry5.test.TapestryTestCase;
 import org.testng.annotations.Test;
 
@@ -25,6 +24,11 @@ import java.util.List;
 
 public class EnumSelectModelTest extends TapestryTestCase
 {
+    public enum Stooge
+    {
+        MOE, LARRY, CURLY_JOE
+    }
+
     @Test
     public void generated_labels()
     {

Copied: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/util/StringToEnumCoercion.java (from r1087941, tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/StringToEnumCoercion.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/util/StringToEnumCoercion.java?p2=tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/util/StringToEnumCoercion.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/StringToEnumCoercion.java&r1=1087941&r2=1088376&rev=1088376&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/StringToEnumCoercion.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/util/StringToEnumCoercion.java Sun Apr  3 18:39:21 2011
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2010 The Apache Software Foundation
+// Copyright 2007, 2008, 2010, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -26,6 +26,8 @@ import org.apache.tapestry5.ioc.util.Unk
  * A {@link org.apache.tapestry5.ioc.services.Coercion} for converting strings into an instance of a particular
  * enumerated type. The {@link Enum#name() name} is used as the key to identify the enum instance, in a case-insensitive
  * fashion.
+ * <p>
+ * Moved from tapestry-core to tapestry-ioc is release 5.3.0, but kept in same package for compatibility.
  * 
  * @param <T>
  *            the type of enumeration
@@ -57,9 +59,13 @@ public final class StringToEnumCoercion<
         T result = stringToEnum.get(input);
 
         if (result == null)
-            throw new UnknownValueException(
-                    PublicUtilMessages.missingEnumValue(input, enumClass, stringToEnum.keySet()), new AvailableValues(
-                            enumClass.getName() + " enum constants", stringToEnum));
+        {
+            String message = String.format("Input '%s' does not identify a value from enumerated type %s.", input,
+                    enumClass.getName());
+
+            throw new UnknownValueException(message, new AvailableValues(enumClass.getName() + " enum constants",
+                    stringToEnum));
+        }
 
         return result;
     }

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/conf/testng.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/conf/testng.xml?rev=1088376&r1=1088375&r2=1088376&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/conf/testng.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/conf/testng.xml Sun Apr  3 18:39:21 2011
@@ -1,13 +1,4 @@
 <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
-  <!--
-    Copyright 2007, 2008 The Apache Software Foundation 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.
-  -->
-
 <suite name="Tapestry IOC" annotations="1.5" verbose="2">
   <test name="Public APIs">
     <packages>
@@ -15,6 +6,7 @@
       <package name="org.apache.tapestry5.ioc.services"/>
       <package name="org.apache.tapestry5.ioc.test"/>
       <package name="org.apache.tapestry5.ioc.util"/>
+      <package name="org.apache.tapestry5.util"/>
     </packages>
   </test>
   <test name="Internals">

Copied: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/util/Stooge.java (from r1087941, tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/root/Stooge.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/util/Stooge.java?p2=tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/util/Stooge.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/root/Stooge.java&r1=1087941&r2=1088376&rev=1088376&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/root/Stooge.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/util/Stooge.java Sun Apr  3 18:39:21 2011
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry5.root;
+package org.apache.tapestry5.util;
 
 public enum Stooge
 {

Copied: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/util/StringToEnumCoercionTest.java (from r1087941, tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/util/StringToEnumCoercionTest.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/util/StringToEnumCoercionTest.java?p2=tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/util/StringToEnumCoercionTest.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/util/StringToEnumCoercionTest.java&r1=1087941&r2=1088376&rev=1088376&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/util/StringToEnumCoercionTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/util/StringToEnumCoercionTest.java Sun Apr  3 18:39:21 2011
@@ -1,4 +1,4 @@
-// Copyright 2007, 2010 The Apache Software Foundation
+// Copyright 2007, 2010, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -14,9 +14,6 @@
 
 package org.apache.tapestry5.util;
 
-import junit.framework.AssertionFailedError;
-
-import org.apache.tapestry5.root.Stooge;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
@@ -55,13 +52,13 @@ public class StringToEnumCoercionTest ex
         try
         {
             coercion.coerce("shemp");
-            throw new AssertionFailedError("unreachable");
+
+            fail("Unreachable");
         }
         catch (RuntimeException ex)
         {
-            assertEquals(
-                    ex.getMessage(),
-                    "Input \'shemp\' does not identify a value from enumerated type org.apache.tapestry5.root.Stooge. Available values: CURLY_JOE, LARRY, MOE.");
+            assertEquals(ex.getMessage(),
+                    "Input \'shemp\' does not identify a value from enumerated type org.apache.tapestry5.util.Stooge.");
         }
     }
 }