Author: violetagg
Date: Wed Jul 10 19:38:49 2013
New Revision: 1501935

URL: http://svn.apache.org/r1501935
Log:
Merged revision 1501719 from tomcat/trunk:
javax.el.ResourceBundleELResolver:
According to javadoc:
1. When creating FeatureDescriptors shortDescription must be empty string
2. isReadOnly returns true if the base is instance of ResourceBundle
Unit tests are added

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/javax/el/ResourceBundleELResolver.java
    tomcat/tc7.0.x/trunk/test/javax/el/TestResourceBundleELResolver.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1501719

Modified: tomcat/tc7.0.x/trunk/java/javax/el/ResourceBundleELResolver.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/javax/el/ResourceBundleELResolver.java?rev=1501935&r1=1501934&r2=1501935&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/javax/el/ResourceBundleELResolver.java (original)
+++ tomcat/tc7.0.x/trunk/java/javax/el/ResourceBundleELResolver.java Wed Jul 10 
19:38:49 2013
@@ -96,9 +96,10 @@ public class ResourceBundleELResolver ex
         
         if (base instanceof ResourceBundle) {
             context.setPropertyResolved(true);
+            return true;
         }
         
-        return true;
+        return false;
     }
 
     @Override
@@ -116,6 +117,7 @@ public class ResourceBundleELResolver ex
                 key = e.nextElement();
                 feat = new FeatureDescriptor();
                 feat.setDisplayName(key);
+                feat.setShortDescription("");
                 feat.setExpert(false);
                 feat.setHidden(false);
                 feat.setName(key);

Modified: tomcat/tc7.0.x/trunk/test/javax/el/TestResourceBundleELResolver.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/javax/el/TestResourceBundleELResolver.java?rev=1501935&r1=1501934&r2=1501935&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/javax/el/TestResourceBundleELResolver.java 
(original)
+++ tomcat/tc7.0.x/trunk/test/javax/el/TestResourceBundleELResolver.java Wed 
Jul 10 19:38:49 2013
@@ -16,7 +16,9 @@
  */
 package javax.el;
 
+import java.beans.FeatureDescriptor;
 import java.util.Enumeration;
+import java.util.Iterator;
 import java.util.ListResourceBundle;
 import java.util.ResourceBundle;
 
@@ -34,16 +36,15 @@ public class TestResourceBundleELResolve
 
         ResourceBundle rb = new TesterResourceBundle();
 
-        ValueExpression var =
-            factory.createValueExpression(rb, ResourceBundle.class);
+        ValueExpression var = factory.createValueExpression(rb,
+                ResourceBundle.class);
         context.getVariableMapper().setVariable("rb", var);
 
+        ValueExpression ve = factory.createValueExpression(context,
+                "${rb.keys}", String.class);
 
-        ValueExpression ve = factory.createValueExpression(
-                context, "${rb.keys}", String.class);
-
-        MethodExpression me = factory.createMethodExpression(
-                context, "${rb.getKeys()}", Enumeration.class, null);
+        MethodExpression me = factory.createMethodExpression(context,
+                "${rb.getKeys()}", Enumeration.class, null);
 
         // Ensure we are specification compliant
         String result1 = (String) ve.getValue(context);
@@ -62,17 +63,249 @@ public class TestResourceBundleELResolve
         Assert.assertFalse(e.hasMoreElements());
     }
 
+    /**
+     * Tests that a null context results in an NPE as per EL Javadoc.
+     */
+    @Test(expected = NullPointerException.class)
+    public void testGetValue01() {
+        ResourceBundleELResolver resolver = new ResourceBundleELResolver();
+        resolver.getValue(null, new Object(), new Object());
+    }
+
+    /**
+     * Tests that a valid property is not resolved if base is not
+     * ResourceBundle.
+     */
+    @Test
+    public void testGetValue02() {
+        doNegativeTest(new Object(), new Object(), MethodUnderTest.GET_VALUE,
+                true);
+    }
+
+    /**
+     * Tests that a valid property is resolved.
+     */
+    @Test
+    public void testGetValue03() {
+        ResourceBundleELResolver resolver = new ResourceBundleELResolver();
+        ELContext context = new ELContextImpl();
+
+        ResourceBundle resourceBundle = new TesterResourceBundle();
+        Object result = resolver.getValue(context, resourceBundle, "key1");
+
+        Assert.assertEquals("value1", result);
+        Assert.assertTrue(context.isPropertyResolved());
+
+        result = resolver.getValue(context, resourceBundle, "unknown-key");
+
+        Assert.assertEquals("???unknown-key???", result);
+        Assert.assertTrue(context.isPropertyResolved());
+
+        result = resolver.getValue(context, resourceBundle, null);
+
+        Assert.assertNull(result);
+        Assert.assertTrue(context.isPropertyResolved());
+    }
+
+    /**
+     * Tests that a null context results in an NPE as per EL Javadoc.
+     */
+    @Test(expected = NullPointerException.class)
+    public void testGetType01() {
+        ResourceBundleELResolver resolver = new ResourceBundleELResolver();
+        resolver.getType(null, new Object(), new Object());
+    }
+
+    /**
+     * Tests that a valid property is not resolved if base is not
+     * ResourceBundle.
+     */
+    @Test
+    public void testGetType02() {
+        doNegativeTest(new Object(), new Object(), MethodUnderTest.GET_TYPE,
+                true);
+    }
+
+    /**
+     * Tests that null will be returned when base is ResourceBundle. Checks 
that
+     * the propertyResolved is true.
+     */
+    @Test
+    public void testGetType03() {
+        ResourceBundleELResolver resolver = new ResourceBundleELResolver();
+        ELContext context = new ELContextImpl();
+
+        ResourceBundle resourceBundle = new TesterResourceBundle();
+        Class<?> result = resolver.getType(context, resourceBundle, "key1");
+
+        Assert.assertNull(result);
+        Assert.assertTrue(context.isPropertyResolved());
+    }
+
+    /**
+     * Tests that a null context results in an NPE as per EL Javadoc.
+     */
+    @Test(expected = NullPointerException.class)
+    public void testSetValue01() {
+        ResourceBundleELResolver resolver = new ResourceBundleELResolver();
+        resolver.setValue(null, new Object(), new Object(), new Object());
+    }
+
+    /**
+     * Tests that a valid property is not set if base is not ResourceBundle.
+     */
+    @Test
+    public void testSetValue02() {
+        doNegativeTest(new Object(), new Object(), MethodUnderTest.SET_VALUE,
+                false);
+    }
+
+    /**
+     * Tests that an exception is thrown because the resolver is read only.
+     */
+    @Test(expected = PropertyNotWritableException.class)
+    public void testSetValue03() {
+        ResourceBundleELResolver resolver = new ResourceBundleELResolver();
+        ELContext context = new ELContextImpl();
+
+        ResourceBundle resourceBundle = new TesterResourceBundle();
+        resolver.setValue(context, resourceBundle, new Object(), new Object());
+    }
+
+    /**
+     * Tests that a null context results in an NPE as per EL Javadoc.
+     */
+    @Test(expected = NullPointerException.class)
+    public void testIsReadOnly01() {
+        ResourceBundleELResolver resolver = new ResourceBundleELResolver();
+        resolver.isReadOnly(null, new Object(), new Object());
+    }
+
+    /**
+     * Tests that the propertyResolved is false and readOnly is false if base 
is
+     * not ResourceBundle.
+     */
+    @Test
+    public void testIsReadOnly02() {
+        ResourceBundleELResolver resolver = new ResourceBundleELResolver();
+        ELContext context = new ELContextImpl();
+
+        boolean result = resolver.isReadOnly(context, new Object(),
+                new Object());
+
+        Assert.assertFalse(result);
+        Assert.assertFalse(context.isPropertyResolved());
+    }
+
+    /**
+     * Tests that the readOnly is true always when the base is ResourceBundle.
+     */
+    @Test
+    public void testIsReadOnly03() {
+        ResourceBundleELResolver resolver = new ResourceBundleELResolver();
+        ELContext context = new ELContextImpl();
+
+        ResourceBundle resourceBundle = new TesterResourceBundle();
+        boolean result = resolver.isReadOnly(context, resourceBundle,
+                new Object());
+
+        Assert.assertTrue(result);
+        Assert.assertTrue(context.isPropertyResolved());
+    }
+
+    /**
+     * Tests that a valid FeatureDescriptors are not returned if base is not
+     * ResourceBundle.
+     */
+    @Test
+    public void testGetFeatureDescriptors01() {
+        ResourceBundleELResolver resolver = new ResourceBundleELResolver();
+        ELContext context = new ELContextImpl();
+
+        Iterator<FeatureDescriptor> result = resolver.getFeatureDescriptors(
+                context, new Object());
+
+        Assert.assertNull(result);
+    }
+
+    /**
+     * Tests that a valid FeatureDescriptors are returned.
+     */
+    @Test
+    public void testGetFeatureDescriptors02() {
+        ResourceBundleELResolver resolver = new ResourceBundleELResolver();
+        ELContext context = new ELContextImpl();
+
+        ResourceBundle resourceBundle = new TesterResourceBundle(
+                new Object[][] { { "key", "value" } });
+        Iterator<FeatureDescriptor> result = resolver.getFeatureDescriptors(
+                context, resourceBundle);
+
+        while (result.hasNext()) {
+            FeatureDescriptor featureDescriptor = result.next();
+            Assert.assertEquals("key", featureDescriptor.getDisplayName());
+            Assert.assertEquals("key", featureDescriptor.getName());
+            Assert.assertEquals("", featureDescriptor.getShortDescription());
+            Assert.assertFalse(featureDescriptor.isExpert());
+            Assert.assertFalse(featureDescriptor.isHidden());
+            Assert.assertTrue(featureDescriptor.isPreferred());
+            Assert.assertEquals(String.class,
+                    featureDescriptor.getValue(ELResolver.TYPE));
+            Assert.assertEquals(Boolean.TRUE, featureDescriptor
+                    .getValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME));
+        }
+    }
 
     private static class TesterResourceBundle extends ListResourceBundle {
 
+        public TesterResourceBundle() {
+            this(new Object[][] { { "key1", "value1" }, { "key2", "value2" } 
});
+        }
+
+        public TesterResourceBundle(Object[][] contents) {
+            this.contents = contents;
+        }
+
         @Override
         protected Object[][] getContents() {
             return contents;
         }
 
-        private static final Object[][] contents = {
-            {"key1","value1"},
-            {"key2","value2"}
-        };
+        private Object[][] contents;
+    }
+
+    private void doNegativeTest(Object base, Object trigger,
+            MethodUnderTest method, boolean checkResult) {
+        ResourceBundleELResolver resolver = new ResourceBundleELResolver();
+        ELContext context = new ELContextImpl();
+
+        Object result = null;
+        switch (method) {
+        case GET_VALUE: {
+            result = resolver.getValue(context, base, trigger);
+            break;
+        }
+        case SET_VALUE: {
+            resolver.setValue(context, base, trigger, new Object());
+            break;
+        }
+        case GET_TYPE: {
+            result = resolver.getType(context, base, trigger);
+            break;
+        }
+        default: {
+            // Should never happen
+            Assert.fail("Missing case for method");
+        }
+        }
+
+        if (checkResult) {
+            Assert.assertNull(result);
+        }
+        Assert.assertFalse(context.isPropertyResolved());
+    }
+
+    private static enum MethodUnderTest {
+        GET_VALUE, SET_VALUE, GET_TYPE
     }
 }

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1501935&r1=1501934&r2=1501935&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Wed Jul 10 19:38:49 2013
@@ -93,6 +93,15 @@
         a named attribute <code>ELResolver.RESOLVABLE_AT_DESIGN_TIME</code> -
         true. (violetagg)
       </fix>
+      <fix>
+        Ensure that <code>FeatureDescriptor</code> objects returned by
+        
<code>javax.el.ResourceBundleELResolver.getFeatureDescriptors(ELContext,Object)</code>
+        will be created with a correct <code>shortDescription</code> - an empty
+        string.
+        
<code>javax.el.ResourceBundleELResolver.isReadOnly(ELContext,Object,Object)</code>
+        returns true if the base object is an instance of ResourceBundle.
+        (violetagg)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Cluster">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to