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.validator.converter;
19  
20  import java.util.Locale;
21  import java.util.ResourceBundle;
22  import javax.servlet.ServletContextEvent;
23  import org.apache.shale.test.base.AbstractJsfTestCase;
24  import org.apache.shale.validator.faces.ValidatorLifecycleListener;
25  import org.apache.shale.validator.util.AbstractUtilities;
26  
27  /***
28   * <p>Test case for the utility methods provided by
29   * <code>AbstractConverter</code>.</p>
30   */
31  public class AbstractConverterTestCase extends AbstractJsfTestCase {
32  
33  
34      // ------------------------------------------------------------ Constructors
35  
36  
37      // Construct a new instance of this test case.
38      public AbstractConverterTestCase(String name) {
39          super(name);
40      }
41  
42  
43      // ---------------------------------------------------- Overall Test Methods
44  
45  
46      // Set up instance variables required by this test case.
47      protected void setUp() throws Exception {
48  
49          super.setUp();
50          application.setMessageBundle("org.apache.shale.validator.TestBundle");
51          facesContext.getViewRoot().setLocale(Locale.US);
52  
53          listener = new ValidatorLifecycleListener();
54          listener.contextInitialized(new ServletContextEvent(servletContext));
55  
56          converter = new ConcreteConverter();
57  
58      }
59  
60  
61      // Tear down instance variables required by this test case.
62      protected void tearDown() throws Exception {
63  
64          converter = null;
65  
66          listener.contextDestroyed(new ServletContextEvent(servletContext));
67          listener = null;
68  
69          super.tearDown();
70  
71      }
72  
73  
74      // -------------------------------------------------------- Static Variables
75  
76  
77      /***
78       * <p>Default resource bundle for error message lookup
79       */
80      protected static final ResourceBundle defaultBundle =
81        ResourceBundle.getBundle(AbstractUtilities.DEFAULT_RESOURCE_BUNDLE, Locale.US);
82  
83  
84      // ------------------------------------------------------ Instance Variables
85  
86  
87      /***
88       * <p>ValidatorLifecycleListener used to load configuration resources</p>
89       */
90      protected ValidatorLifecycleListener listener = null;
91  
92  
93      /***
94       * <p>Converter instance under test.</p>
95       */
96      protected ConcreteConverter converter = null;
97  
98  
99      // ------------------------------------------------- Individual Test Methods
100 
101 
102     // Test retrieving messages
103     public void testMessage() {
104 
105         String message = null;
106 
107         // Check a message that should be overridden by the application
108         message = converter.message(facesContext, "errors.long");
109         assertNotNull(message);
110         assertEquals("Custom Long Error Message", message);
111 
112         // Check a message that should be grabbed from the default resources
113         message = converter.message(facesContext, "errors.integer");
114         assertNotNull(message);
115         assertEquals(defaultBundle.getString("errors.integer"), message);
116 
117         // Check a message that should be undefined
118         message = converter.message(facesContext, "???undefined???");
119         assertNull(message);
120 
121     }
122 
123 
124 }