1 16 17 package org.apache.commons.configuration.web; 18 19 import java.util.Enumeration ; 20 import javax.servlet.ServletRequest ; 21 22 import com.mockobjects.servlet.MockHttpServletRequest; 23 import org.apache.commons.collections.iterators.IteratorEnumeration; 24 import org.apache.commons.configuration.AbstractConfiguration; 25 import org.apache.commons.configuration.BaseConfiguration; 26 import org.apache.commons.configuration.Configuration; 27 import org.apache.commons.configuration.TestAbstractConfiguration; 28 29 35 public class TestServletRequestConfiguration extends TestAbstractConfiguration 36 { 37 protected AbstractConfiguration getConfiguration() 38 { 39 final Configuration configuration = new BaseConfiguration(); 40 configuration.setProperty("key1", "value1"); 41 configuration.setProperty("key2", "value2"); 42 configuration.addProperty("list", "value1"); 43 configuration.addProperty("list", "value2"); 44 45 ServletRequest request = new MockHttpServletRequest() 46 { 47 public String [] getParameterValues(String key) 48 { 49 return configuration.getStringArray(key); 50 } 51 52 public Enumeration getParameterNames() 53 { 54 return new IteratorEnumeration(configuration.getKeys()); 55 } 56 }; 57 58 return new ServletRequestConfiguration(request); 59 } 60 61 protected AbstractConfiguration getEmptyConfiguration() 62 { 63 final Configuration configuration = new BaseConfiguration(); 64 65 ServletRequest request = new MockHttpServletRequest() 66 { 67 public String getParameter(String key) 68 { 69 return null; 70 } 71 72 public Enumeration getParameterNames() 73 { 74 return new IteratorEnumeration(configuration.getKeys()); 75 } 76 }; 77 78 return new ServletRequestConfiguration(request); 79 } 80 81 public void testAddPropertyDirect() 82 { 83 try 84 { 85 super.testAddPropertyDirect(); 86 fail("addPropertyDirect should throw an UnsupportedException"); 87 } 88 catch (UnsupportedOperationException e) 89 { 90 } 92 } 93 94 public void testClearProperty() 95 { 96 try 97 { 98 super.testClearProperty(); 99 fail("testClearProperty should throw an UnsupportedException"); 100 } 101 catch (UnsupportedOperationException e) 102 { 103 } 105 } 106 107 } 108 | Popular Tags |