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: 515306 $, $Date: 2007-03-06 22:15:00 +0100 (Di, 06 Mrz 2007) $
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 parameters.setProperty("listesc", "value1//,value2");
47
48
49 ServletContext context = new MockServletContext()
50 {
51 public String getInitParameter(String key)
52 {
53 return parameters.getProperty(key);
54 }
55
56 public Enumeration getInitParameterNames()
57 {
58 return parameters.keys();
59 }
60 };
61
62
63 final MockServletConfig config = new MockServletConfig();
64 config.setServletContext(context);
65
66
67 Servlet servlet = new HttpServlet()
68 {
69 public ServletConfig getServletConfig()
70 {
71 return config;
72 }
73 };
74
75 return new ServletContextConfiguration(servlet);
76 }
77
78 protected AbstractConfiguration getEmptyConfiguration()
79 {
80
81 ServletContext context = new MockServletContext()
82 {
83 public Enumeration getInitParameterNames()
84 {
85 return new Properties().keys();
86 }
87 };
88
89 return new ServletContextConfiguration(context);
90 }
91
92 public void testAddPropertyDirect()
93 {
94 try
95 {
96 super.testAddPropertyDirect();
97 fail("addPropertyDirect should throw an UnsupportedException");
98 }
99 catch (UnsupportedOperationException e)
100 {
101
102 }
103 }
104
105 public void testClearProperty()
106 {
107 try
108 {
109 super.testClearProperty();
110 fail("testClearProperty should throw an UnsupportedException");
111 }
112 catch (UnsupportedOperationException e)
113 {
114
115 }
116 }
117
118 }