001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.commons.configuration.web;
019:
020: import java.util.Enumeration;
021: import java.util.Properties;
022: import javax.servlet.Servlet;
023: import javax.servlet.ServletConfig;
024: import javax.servlet.ServletContext;
025: import javax.servlet.http.HttpServlet;
026:
027: import com.mockobjects.servlet.MockServletConfig;
028: import com.mockobjects.servlet.MockServletContext;
029: import org.apache.commons.configuration.AbstractConfiguration;
030: import org.apache.commons.configuration.TestAbstractConfiguration;
031:
032: /**
033: * Test case for the {@link ServletContextConfiguration} class.
034: *
035: * @author Emmanuel Bourg
036: * @version $Revision: 515306 $, $Date: 2007-03-06 22:15:00 +0100 (Di, 06 Mrz 2007) $
037: */
038: public class TestServletContextConfiguration extends
039: TestAbstractConfiguration {
040: protected AbstractConfiguration getConfiguration() {
041: final Properties parameters = new Properties();
042: parameters.setProperty("key1", "value1");
043: parameters.setProperty("key2", "value2");
044: parameters.setProperty("list", "value1, value2");
045: parameters.setProperty("listesc", "value1\\,value2");
046:
047: // create a servlet context
048: ServletContext context = new MockServletContext() {
049: public String getInitParameter(String key) {
050: return parameters.getProperty(key);
051: }
052:
053: public Enumeration getInitParameterNames() {
054: return parameters.keys();
055: }
056: };
057:
058: // create a servlet config
059: final MockServletConfig config = new MockServletConfig();
060: config.setServletContext(context);
061:
062: // create a servlet
063: Servlet servlet = new HttpServlet() {
064: public ServletConfig getServletConfig() {
065: return config;
066: }
067: };
068:
069: return new ServletContextConfiguration(servlet);
070: }
071:
072: protected AbstractConfiguration getEmptyConfiguration() {
073: // create a servlet context
074: ServletContext context = new MockServletContext() {
075: public Enumeration getInitParameterNames() {
076: return new Properties().keys();
077: }
078: };
079:
080: return new ServletContextConfiguration(context);
081: }
082:
083: public void testAddPropertyDirect() {
084: try {
085: super .testAddPropertyDirect();
086: fail("addPropertyDirect should throw an UnsupportedException");
087: } catch (UnsupportedOperationException e) {
088: // ok
089: }
090: }
091:
092: public void testClearProperty() {
093: try {
094: super .testClearProperty();
095: fail("testClearProperty should throw an UnsupportedException");
096: } catch (UnsupportedOperationException e) {
097: // ok
098: }
099: }
100:
101: }
|