[ 
https://issues.apache.org/struts/browse/SHALE-485?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=43500#action_43500
 ] 

Tim Kroeger commented on SHALE-485:
-----------------------------------

That means, MockApplication12.addResourceBundle() should add the name and 
baseName, not the name and the resource bundle since it is dependent on the 
locale possibly at request time. -> addResourceBundle(String name, String 
baseName) {}

> ResourceBundle lookup failure in MockApplication12
> --------------------------------------------------
>
>                 Key: SHALE-485
>                 URL: https://issues.apache.org/struts/browse/SHALE-485
>             Project: Shale
>          Issue Type: Bug
>          Components: Test
>    Affects Versions: 1.0.4
>         Environment: Java 5, JSF 1.2, i686 GNU/Linux
>            Reporter: Tim Kroeger
>
> MockApplication12.getResourceBundle(FacesContext context, String name) is 
> intended to lookup the resource bundle's base name prior to requesting the 
> resource via ResourceBundle.getBundle(name, locale). In the current 
> implementation it tries to lookup the name of the resource registered with 
> the application, which is wrong. Consider a resource bundle added via
>       ResourceBundle bundle = ResourceBundle.getBundle("foo.bar.resource", 
> new Locale("de", "DE"));
>       ((MockApplication12) application).addResourceBundle("fooBarResource", 
> bundle);
> and e.g. a validator you want to test which composes a new localized 
> FacesMessage by doing
>       context.getApplication().getResourceBundle(context, 
> "fooBarResource").getString("message");
> which simulates what would happen in an application where you configured your 
> resource bundles via faces-config.xml.
> This will throw a MissingResourceException since
>     public ResourceBundle getResourceBundle(FacesContext context, String 
> name) {
>         if ((context == null) || (name == null)) {
>             throw new NullPointerException();
>         }
>         Locale locale = null;
>         UIViewRoot viewRoot = context.getViewRoot();
>         if (viewRoot != null) {
>             locale = viewRoot.getLocale();
>         }
>         if (locale == null) {
>             locale = Locale.getDefault();
>         }
>         return ResourceBundle.getBundle(name, locale);
>     }
> tries to lookup "fooBarResource" with it's classLoader. Instead of that, one 
> should either do something like:
>     public ResourceBundle getResourceBundle(FacesContext context, String 
> name) {
>         if ((context == null) || (name == null)) {
>             throw new NullPointerException();
>         }
>         if (!bundles.containsKey(name)) {
>             return null;
>         }
>         Locale locale = null;
>         UIViewRoot viewRoot = context.getViewRoot();
>         if (viewRoot != null) {
>             locale = viewRoot.getLocale();
>         }
>         if (locale == null) {
>             locale = Locale.getDefault();
>         }
>         return bundles.get(name);
>     }
> which completely drops any locale context but at least returns a resource 
> bundle, that was added with the corresponding key
> OR
> one could go ahead and implement a solution, where only the mapping 'name -> 
> baseName' is stored in a map instead of mappings to ResourceBundles, so 
> MockApplication12.getResourceBundle can lookup the baseName via the provided 
> name parameter as key to the bundles Map property and then utilize 
> ResourceBundle.getBundle() to lookup the bundle with the desired locale. That 
> at least is, what Sun does in it's 
> com.sun.faces.application.ApplicationAssociate which is used by 
> com.sun.faces.application.ApplicationImpl.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to