1   /*
2    * Copyright 2004 The Apache Software Foundation
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.pluto.descriptors.servlet;
17  
18  import java.util.Arrays;
19  
20  import junit.framework.TestCase;
21  
22  /***
23   * Test Case for the Web Application configuration descriptor.
24   * @author <a href="ddewolf@apache.org">David H. DeWolf</a>
25   * @version 1.0
26   * @since Mar 23, 2005
27   */
28  public class WebAppDDTest extends TestCase {
29  
30      private WebAppDD dd;
31  
32      public WebAppDDTest() {
33  
34      }
35  
36      public void setUp() {
37          dd = new WebAppDD();
38      }
39  
40      public void tearDown() {
41          dd = null;
42      }
43  
44      public void testCollectionsNotNull() {
45          assertNotNull(dd.getContextParams());
46          assertNotNull(dd.getEjbRefs());
47          assertNotNull(dd.getEnvEntrys());
48          assertNotNull(dd.getErrorPages());
49          assertNotNull(dd.getFilterMappings());
50          assertNotNull(dd.getFilters());
51          assertNotNull(dd.getListeners());
52          assertNotNull(dd.getMimeMappings());
53          assertNotNull(dd.getResourceRefs());
54          assertNotNull(dd.getSecurityConstraints());
55          assertNotNull(dd.getSecurityRoles());
56          assertNotNull(dd.getServletMappings());
57          assertNotNull(dd.getServlets());
58      }
59  
60      public void testFindServlet() {
61          ServletDD[] servlets = {new ServletDD(), new ServletDD()};
62          servlets[0].setServletName("one");
63          servlets[1].setServletName("two");
64          dd.setServlets(Arrays.asList(servlets));
65  
66          assertEquals(servlets[0], dd.getServlet("one"));
67          assertEquals(servlets[1], dd.getServlet("two"));
68      }
69  
70      public void testFindFilter() {
71          FilterDD[] filters = {new FilterDD(), new FilterDD()};
72          filters[0].setFilterName("one");
73          filters[1].setFilterName("two");
74          dd.setFilters(Arrays.asList(filters));
75  
76          assertEquals(filters[0], dd.getFilter("one"));
77          assertEquals(filters[1], dd.getFilter("two"));
78      }
79  
80      public void testFindServletMapping() {
81          ServletMappingDD[] servlets = {new ServletMappingDD(), new ServletMappingDD()};
82          servlets[0].setUrlPattern("/test/one");
83          servlets[1].setUrlPattern("/two");
84          dd.setServletMappings(Arrays.asList(servlets));
85  
86          assertEquals(servlets[0], dd.getServletMapping("/test/one"));
87          assertEquals(servlets[1], dd.getServletMapping("/two"));
88      }
89  }
90