6 Replies Latest reply on Mar 11, 2008 12:40 PM by Stan Silvert

    Testing internationalized sites

    Bartosz Jablonski Newbie

      Hi,

      I wanted to test if I display correct messages on a page regarding action taken by a user. I use polish letters and therefore I have some problems with it. As far as I know pages are encoded in UTF-8 standard in JSF by default . I load my messages from bundles (properties file) and they are displayed correctly in the browser. If you check the source of the page I can see polish letters encoded with UTF-8 i.e.

      <span id="loginForm:passwordOut">Has'an encoded UTF-8 letter goes here'o:</span>
      

      Of course messages loaded from bundle are decoded correctly ( I see them in debug mode ;) )

      The problem appears when I want to check if a message loaded from the bundle message is equal to the message in html element. My test scenario: I send action to the server and than I want to get response and compare text within elements with a given text from Bundle Messages. See code below:
      public void testWrongLogin() throws MalformedURLException, IOException, SAXException{
       JSFClientSession client = new JSFClientSession("/pages/login/signin.jsf");
       RichFacesClient rfClient = new RichFacesClient(client);
       JSFServerSession server = new JSFServerSession(client);
      
       //set a wrong login
       client.setParameter("loginForm:loginIn", "wrongLogin");
       //if the login is wrong password doesn't matter
       client.setParameter("loginForm:passwordIn", "passwordNotImportant");
       rfClient.ajaxSubmit("loginForm:loginAction");
       String wrongLoginMessage = BundleUtil.getMessageResourceString("loginMsg", "signin_wrongLoginOrPassword", null, server.getFacesContext());
       WebResponse webResponse = client.getWebResponse();
       HTMLElement element = webResponse.getElementWithID("loginForm:loginErrorPanel");
       assertEquals(wrongLoginMessage, element.getText());
       }
      

      In that case as a text within checked element I get text with '?' instead of polish letters. Why these text isn't decoded correctly into String in Java. Do you know what can be the problem? Any workaround?

      P.s. If I check encoding in browsers (IE, Firefox) it's still UTF-8.

      Thanks for help
      jabko


        • 1. Re: Testing internationalized sites
          Stan Silvert Master

          Have you tried setting the Accept-Language and Accept-Charset headers on your WebConversation?

          WebConversation webConv = WebConversationFactory.makeWebConversation();
          webConv.setHeaderField("Accept-Language", "pl");
          webConv.setHeaderField("Accept-Charset", "ISO-8859-2");
          JSFClientSession client = new JSFClientSession (webConv, "/pages/login/signin.jsf");


          Please let me know if that works.

          Also, you can check your messages at the server side with JSFServerSession.getFacesMessages(). This might be a more reliable test.

          Stan

          • 2. Re: Testing internationalized sites
            Bartosz Jablonski Newbie

            Hi,

            I think problem is somewhere else. I debug a little and checked how my response looks like when I do first request to the server. I checked of course client after this line of code:

            JSFClientSession client = new JSFClientSession("/pages/login/signin.jsf");
            

            JSFClientSession object contains HttpWebResponse object. In the object I can see properly encoded polish letters in UTF-8 but when I do ajaxSubmit on RichFacesClient
            rfClient.ajaxSubmit("loginForm:loginAction");
             String wrongLoginMessage = BundleUtil.getMessageResourceString("loginMsg", "signin_wrongLoginOrPassword", null, server.getFacesContext());
             WebResponse webResponse = client.getWebResponse();
            

            webResponse object contains already badly encoded polish letters. I can conclude that it's a bug probably while executing ajaxSubmit and than creating WebResponse object.


            Any thoughts about this?


            Thanks
            Bart

            • 3. Re: Testing internationalized sites
              Stan Silvert Master

              So did you try my earlier suggestion? If so, was there any affect at all?

              It would be great if you could provide me with a simple example. I'd like to try this out myself.

              Thanks,

              Stan

              • 4. Re: Testing internationalized sites
                Bartosz Jablonski Newbie

                Hi,

                I did try your suggestion but id didn't really help.

                I'll send a simple example later on.

                Bart

                • 5. Re: Testing internationalized sites
                  Stan Silvert Master

                  Bart,

                  I got your sample working and it looks like a bug in the JSFUnit RichFaces code. I will need to narrow it down some more as soon as I get a little free time. Hopefully, I'll have the problem fixed in the next few days.

                  Stan

                  • 6. Re: Testing internationalized sites
                    Stan Silvert Master

                    Hi Bart,

                    Sorry this one took so long. It was a tough one to track down.

                    I have committed a fix that you can try out if you build JSFUnit from SVN.

                    In your test, you will need to set the Content-Type like this:

                    WebConversation webConv = WebConversationFactory.makeWebConversation();
                    webConv.setHeaderField("Content-Type", "text/html;charset=ISO-8859-2");
                    JSFClientSession client = new JSFClientSession (webConv, "/foo.jsf");


                    For tracking purposes, here is the jira task: http://jira.jboss.com/jira/browse/JSFUNIT-79

                    Regards,

                    Stan