You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2012/10/12 20:41:55 UTC

git commit: DELTASPIKE-281 add unit test and fix some bugs in the locale mechanism

Updated Branches:
  refs/heads/master a092dabf5 -> 9682dce0f


DELTASPIKE-281 add unit test and fix some bugs in the locale mechanism


Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/9682dce0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/9682dce0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/9682dce0

Branch: refs/heads/master
Commit: 9682dce0f487902ea1bf607641c502dc77ed0506
Parents: a092dab
Author: Mark Struberg <st...@apache.org>
Authored: Fri Oct 12 20:40:49 2012 +0200
Committer: Mark Struberg <st...@apache.org>
Committed: Fri Oct 12 20:40:49 2012 +0200

----------------------------------------------------------------------
 .../core/impl/message/DefaultMessageResolver.java  |    5 +-
 .../test/jsf/impl/message/JsfMessageTest.java      |   36 ++++++++++++++-
 .../impl/message/beans/JsfMessageBackingBean.java  |   15 +++++-
 .../jsfMessageTest/UserMessage.properties          |   25 ----------
 .../jsfMessageTest/UserMessage_de.properties       |   25 ++++++++++
 .../jsfMessageTest/UserMessage_en.properties       |   25 ++++++++++
 .../src/test/resources/jsfMessageTest/page.xhtml   |    4 +-
 7 files changed, 102 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/9682dce0/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/DefaultMessageResolver.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/DefaultMessageResolver.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/DefaultMessageResolver.java
index 3791467..779914d 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/DefaultMessageResolver.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/DefaultMessageResolver.java
@@ -59,6 +59,8 @@ public class DefaultMessageResolver implements MessageResolver
 
             Iterator<String> messageSourceIterator = messageSources.iterator();
 
+            Locale locale = messageContext.getLocale();
+
             String currentMessageSource;
             while (messageSourceIterator.hasNext())
             {
@@ -66,7 +68,6 @@ public class DefaultMessageResolver implements MessageResolver
 
                 try
                 {
-                    Locale locale = messageContext.getLocale();
                     ResourceBundle messageBundle = PropertyFileUtils.getResourceBundle(currentMessageSource, locale);
 
                     if (category != null && category.length() > 0)
@@ -78,7 +79,7 @@ public class DefaultMessageResolver implements MessageResolver
                         catch (MissingResourceException e)
                         {
                             // we fallback on the version without the category
-                            messageBundle.getString(resourceKey);
+                            return messageBundle.getString(resourceKey);
                         }
                     }
 

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/9682dce0/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/JsfMessageTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/JsfMessageTest.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/JsfMessageTest.java
index b22b36a..9429e7e 100644
--- a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/JsfMessageTest.java
+++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/JsfMessageTest.java
@@ -62,7 +62,8 @@ public class JsfMessageTest
         return ShrinkWrap
                 .create(WebArchive.class, "jsfMessageTest.war")
                 .addPackage(JsfMessageBackingBean.class.getPackage())
-                .addAsResource("jsfMessageTest/UserMessage.properties")
+                .addAsResource("jsfMessageTest/UserMessage_en.properties")
+                .addAsResource("jsfMessageTest/UserMessage_de.properties")
                 .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndJsfArchive())
                 .addAsWebInfResource("default/WEB-INF/web.xml", "web.xml")
                 .addAsWebResource("jsfMessageTest/page.xhtml", "page.xhtml")
@@ -72,10 +73,15 @@ public class JsfMessageTest
 
     @Test
     @RunAsClient
-    public void testViewScopedContext() throws Exception
+    public void testEnglishMessages() throws Exception
     {
         driver.get(new URL(contextPath, "page.xhtml").toString());
 
+        //X comment this in if you like to debug the server
+        //X I've already reported ARQGRA-213 for it
+        //X System.out.println("contextpath= " + contextPath);
+        //X Thread.sleep(600000L);
+
         // check the JSF FacesMessages
         Assert.assertNotNull(ExpectedConditions.presenceOfElementLocated(By.xpath("id('messages')")).apply(driver));
 
@@ -96,4 +102,30 @@ public class JsfMessageTest
                 By.id("test:valueOutput"), "a simple message without a param.").apply(driver));
     }
 
+    @Test
+    @RunAsClient
+    public void testGermanMessages() throws Exception
+    {
+        driver.get(new URL(contextPath, "page.xhtml?lang=de").toString());
+
+        // check the JSF FacesMessages
+        Assert.assertNotNull(ExpectedConditions.presenceOfElementLocated(By.xpath("id('messages')")).apply(driver));
+
+        Assert.assertTrue(ExpectedConditions.textToBePresentInElement(
+                By.xpath("id('messages')/ul/li[1]"), "Nachricht mit Details warnInfo!").apply(driver));
+
+        Assert.assertTrue(ExpectedConditions.textToBePresentInElement(
+                By.xpath("id('messages')/ul/li[2]"), "Nachricht ohne Details aber mit Parameter errorInfo.").apply(driver));
+
+        Assert.assertTrue(ExpectedConditions.textToBePresentInElement(
+                By.xpath("id('messages')/ul/li[3]"), "Einfache Nachricht ohne Parameter.").apply(driver));
+
+        Assert.assertTrue(ExpectedConditions.textToBePresentInElement(
+                By.xpath("id('messages')/ul/li[4]"), "Einfache Nachricht mit String Parameter fatalInfo.").apply(driver));
+
+        // check the free message usage
+        Assert.assertTrue(ExpectedConditions.textToBePresentInElement(
+                By.id("test:valueOutput"), "Einfache Nachricht ohne Parameter.").apply(driver));
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/9682dce0/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/beans/JsfMessageBackingBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/beans/JsfMessageBackingBean.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/beans/JsfMessageBackingBean.java
index 085591f..254e273 100644
--- a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/beans/JsfMessageBackingBean.java
+++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/beans/JsfMessageBackingBean.java
@@ -18,12 +18,9 @@
 */
 package org.apache.deltaspike.test.jsf.impl.message.beans;
 
-import javax.annotation.PostConstruct;
 import javax.enterprise.context.RequestScoped;
-import javax.faces.bean.ViewScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
-import java.io.Serializable;
 
 import org.apache.deltaspike.jsf.message.JsfMessage;
 
@@ -37,6 +34,8 @@ public class JsfMessageBackingBean
     @Inject
     private JsfMessage<UserMessage> msg;
 
+    private String locale = "en";
+
 
     public void init()
     {
@@ -50,4 +49,14 @@ public class JsfMessageBackingBean
     {
         return msg.get().simpleMessageNoParam();
     }
+
+    public String getLocale()
+    {
+        return locale;
+    }
+
+    public void setLocale(String locale)
+    {
+        this.locale = locale;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/9682dce0/deltaspike/modules/jsf/impl/src/test/resources/jsfMessageTest/UserMessage.properties
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/resources/jsfMessageTest/UserMessage.properties b/deltaspike/modules/jsf/impl/src/test/resources/jsfMessageTest/UserMessage.properties
deleted file mode 100644
index bfdbed9..0000000
--- a/deltaspike/modules/jsf/impl/src/test/resources/jsfMessageTest/UserMessage.properties
+++ /dev/null
@@ -1,25 +0,0 @@
-#Licensed to the Apache Software Foundation (ASF) under one
-#or more contributor license agreements.  See the NOTICE file
-#distributed with this work for additional information
-#regarding copyright ownership.  The ASF licenses this file
-#to you 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.
-
-messageWithDetail = message with details %s!
-messageWithDetail.detail = message with loooong and very specific details %s!
-
-messageWithoutDetail = message without detail but parameter %s.
-
-simpleMessageWithParam = simple message with a string param %s.
-
-simpleMessageNoParam = a simple message without a param.

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/9682dce0/deltaspike/modules/jsf/impl/src/test/resources/jsfMessageTest/UserMessage_de.properties
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/resources/jsfMessageTest/UserMessage_de.properties b/deltaspike/modules/jsf/impl/src/test/resources/jsfMessageTest/UserMessage_de.properties
new file mode 100644
index 0000000..07d26a7
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/test/resources/jsfMessageTest/UserMessage_de.properties
@@ -0,0 +1,25 @@
+#Licensed to the Apache Software Foundation (ASF) under one
+#or more contributor license agreements.  See the NOTICE file
+#distributed with this work for additional information
+#regarding copyright ownership.  The ASF licenses this file
+#to you 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.
+
+messageWithDetail = Nachricht mit Details %s!
+messageWithDetail.detail = Nachricht mit sehr langen und genauen Details %s!
+
+messageWithoutDetail = Nachricht ohne Details aber mit Parameter %s.
+
+simpleMessageWithParam = Einfache Nachricht mit String Parameter %s.
+
+simpleMessageNoParam = Einfache Nachricht ohne Parameter.

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/9682dce0/deltaspike/modules/jsf/impl/src/test/resources/jsfMessageTest/UserMessage_en.properties
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/resources/jsfMessageTest/UserMessage_en.properties b/deltaspike/modules/jsf/impl/src/test/resources/jsfMessageTest/UserMessage_en.properties
new file mode 100644
index 0000000..bfdbed9
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/test/resources/jsfMessageTest/UserMessage_en.properties
@@ -0,0 +1,25 @@
+#Licensed to the Apache Software Foundation (ASF) under one
+#or more contributor license agreements.  See the NOTICE file
+#distributed with this work for additional information
+#regarding copyright ownership.  The ASF licenses this file
+#to you 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.
+
+messageWithDetail = message with details %s!
+messageWithDetail.detail = message with loooong and very specific details %s!
+
+messageWithoutDetail = message without detail but parameter %s.
+
+simpleMessageWithParam = simple message with a string param %s.
+
+simpleMessageNoParam = a simple message without a param.

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/9682dce0/deltaspike/modules/jsf/impl/src/test/resources/jsfMessageTest/page.xhtml
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/resources/jsfMessageTest/page.xhtml b/deltaspike/modules/jsf/impl/src/test/resources/jsfMessageTest/page.xhtml
index 1e21af2..4137cc7 100644
--- a/deltaspike/modules/jsf/impl/src/test/resources/jsfMessageTest/page.xhtml
+++ b/deltaspike/modules/jsf/impl/src/test/resources/jsfMessageTest/page.xhtml
@@ -25,8 +25,9 @@
       xmlns:ui="http://java.sun.com/jsf/facelets">
 
 <body>
-<f:view>
+<f:view locale="#{jsfMessageBackingBean.locale}">
     <f:metadata>
+        <f:viewParam name="lang" id="lang" value="#{jsfMessageBackingBean.locale}"/>
         <f:event type="javax.faces.event.PreRenderViewEvent" listener="#{jsfMessageBackingBean.init}"/>
     </f:metadata>
     <div>
@@ -39,6 +40,7 @@
         <h:outputLabel for="valueOutput" value="the message:"/>
         <h:outputText id="valueOutput" value="#{jsfMessageBackingBean.someMessage}"/>
         <br/>
+
     </h:form>
     </div>
 </f:view>