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.lookup;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  import java.util.Locale;
23  
24  import javax.faces.el.ValueBinding;
25  import javax.faces.model.SelectItem;
26  
27  import junit.framework.Test;
28  import junit.framework.TestSuite;
29  
30  import org.apache.shale.test.base.AbstractViewControllerTestCase;
31  import org.apache.shale.usecases.view.Domains;
32  
33  public class ListLocalesTestCase extends AbstractViewControllerTestCase {
34  
35  	
36      // Construct a new instance of this test case.
37      public ListLocalesTestCase(String name) {
38          super(name);
39      }
40  
41  	
42      // Return the tests included in this test case.
43      public static Test suite() {
44  
45          return (new TestSuite(ListLocalesTestCase.class));
46  
47      }
48  
49  	// View controller to test</p>
50  	private ListLocales vc = null;
51  	
52  	 // Setup the test by simulating support for several locales
53  	 // that would be configured declaratively in the faces config. 
54  	 // Then cache a Domains object in context.
55  	protected void setUp() throws Exception {
56  		super.setUp();
57  
58          // Configure the supported locales for this application
59          List list = new ArrayList();
60          list.add(new Locale("en"));
61          list.add(new Locale("fr"));
62          list.add(new Locale("de"));
63          list.add(new Locale("es"));
64          application.setSupportedLocales(list);
65  
66  		// simulate a managed bean
67  		ValueBinding vb = application.createValueBinding("domains");
68  		vb.setValue(facesContext, new Domains());
69  		
70  		vc = new ListLocales();
71  	
72  	}
73  
74  	 //Tear Down the test
75  	protected void tearDown() throws Exception {
76  		super.tearDown();
77  	    vc = null;
78  	}
79  	
80      // Test behavior of prerender() method
81      public void testPrerender() {
82  
83          Locale locale = new Locale("en");
84          facesContext.getViewRoot().setLocale(locale);
85          vc.init();
86          vc.prerender();
87  
88  		SelectItem[] locales = vc.getSupportedLocales();
89  		assertEquals(locales.length, 4);
90  
91  		
92      }
93  
94      // Test behavior of destroy() method
95      public void testDestroy() {
96          vc.destroy();
97  		assertEquals(vc.getSupportedLocales(), null);
98      }
99  }