KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > displaytag > jsptests > I18nPropertiesTest


1 package org.displaytag.jsptests;
2
3 import org.displaytag.test.DisplaytagCase;
4
5 import com.meterware.httpunit.GetMethodWebRequest;
6 import com.meterware.httpunit.WebRequest;
7 import com.meterware.httpunit.WebResponse;
8
9
10 /**
11  * Verify that the TableProperties will show values from the proper locale.
12  * @author rapruitt
13  * @version $Revision: 707 $ ($Author: fgiust $)
14  */

15 public class I18nPropertiesTest extends DisplaytagCase
16 {
17
18     /**
19      * No results for an en locale.
20      */

21     private static final String JavaDoc MSG_DEFAULT = "There are no results.";
22
23     /**
24      * No results for an it locale.
25      */

26     private static final String JavaDoc MSG_IT = "Non ci sono risultati.";
27
28     /**
29      * @see org.displaytag.test.DisplaytagCase#getJspName()
30      */

31     public String JavaDoc getJspName()
32     {
33         return "i18nProperties.jsp";
34     }
35
36     /**
37      * Check that the "no results" property is loaded from the correct locale file.
38      * @param jspName jsp name, with full path
39      * @throws Exception any axception thrown during test.
40      */

41     public void doTest(String JavaDoc jspName) throws Exception JavaDoc
42     {
43
44         WebRequest request = new GetMethodWebRequest(jspName);
45         request.setHeaderField("Accept-Language", "en-us,en;q=0.5");
46
47         WebResponse response = runner.getResponse(request);
48
49         if (log.isDebugEnabled())
50         {
51             log.debug("RESPONSE: " + response.getText());
52         }
53
54         assertTrue("Expected message\"" + MSG_DEFAULT + "\" has not been found in response with locale en", response
55             .getText()
56             .indexOf(MSG_DEFAULT) > -1);
57         assertTrue("Unexpected message\"" + MSG_IT + "\" has been found in response with locale en", response
58             .getText()
59             .indexOf(MSG_IT) == -1);
60
61         // Now, with an Italian locale.
62
request = new GetMethodWebRequest(jspName);
63         request.setHeaderField("Accept-Language", "it-it,it;q=0.5");
64
65         response = runner.getResponse(request);
66
67         if (log.isDebugEnabled())
68         {
69             log.debug("RESPONSE: " + response.getText());
70         }
71
72         assertTrue("Expected message\"" + MSG_IT + "\" has not been found in response with locale it", response
73             .getText()
74             .indexOf(MSG_IT) > -1);
75         assertTrue("Unexpected message\"" + MSG_DEFAULT + "\" has been found in response with locale it", response
76             .getText()
77             .indexOf(MSG_DEFAULT) == -1);
78     }
79 }
80
Popular Tags