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 023 import javax.servlet.FilterConfig; 024 import javax.servlet.ServletContext; 025 026 import org.apache.commons.configuration.AbstractConfiguration; 027 import org.apache.commons.configuration.TestAbstractConfiguration; 028 import org.junit.Test; 029 030 /** 031 * Test case for the {@link ServletFilterConfiguration} class. 032 * 033 * @author Emmanuel Bourg 034 * @version $Id: TestServletFilterConfiguration.java 1222465 2011-12-22 21:32:56Z oheger $ 035 */ 036 public class TestServletFilterConfiguration extends TestAbstractConfiguration 037 { 038 @Override 039 protected AbstractConfiguration getConfiguration() 040 { 041 MockFilterConfig config = new MockFilterConfig(); 042 config.setInitParameter("key1", "value1"); 043 config.setInitParameter("key2", "value2"); 044 config.setInitParameter("list", "value1, value2"); 045 config.setInitParameter("listesc", "value1\\,value2"); 046 047 return new ServletFilterConfiguration(config); 048 } 049 050 @Override 051 protected AbstractConfiguration getEmptyConfiguration() 052 { 053 return new ServletFilterConfiguration(new MockFilterConfig()); 054 } 055 056 private class MockFilterConfig implements FilterConfig 057 { 058 private Properties parameters = new Properties(); 059 060 public String getFilterName() 061 { 062 return null; 063 } 064 065 public ServletContext getServletContext() 066 { 067 return null; 068 } 069 070 public String getInitParameter(String key) 071 { 072 return parameters.getProperty(key); 073 } 074 075 public Enumeration<?> getInitParameterNames() 076 { 077 return parameters.keys(); 078 } 079 080 public void setInitParameter(String key, String value) 081 { 082 parameters.setProperty(key, value); 083 } 084 } 085 086 @Override 087 @Test(expected = UnsupportedOperationException.class) 088 public void testAddPropertyDirect() 089 { 090 super.testAddPropertyDirect(); 091 } 092 093 @Override 094 @Test(expected = UnsupportedOperationException.class) 095 public void testClearProperty() 096 { 097 super.testClearProperty(); 098 } 099 }