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  package org.apache.shale.clay.config;
18  
19  import java.io.File;
20  
21  import org.apache.shale.clay.config.beans.ComponentConfigBean;
22  import org.apache.shale.clay.config.beans.ConfigBean;
23  import org.apache.shale.clay.config.beans.ConfigBeanFactory;
24  import org.apache.shale.clay.config.beans.TemplateComponentConfigBean;
25  import org.apache.shale.clay.config.beans.TemplateConfigBean;
26  import org.apache.shale.test.base.AbstractViewControllerTestCase;
27  
28  // package scope base class that loads factory definitions
29  public abstract class AbstractTestCaseConfig extends AbstractViewControllerTestCase {
30  
31      // Construct a new instance of this test case.
32      public AbstractTestCaseConfig(String name) {
33          super(name);
34      }
35  
36  
37      protected ConfigBean standardConfigBean = null;
38      protected ConfigBean htmlTemplateConfigBean = null;
39      protected ConfigBean xmlTemplateConfigBean = null;
40  
41      //COMPONENTS[0] = jsfid, COMPONENTS[1] = componentType, COMPONENT[2] = className
42      protected static final Object[] COMPONENTS = {new String[] {"token", "org.apache.shale.Token", "org.apache.shale.component.Token"},
43                            new String[] {"outputText", "javax.faces.HtmlOutputText", "javax.faces.component.html.HtmlOutputText"}, 
44                            new String[] {"selectItem", "javax.faces.SelectItem", "javax.faces.component.UISelectItem"},
45                            new String[] {"selectItems", "javax.faces.SelectItems", "javax.faces.component.UISelectItems"},
46                            new String[] {"selectOneRadio", "javax.faces.HtmlSelectOneRadio", "javax.faces.component.html.HtmlSelectOneRadio"},
47                            new String[] {"selectOneMenu", "javax.faces.HtmlSelectOneMenu", "javax.faces.component.html.HtmlSelectOneMenu"},
48                            new String[] {"selectManyMenu", "javax.faces.HtmlSelectManyMenu", "javax.faces.component.html.HtmlSelectManyMenu"},
49                            new String[] {"manySelectCheckbox", "javax.faces.HtmlSelectManyCheckbox", "javax.faces.component.html.HtmlSelectManyCheckbox"},
50                            new String[] {"selectBooleanCheckbox", "javax.faces.HtmlSelectBooleanCheckbox", "javax.faces.component.html.HtmlSelectBooleanCheckbox"},
51                            new String[] {"panelGroup", "javax.faces.HtmlPanelGroup", "javax.faces.component.html.HtmlPanelGroup"},
52                            new String[] {"outputLink", "javax.faces.HtmlOutputLink", "javax.faces.component.html.HtmlOutputLink"},
53                            new String[] {"outputLabel", "javax.faces.HtmlOutputLabel", "javax.faces.component.html.HtmlOutputLabel"},
54                            new String[] {"inputTextarea", "javax.faces.HtmlInputTextarea","javax.faces.component.html.HtmlInputTextarea"},
55                            new String[] {"inputSecret", "javax.faces.HtmlInputSecret","javax.faces.component.html.HtmlInputSecret"},
56                            new String[] {"inputText", "javax.faces.HtmlInputText", "javax.faces.component.html.HtmlInputText"},
57                            new String[] {"image", "javax.faces.HtmlGraphicImage", "javax.faces.component.html.HtmlGraphicImage"},
58                            new String[] {"form", "javax.faces.HtmlForm", "javax.faces.component.html.HtmlForm"},
59                            new String[] {"dataTable", "javax.faces.HtmlDataTable", "javax.faces.component.html.HtmlDataTable"},
60                            new String[] {"commandLink", "javax.faces.HtmlCommandLink", "javax.faces.component.html.HtmlCommandLink"},
61                            new String[] {"column", "javax.faces.Column", "javax.faces.component.UIColumn"},
62                            new String[] {"inputHidden", "javax.faces.HtmlInputHidden", "javax.faces.component.html.HtmlInputHidden"},
63                            new String[] {"outputFormat", "javax.faces.HtmlOutputFormat", "javax.faces.component.html.HtmlOutputFormat"},
64                            new String[] {"messages", "javax.faces.HtmlMessages", "javax.faces.component.html.HtmlMessages"},
65                            new String[] {"message", "javax.faces.HtmlMessage", "javax.faces.component.html.HtmlMessage"},
66                            new String[] {"commandButton", "javax.faces.HtmlCommandButton", "javax.faces.component.html.HtmlCommandButton"},
67                            new String[] {"panelGrid", "javax.faces.HtmlPanelGrid", "javax.faces.component.html.HtmlPanelGrid"},
68                            new String[] {"namingContainer", "javax.faces.NamingContainer", "javax.faces.component.UINamingContainer"},
69                            new String[] {"clay", "org.apache.shale.clay.component.Clay", "org.apache.shale.clay.component.Clay"}    
70      };
71  
72      // load the mock component config data
73      protected void loadComponents() {
74         for (int i = 0; i < COMPONENTS.length; i++) {
75            application.addComponent(((String[])COMPONENTS[i])[1], ((String[])COMPONENTS[i])[2]);
76         }
77      }
78      
79      //CONVERTERS[0] = jsfid, CONVERTERS[1] = componentType, CONVERTERS[2] = className
80      protected static final Object[] CONVERTERS = {
81                 new String[] {"integerConverter", "javax.faces.Integer", "javax.faces.convert.IntegerConverter"},
82                 new String[] {"dateTimeConverter", "javax.faces.DateTime", "javax.faces.convert.DateTimeConverter"}
83      };    
84      
85      // load the mock converter config data
86      protected void loadConverters() {
87          for (int i = 0; i < CONVERTERS.length; i++) {
88             application.addConverter(((String[])CONVERTERS[i])[1], ((String[])CONVERTERS[i])[2]);
89          }
90       }
91      
92      //VALIDATORS[0] = jsfid, VALIDATORS[1] = componentType, VALIDATORS[2] = className
93      public static final Object[] VALIDATORS = {
94                 new String[] {"longRangeValidator","javax.faces.LongRange", "javax.faces.validator.LongRangeValidator"}
95      };     
96  
97      // load the mock validator config
98      protected void loadValidators() {
99          for (int i = 0; i < VALIDATORS.length; i++) {
100            application.addValidator(((String[])VALIDATORS[i])[1], ((String[])VALIDATORS[i])[2]);
101         }
102     }
103 
104     // setup the testcase   
105     protected void setUp() throws Exception {
106         super.setUp();
107 
108         // Configure document root for tests
109         String documentRoot = System.getProperty("documentRoot");
110         if (documentRoot == null) {
111             documentRoot = System.getProperty("user.dir") + "//target//test-classes";           
112         }
113         servletContext.setDocumentRoot(new File(documentRoot));
114         
115         
116 
117         //load the mock config data
118         loadComponents();
119         loadConverters();
120         loadValidators();
121 
122         // sets the default html template suffix ".html"
123         servletContext.addInitParameter(Globals.CLAY_HTML_TEMPLATE_SUFFIX, ".html");
124 
125         // sets the default html template suffix ".xml"
126         servletContext.addInitParameter(Globals.CLAY_XML_TEMPLATE_SUFFIX, ".xml");
127        
128         // creates the component metadata container from the xml config files
129         standardConfigBean = new ComponentConfigBean();
130         // creates a container that builds the component metadata from an HTML  
131         // template configuration.
132         htmlTemplateConfigBean = new TemplateConfigBean();
133         // full xml view support
134         xmlTemplateConfigBean = new TemplateComponentConfigBean();
135 
136         
137         // register with the factory
138         ConfigBeanFactory.register(standardConfigBean);
139         ConfigBeanFactory.register(htmlTemplateConfigBean);
140         ConfigBeanFactory.register(xmlTemplateConfigBean);
141 
142     }
143 
144     protected void tearDown() throws Exception {
145         super.tearDown();
146 
147         // deregister
148         ConfigBeanFactory.destroy();
149         standardConfigBean = null;
150         htmlTemplateConfigBean = null;
151         xmlTemplateConfigBean = null;
152     }
153 
154     // loads the config files
155     protected void loadConfigFile(String commonConfigFiles) {
156         loadConfigFiles(commonConfigFiles, null);
157     }
158     
159     // loads the config files
160     protected void loadConfigFiles(String commonConfigFiles, String fullXmlConfigFiles) {
161         // this would be done in the ClayConfigureListener
162         
163         if (commonConfigFiles !=  null)
164            servletContext.addInitParameter(Globals.CLAY_COMMON_CONFIG_FILES, commonConfigFiles);  
165         
166         if (fullXmlConfigFiles != null) {
167            servletContext.addInitParameter(Globals.CLAY_FULLXML_CONFIG_FILES, fullXmlConfigFiles);  
168         }
169         
170         standardConfigBean.init(servletContext);
171         htmlTemplateConfigBean.init(servletContext);
172         xmlTemplateConfigBean.init(servletContext);
173 
174     }
175 
176        
177 }