01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.integration.pagelevel;
16:
17: import java.util.Locale;
18:
19: import org.apache.tapestry.dom.Document;
20: import org.apache.tapestry.test.PageTester;
21: import org.testng.Assert;
22: import org.testng.annotations.AfterMethod;
23: import org.testng.annotations.BeforeMethod;
24: import org.testng.annotations.Test;
25:
26: public class LocaleTest extends Assert {
27: private PageTester _tester;
28:
29: @Test
30: public void no_preferred_language() {
31: Document doc = _tester.renderPage("TestPageForLocale");
32: assertEquals(doc.getElementById("id1").getChildText(),
33: "English page");
34: }
35:
36: @Test
37: public void prefer_canada_french() {
38: _tester.setPreferedLanguage(Locale.CANADA_FRENCH);
39: Document doc = _tester.renderPage("TestPageForLocale");
40: assertEquals(doc.getElementById("id1").getChildText(),
41: "French page");
42: }
43:
44: @Test
45: public void change_language_in_browser() {
46: Document doc = _tester.renderPage("TestPageForLocale");
47: assertEquals(doc.getElementById("id1").getChildText(),
48: "English page");
49: _tester.setPreferedLanguage(Locale.CANADA_FRENCH);
50: doc = _tester.renderPage("TestPageForLocale");
51: assertEquals(doc.getElementById("id1").getChildText(),
52: "French page");
53: }
54:
55: @Test
56: public void persist_locale() {
57: Document doc = _tester.renderPage("TestPageForLocale");
58: doc = _tester.clickLink(doc.getElementById("changeLocale"));
59: assertEquals(doc.getElementById("id1").getChildText(),
60: "French page");
61: }
62:
63: @BeforeMethod
64: public void before() {
65: String appPackage = "org.apache.tapestry.integration.app2";
66: // LocaleAppModule.java has configured support for a certain locales.
67: String appName = "LocaleApp";
68: _tester = new PageTester(appPackage, appName);
69: }
70:
71: @AfterMethod
72: public void after() {
73: if (_tester != null) {
74: _tester.shutdown();
75: }
76: }
77: }
|