KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > mock > web > MockFilterConfig


1 /*
2  * Copyright 2002-2007 the original author or authors.
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
17 package org.springframework.mock.web;
18
19 import java.util.Enumeration JavaDoc;
20 import java.util.Properties JavaDoc;
21
22 import javax.servlet.FilterConfig JavaDoc;
23 import javax.servlet.ServletContext JavaDoc;
24
25 import org.springframework.util.Assert;
26
27 /**
28  * Mock implementation of the {@link javax.servlet.FilterConfig} interface.
29  *
30  * <p>Used for testing the web framework; also usefol for testing
31  * custom {@link javax.servlet.Filter} implementations.
32  *
33  * @author Juergen Hoeller
34  * @since 1.0.2
35  * @see MockFilterChain
36  * @see PassThroughFilterChain
37  */

38 public class MockFilterConfig implements FilterConfig JavaDoc {
39
40     private final ServletContext JavaDoc servletContext;
41
42     private final String JavaDoc filterName;
43
44     private final Properties JavaDoc initParameters = new Properties JavaDoc();
45
46
47     /**
48      * Create a new MockFilterConfig with a default {@link MockServletContext}.
49      */

50     public MockFilterConfig() {
51         this(null, "");
52     }
53
54     /**
55      * Create a new MockFilterConfig with a default {@link MockServletContext}.
56      * @param filterName the name of the filter
57      */

58     public MockFilterConfig(String JavaDoc filterName) {
59         this(null, filterName);
60     }
61
62     /**
63      * Create a new MockFilterConfig.
64      * @param servletContext the ServletContext that the servlet runs in
65      */

66     public MockFilterConfig(ServletContext JavaDoc servletContext) {
67         this(servletContext, "");
68     }
69
70     /**
71      * Create a new MockFilterConfig.
72      * @param servletContext the ServletContext that the servlet runs in
73      * @param filterName the name of the filter
74      */

75     public MockFilterConfig(ServletContext JavaDoc servletContext, String JavaDoc filterName) {
76         this.servletContext = (servletContext != null ? servletContext : new MockServletContext());
77         this.filterName = filterName;
78     }
79
80
81     public String JavaDoc getFilterName() {
82         return filterName;
83     }
84
85     public ServletContext JavaDoc getServletContext() {
86         return servletContext;
87     }
88
89     public void addInitParameter(String JavaDoc name, String JavaDoc value) {
90         Assert.notNull(name, "Parameter name must not be null");
91         this.initParameters.setProperty(name, value);
92     }
93
94     public String JavaDoc getInitParameter(String JavaDoc name) {
95         Assert.notNull(name, "Parameter name must not be null");
96         return this.initParameters.getProperty(name);
97     }
98
99     public Enumeration JavaDoc getInitParameterNames() {
100         return this.initParameters.keys();
101     }
102
103 }
104
Popular Tags