2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to you under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shale.usecases.locale;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  import java.util.Locale;
23  
24  import junit.framework.Test;
25  import junit.framework.TestSuite;
26  
27  import org.apache.shale.test.base.AbstractViewControllerTestCase;
28  
29  /***
30   * <p>Test case for the {@link Select} ViewController implementation.</p>
31   *
32   * $Id: SelectTestCase.java 464373 2006-10-16 04:21:54Z rahul $
33   */
34  public class SelectTestCase extends AbstractViewControllerTestCase {
35  
36  
37      // ------------------------------------------------------------ Constructors
38  
39  
40      // Construct a new instance of this test case.
41      public SelectTestCase(String name) {
42          super(name);
43      }
44  
45  
46      // ---------------------------------------------------- Overall Test Methods
47  
48  
49      // Set up instance variables required by this test case.
50      protected void setUp() throws Exception {
51  
52          super.setUp();
53  
54          // Configure the supported locales for this application
55          List list = new ArrayList();
56          list.add(new Locale("en"));
57          list.add(new Locale("fr"));
58          list.add(new Locale("de"));
59          list.add(new Locale("es"));
60          application.setSupportedLocales(list);
61  
62          // Construct a new ViewController instance
63          vc = new Select();
64  
65      }
66  
67      // Return the tests included in this test case.
68      public static Test suite() {
69  
70          return (new TestSuite(SelectTestCase.class));
71  
72      }
73  
74  
75      // Tear down instance variables required by this test case.
76      protected void tearDown() throws Exception {
77  
78          vc = null;
79          super.tearDown();
80  
81      }
82  
83  
84      // ------------------------------------------------------ Instance Variables
85  
86  
87      // The instance to be tested
88      Select vc = null;
89  
90  
91      // ------------------------------------------------------------ Test Methods
92  
93  
94      // Test behavior of prerender() method
95      public void testPrerender() {
96  
97          Locale locale = new Locale("en");
98          facesContext.getViewRoot().setLocale(locale);
99          vc.init();
100         vc.prerender();
101         assertEquals(locale.toString(), vc.getLocale());
102 
103     }
104 
105 
106     // Test a pristine instance of {@link Select}
107     public void testPristine() {
108 
109         assertNull(vc.getLocale());
110 
111     }
112 
113 
114     // Test behavior of select() with an invalid value
115     public void testSelectInvalid() {
116 
117         Locale locale = new Locale("en");
118         facesContext.getViewRoot().setLocale(locale);
119         vc.init();
120         vc.preprocess();
121         vc.setLocale("it");
122         String result = vc.select();
123         assertEquals(Select.FAILURE, result);
124         checkMessageCount(1);
125         assertEquals(locale, facesContext.getViewRoot().getLocale());
126 
127     }
128 
129 
130     // Test behavior of select() with no input value at all
131     public void testSelectNull() {
132 
133         Locale locale = new Locale("en");
134         facesContext.getViewRoot().setLocale(locale);
135         vc.init();
136         vc.preprocess();
137         vc.setLocale(null);
138         String result = vc.select();
139         assertNull(result);
140         checkMessageCount(1);
141         assertEquals(locale, facesContext.getViewRoot().getLocale());
142 
143     }
144 
145 
146     // Test behavior of select() with a valid value
147     public void testSelectValid() {
148 
149         Locale locale = new Locale("en");
150         facesContext.getViewRoot().setLocale(locale);
151         vc.init();
152         vc.preprocess();
153         vc.setLocale("de");
154         String result = vc.select();
155         assertEquals(result, Select.SUCCESS);
156         checkMessageCount(0);
157         assertEquals(new Locale("de"), facesContext.getViewRoot().getLocale());
158 
159     }
160 
161 
162 }