1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.configuration.web;
19
20 import java.util.Enumeration;
21 import java.util.Properties;
22 import javax.servlet.Servlet;
23 import javax.servlet.ServletConfig;
24 import javax.servlet.ServletContext;
25 import javax.servlet.http.HttpServlet;
26
27 import com.mockobjects.servlet.MockServletConfig;
28 import com.mockobjects.servlet.MockServletContext;
29 import org.apache.commons.configuration.AbstractConfiguration;
30 import org.apache.commons.configuration.TestAbstractConfiguration;
31
32 /***
33 * Test case for the {@link ServletContextConfiguration} class.
34 *
35 * @author Emmanuel Bourg
36 * @version $Revision: 439648 $, $Date: 2006-09-02 22:42:10 +0200 (Sa, 02 Sep 2006) $
37 */
38 public class TestServletContextConfiguration extends TestAbstractConfiguration
39 {
40 protected AbstractConfiguration getConfiguration()
41 {
42 final Properties parameters = new Properties();
43 parameters.setProperty("key1", "value1");
44 parameters.setProperty("key2", "value2");
45 parameters.setProperty("list", "value1, value2");
46
47
48 ServletContext context = new MockServletContext()
49 {
50 public String getInitParameter(String key)
51 {
52 return parameters.getProperty(key);
53 }
54
55 public Enumeration getInitParameterNames()
56 {
57 return parameters.keys();
58 }
59 };
60
61
62 final MockServletConfig config = new MockServletConfig();
63 config.setServletContext(context);
64
65
66 Servlet servlet = new HttpServlet()
67 {
68 public ServletConfig getServletConfig()
69 {
70 return config;
71 }
72 };
73
74 return new ServletContextConfiguration(servlet);
75 }
76
77 protected AbstractConfiguration getEmptyConfiguration()
78 {
79
80 ServletContext context = new MockServletContext()
81 {
82 public Enumeration getInitParameterNames()
83 {
84 return new Properties().keys();
85 }
86 };
87
88 return new ServletContextConfiguration(context);
89 }
90
91 public void testAddPropertyDirect()
92 {
93 try
94 {
95 super.testAddPropertyDirect();
96 fail("addPropertyDirect should throw an UnsupportedException");
97 }
98 catch (UnsupportedOperationException e)
99 {
100
101 }
102 }
103
104 public void testClearProperty()
105 {
106 try
107 {
108 super.testClearProperty();
109 fail("testClearProperty should throw an UnsupportedException");
110 }
111 catch (UnsupportedOperationException e)
112 {
113
114 }
115 }
116
117 }