KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > mock > MockServletConfig


1 /*
2  * $Id: MockServletConfig.java 54929 2004-10-16 16:38:42Z germuska $
3  *
4  * Copyright 1999-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19
20 package org.apache.struts.mock;
21
22
23 import java.util.Enumeration JavaDoc;
24 import java.util.HashMap JavaDoc;
25
26 import javax.servlet.ServletConfig JavaDoc;
27 import javax.servlet.ServletContext JavaDoc;
28
29
30 /**
31  * <p>Mock <strong>ServletConfig</strong> object for low-level unit tests
32  * of Struts controller components. Coarser grained tests should be
33  * implemented in terms of the Cactus framework, instead of the mock
34  * object classes.</p>
35  *
36  * <p><strong>WARNING</strong> - Only the minimal set of methods needed to
37  * create unit tests is provided, plus additional methods to configure this
38  * object as necessary. Methods for unsupported operations will throw
39  * <code>UnsupportedOperationException</code>.</p>
40  *
41  * <p><strong>WARNING</strong> - Because unit tests operate in a single
42  * threaded environment, no synchronization is performed.</p>
43  *
44  * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
45  */

46
47 public class MockServletConfig implements ServletConfig JavaDoc {
48
49
50
51     // ----------------------------------------------------------- Constructors
52

53
54     public MockServletConfig() {
55         super();
56     }
57
58
59     public MockServletConfig(ServletContext JavaDoc context) {
60         super();
61         setServletContext(context);
62     }
63
64
65     // ----------------------------------------------------- Instance Variables
66

67
68     protected ServletContext JavaDoc context = null;
69     protected HashMap JavaDoc parameters = new HashMap JavaDoc();
70
71
72     // --------------------------------------------------------- Public Methods
73

74
75     public void addInitParameter(String JavaDoc name, String JavaDoc value) {
76         parameters.put(name, value);
77     }
78
79
80     public void setServletContext(ServletContext JavaDoc context) {
81         this.context = context;
82     }
83
84
85     // ------------------------------------------------- ServletContext Methods
86

87
88     public String JavaDoc getInitParameter(String JavaDoc name) {
89         return ((String JavaDoc) parameters.get(name));
90     }
91
92
93     public Enumeration JavaDoc getInitParameterNames() {
94         return (new MockEnumeration(parameters.keySet().iterator()));
95     }
96
97
98     public ServletContext JavaDoc getServletContext() {
99         return (this.context);
100     }
101
102
103     public String JavaDoc getServletName() {
104         return ("action");
105     }
106
107
108 }
109
Popular Tags