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.test.config;
19  
20  import java.net.URL;
21  import java.util.ArrayList;
22  import java.util.Iterator;
23  import java.util.List;
24  import javax.faces.convert.Converter;
25  import javax.faces.render.Renderer;
26  import junit.framework.Test;
27  import junit.framework.TestSuite;
28  import org.apache.shale.test.base.AbstractJsfTestCase;
29  
30  /***
31   * <p>Unit tests for the configuration parser utility class.</p>
32   */
33  public class ConfigParserTestCase extends AbstractJsfTestCase {
34  
35  
36      // ------------------------------------------------------------ Constructors
37  
38  
39      // Construct a new instance of this test case.
40      public ConfigParserTestCase(String name) {
41          super(name);
42      }
43  
44  
45      // ---------------------------------------------------- Overall Test Methods
46  
47  
48      // Set up instance variables required by this test case.
49      protected void setUp() throws Exception {
50  
51          super.setUp();
52          parser = new ConfigParser();
53  
54      }
55  
56  
57      // Return the tests included in this test case.
58      public static Test suite() {
59  
60          return (new TestSuite(ConfigParserTestCase.class));
61  
62      }
63  
64  
65      // Tear down instance variables required by this test case.
66      protected void tearDown() throws Exception {
67  
68          parser = null;
69          super.tearDown();
70  
71      }
72  
73  
74      // ------------------------------------------------------ Instance Variables
75  
76  
77      // ConfigParser instance under test
78      ConfigParser parser = null;
79  
80  
81      // ------------------------------------------------- Individual Test Methods
82  
83  
84      // Test access to the platform configuration resources
85      public void testPlatform() throws Exception {
86  
87          // Make sure we can acquire a good set of URLs
88          URL[] urls = parser.getPlatformURLs();
89          assertNotNull(urls);
90          assertEquals(1, urls.length);
91          assertNotNull(urls[0]);
92  
93          // Now can we actually parse them?
94          parser.parse(urls);
95  
96      }
97  
98  
99      // Test a pristine instance
100     public void testPristine() {
101 
102         assertNotNull(parser);
103 
104     }
105 
106 
107     // Test loading a simple configuration resource
108     public void testSimple() throws Exception {
109 
110         URL url = this.getClass().getResource("/org/apache/shale/test/config/faces-config-1.xml");
111         assertNotNull(url);
112         parser.parse(url);
113         Iterator items = null;
114         List list = new ArrayList();
115 
116         items = application.getComponentTypes();
117         list.clear();
118         while (items.hasNext()) {
119             list.add(items.next());
120         }
121         assertTrue(list.contains("component-type-1"));
122         assertTrue(list.contains("component-type-2"));
123 
124         items = application.getConverterIds();
125         list.clear();
126         while (items.hasNext()) {
127             list.add(items.next());
128         }
129         assertTrue(list.contains("converter-id-1"));
130         assertTrue(list.contains("converter-id-2"));
131 
132         Converter converter = application.createConverter(Integer.class);
133         assertNotNull(converter);
134         assertTrue(converter instanceof MyConverter);
135 
136         items = application.getValidatorIds();
137         list.clear();
138         while (items.hasNext()) {
139             list.add(items.next());
140         }
141         assertTrue(list.contains("validator-id-1"));
142         assertTrue(list.contains("validator-id-2"));
143 
144         Renderer renderer = renderKit.getRenderer("component-family-1", "renderer-type-1");
145         assertNotNull(renderer);
146         assertTrue(renderer instanceof MyRenderer);
147         
148         renderer = renderKit.getRenderer("component-family-2", "renderer-type-2");
149         assertNotNull(renderer);
150         assertTrue(renderer instanceof MyRenderer);
151         
152     }
153 
154 
155     // --------------------------------------------------------- Private Methods
156 
157 
158 }