1 16 17 package org.apache.commons.configuration.web; 18 19 import java.util.Enumeration ; 20 import java.util.Properties ; 21 import javax.servlet.Servlet ; 22 import javax.servlet.ServletConfig ; 23 import javax.servlet.ServletContext ; 24 import javax.servlet.http.HttpServlet ; 25 26 import com.mockobjects.servlet.MockServletConfig; 27 import com.mockobjects.servlet.MockServletContext; 28 import org.apache.commons.configuration.AbstractConfiguration; 29 import org.apache.commons.configuration.TestAbstractConfiguration; 30 31 37 public class TestServletContextConfiguration extends TestAbstractConfiguration 38 { 39 protected AbstractConfiguration getConfiguration() 40 { 41 final Properties parameters = new Properties (); 42 parameters.setProperty("key1", "value1"); 43 parameters.setProperty("key2", "value2"); 44 parameters.setProperty("list", "value1, value2"); 45 46 ServletContext context = new MockServletContext() 48 { 49 public String getInitParameter(String key) 50 { 51 return parameters.getProperty(key); 52 } 53 54 public Enumeration getInitParameterNames() 55 { 56 return parameters.keys(); 57 } 58 }; 59 60 final MockServletConfig config = new MockServletConfig(); 62 config.setServletContext(context); 63 64 Servlet servlet = new HttpServlet () 66 { 67 public ServletConfig getServletConfig() 68 { 69 return config; 70 } 71 }; 72 73 return new ServletContextConfiguration(servlet); 74 } 75 76 protected AbstractConfiguration getEmptyConfiguration() 77 { 78 ServletContext context = new MockServletContext() 80 { 81 public Enumeration getInitParameterNames() 82 { 83 return new Properties ().keys(); 84 } 85 }; 86 87 return new ServletContextConfiguration(context); 88 } 89 90 public void testAddPropertyDirect() 91 { 92 try 93 { 94 super.testAddPropertyDirect(); 95 fail("addPropertyDirect should throw an UnsupportedException"); 96 } 97 catch (UnsupportedOperationException e) 98 { 99 } 101 } 102 103 public void testClearProperty() 104 { 105 try 106 { 107 super.testClearProperty(); 108 fail("testClearProperty should throw an UnsupportedException"); 109 } 110 catch (UnsupportedOperationException e) 111 { 112 } 114 } 115 116 } 117 | Popular Tags |