commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject cvs commit: jakarta-commons/configuration/xdocs changes.xml
Date Thu, 14 Oct 2004 09:54:36 GMT
ebourg      2004/10/14 02:54:36

  Modified:    configuration project.xml
               configuration/xdocs changes.xml
  Added:       configuration/src/java/org/apache/commons/configuration/web
                        AppletConfiguration.java package.html
                        ServletConfiguration.java
                        ServletContextConfiguration.java
                        ServletFilterConfiguration.java
                        ServletRequestConfiguration.java
               configuration/src/test/org/apache/commons/configuration
                        TestAbstractConfiguration.java
               configuration/src/test/org/apache/commons/configuration/web
                        TestAppletConfiguration.java
                        TestServletConfiguration.java
                        TestServletContextConfiguration.java
                        TestServletFilterConfiguration.java
                        TestServletRequestConfiguration.java
  Log:
  Added web configurations
  
  Revision  Changes    Path
  1.39      +20 -4     jakarta-commons/configuration/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/project.xml,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- project.xml	12 Oct 2004 12:29:08 -0000	1.38
  +++ project.xml	14 Oct 2004 09:54:35 -0000	1.39
  @@ -68,17 +68,17 @@
         <id>1.0-rc1</id>
         <name>1.0-rc1</name>
         <tag>CONFIGURATION_1_0_RC1</tag>
  -    </version>  
  +    </version>
       <version>
         <id>1.0-rc2</id>
         <name>1.0-rc2</name>
         <tag>CONFIGURATION_1_0_RC2</tag>
  -    </version>    
  +    </version>
       <version>
         <id>1.0</id>
         <name>1.0</name>
         <tag>CONFIGURATION_1_0</tag>
  -    </version>    
  +    </version>
     </versions>
     <mailingLists>
       <mailingList>
  @@ -264,6 +264,11 @@
         </properties>
       </dependency>
   
  +    <dependency>
  +      <id>servletapi</id>
  +      <version>2.3</version>
  +    </dependency>
  +
       <!-- Needed for testing -->
   
       <dependency>
  @@ -308,6 +313,16 @@
         <version>1.4</version>
       </dependency>
   
  +    <dependency>
  +      <id>mockobjects:mockobjects-core</id>
  +      <version>0.09</version>
  +    </dependency>
  +
  +    <dependency>
  +      <id>mockobjects:mockobjects-jdk1.4-j2ee1.3</id>
  +      <version>0.09</version>
  +    </dependency>
  +
       <!-- Fake dependency to test loading configuration files from a JAR -->
       <dependency>
         <id>resources</id>
  @@ -348,6 +363,7 @@
         <excludes>
           <exclude>**/TestBasePropertiesConfiguration.java</exclude>
           <exclude>**/NonStringTestHolder.java</exclude>
  +        <exclude>**/TestAbstractConfiguration.java</exclude>
         </excludes>
         <resources>
           <resource>
  
  
  
  1.1                  jakarta-commons/configuration/src/java/org/apache/commons/configuration/web/AppletConfiguration.java
  
  Index: AppletConfiguration.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License")
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.commons.configuration.web;
  
  import java.applet.Applet;
  import java.util.Iterator;
  
  import org.apache.commons.collections.iterators.ArrayIterator;
  import org.apache.commons.configuration.AbstractConfiguration;
  
  /**
   * A configuration wrapper to read applet parameters. This configuration is
   * read only, adding or removing a property will throw an
   * UnsupportedOperationException.
   *
   * @author <a href="mailto:ebourg@apache.org">Emmanuel Bourg</a>
   * @version $Revision: 1.1 $, $Date: 2004/10/14 09:54:35 $
   */
  public class AppletConfiguration extends AbstractConfiguration
  {
      protected Applet applet;
  
      /**
       * Create an AppletConfiguration using the initialization parameters of
       * the specified Applet.
       *
       * @param applet
       */
      public AppletConfiguration(Applet applet)
      {
          this.applet = applet;
      }
  
      protected Object getPropertyDirect(String key)
      {
          return applet.getParameter(key);
      }
  
      protected void addPropertyDirect(String key, Object obj)
      {
          throw new UnsupportedOperationException("Read only configuration");
      }
  
      public boolean isEmpty()
      {
          return !getKeys().hasNext();
      }
  
      public boolean containsKey(String key)
      {
          return getPropertyDirect(key) != null;
      }
  
      public void clearProperty(String key)
      {
          throw new UnsupportedOperationException("Read only configuration");
      }
  
      public Iterator getKeys()
      {
          String[][] paramsInfo = applet.getParameterInfo();
          String[] keys = new String[paramsInfo != null ? paramsInfo.length : 0];
          for (int i = 0; i < keys.length; i++)
          {
              keys[i] = paramsInfo[i][0];
          }
  
          return new ArrayIterator(keys);
      }
  }
  
  
  
  1.1                  jakarta-commons/configuration/src/java/org/apache/commons/configuration/web/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <body>
  
  Configurations for web environments
  
  </body>
  </html>
  
  
  
  1.1                  jakarta-commons/configuration/src/java/org/apache/commons/configuration/web/ServletConfiguration.java
  
  Index: ServletConfiguration.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License")
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.commons.configuration.web;
  
  import java.util.Iterator;
  import javax.servlet.Servlet;
  import javax.servlet.ServletConfig;
  
  import org.apache.commons.collections.iterators.EnumerationIterator;
  import org.apache.commons.configuration.AbstractConfiguration;
  
  /**
   * A configuration wrapper around a {@link ServletConfig}. This configuration
   * is read only, adding or removing a property will throw an
   * UnsupportedOperationException.
   *
   * @author <a href="mailto:ebourg@apache.org">Emmanuel Bourg</a>
   * @version $Revision: 1.1 $, $Date: 2004/10/14 09:54:35 $
   */
  public class ServletConfiguration extends AbstractConfiguration
  {
      protected ServletConfig config;
  
      /**
       * Create a ServletConfiguration using the initialization parameter of
       * the specified servlet.
       *
       * @param servlet the servlet
       */
      public ServletConfiguration(Servlet servlet)
      {
          this(servlet.getServletConfig());
      }
  
      /**
       * Create a ServletConfiguration using the servlet initialization parameters.
       *
       * @param config the servlet configuration
       */
      public ServletConfiguration(ServletConfig config)
      {
          this.config = config;
      }
  
      protected Object getPropertyDirect(String key)
      {
          return config.getInitParameter(key);
      }
  
      protected void addPropertyDirect(String key, Object obj)
      {
          throw new UnsupportedOperationException("Read only configuration");
      }
  
      public boolean isEmpty()
      {
          return !getKeys().hasNext();
      }
  
      public boolean containsKey(String key)
      {
          return getPropertyDirect(key) != null;
      }
  
      public void clearProperty(String key)
      {
          throw new UnsupportedOperationException("Read only configuration");
      }
  
      public Iterator getKeys()
      {
          return new EnumerationIterator(config.getInitParameterNames());
      }
  
  }
  
  
  
  1.1                  jakarta-commons/configuration/src/java/org/apache/commons/configuration/web/ServletContextConfiguration.java
  
  Index: ServletContextConfiguration.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License")
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.commons.configuration.web;
  
  import java.util.Iterator;
  import javax.servlet.Servlet;
  import javax.servlet.ServletContext;
  
  import org.apache.commons.collections.iterators.EnumerationIterator;
  import org.apache.commons.configuration.AbstractConfiguration;
  
  /**
   * A configuration wrapper to read the initialization parameters of a servlet
   * context. This configuration is read only, adding or removing a property will
   * throw an UnsupportedOperationException.
   *
   * @author <a href="mailto:ebourg@apache.org">Emmanuel Bourg</a>
   * @version $Revision: 1.1 $, $Date: 2004/10/14 09:54:35 $
   */
  public class ServletContextConfiguration extends AbstractConfiguration
  {
      protected ServletContext context;
  
      /**
       * Create a ServletContextConfiguration using the context of
       * the specified servlet.
       *
       * @param servlet the servlet
       */
      public ServletContextConfiguration(Servlet servlet)
      {
          this.context = servlet.getServletConfig().getServletContext();
      }
  
      /**
       * Create a ServletContextConfiguration using the servlet context
       * initialization parameters.
       *
       * @param context the servlet context
       */
      public ServletContextConfiguration(ServletContext context)
      {
          this.context = context;
      }
  
      protected Object getPropertyDirect(String key)
      {
          return context.getInitParameter(key);
      }
  
      protected void addPropertyDirect(String key, Object obj)
      {
          throw new UnsupportedOperationException("Read only configuration");
      }
  
      public boolean isEmpty()
      {
          return !getKeys().hasNext();
      }
  
      public boolean containsKey(String key)
      {
          return getPropertyDirect(key) != null;
      }
  
      public void clearProperty(String key)
      {
          throw new UnsupportedOperationException("Read only configuration");
      }
  
      public Iterator getKeys()
      {
          return new EnumerationIterator(context.getInitParameterNames());
      }
  }
  
  
  
  1.1                  jakarta-commons/configuration/src/java/org/apache/commons/configuration/web/ServletFilterConfiguration.java
  
  Index: ServletFilterConfiguration.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License")
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.commons.configuration.web;
  
  import java.util.Iterator;
  import javax.servlet.FilterConfig;
  
  import org.apache.commons.collections.iterators.EnumerationIterator;
  import org.apache.commons.configuration.AbstractConfiguration;
  
  /**
   * A configuration wrapper around a {@link FilterConfig}. This configuration is
   * read only, adding or removing a property will throw an
   * UnsupportedOperationException.
   *
   * @author <a href="mailto:ebourg@apache.org">Emmanuel Bourg</a>
   * @version $Revision: 1.1 $, $Date: 2004/10/14 09:54:35 $
   */
  public class ServletFilterConfiguration extends AbstractConfiguration
  {
      protected FilterConfig config;
  
      /**
       * Create a ServletFilterConfiguration using the filter initialization parameters.
       */
      public ServletFilterConfiguration(FilterConfig config)
      {
          this.config = config;
      }
  
      protected Object getPropertyDirect(String key)
      {
          return config.getInitParameter(key);
      }
  
      protected void addPropertyDirect(String key, Object obj)
      {
          throw new UnsupportedOperationException("Read only configuration");
      }
  
      public boolean isEmpty()
      {
          return !getKeys().hasNext();
      }
  
      public boolean containsKey(String key)
      {
          return getPropertyDirect(key) != null;
      }
  
      public void clearProperty(String key)
      {
          throw new UnsupportedOperationException("Read only configuration");
      }
  
      public Iterator getKeys()
      {
          return new EnumerationIterator(config.getInitParameterNames());
      }
  }
  
  
  
  1.1                  jakarta-commons/configuration/src/java/org/apache/commons/configuration/web/ServletRequestConfiguration.java
  
  Index: ServletRequestConfiguration.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License")
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.commons.configuration.web;
  
  import java.util.Iterator;
  import javax.servlet.ServletRequest;
  
  import org.apache.commons.collections.iterators.EnumerationIterator;
  import org.apache.commons.configuration.AbstractConfiguration;
  
  /**
   * A configuration wrapper to read the parameters of a servlet request. This
   * configuration is read only, adding or removing a property will throw an
   * UnsupportedOperationException.
   *
   * @author <a href="mailto:ebourg@apache.org">Emmanuel Bourg</a>
   * @version $Revision: 1.1 $, $Date: 2004/10/14 09:54:35 $
   */
  public class ServletRequestConfiguration extends AbstractConfiguration
  {
      protected ServletRequest request;
  
      /**
       * Create a ServletRequestConfiguration using the request parameters.
       *
       * @param request the servlet request
       */
      public ServletRequestConfiguration(ServletRequest request)
      {
          this.request = request;
      }
  
      protected Object getPropertyDirect(String key)
      {
          return request.getParameter(key);
      }
  
      protected void addPropertyDirect(String key, Object obj)
      {
          throw new UnsupportedOperationException("Read only configuration");
      }
  
      public boolean isEmpty()
      {
          return !getKeys().hasNext();
      }
  
      public boolean containsKey(String key)
      {
          return getPropertyDirect(key) != null;
      }
  
      public void clearProperty(String key)
      {
          throw new UnsupportedOperationException("Read only configuration");
      }
  
      public Iterator getKeys()
      {
          return new EnumerationIterator(request.getParameterNames());
      }
  }
  
  
  
  1.1                  jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestAbstractConfiguration.java
  
  Index: TestAbstractConfiguration.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License")
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.commons.configuration;
  
  import junit.framework.TestCase;
  
  import java.util.Iterator;
  
  /**
   * Abstract TestCase for implementations of {@link AbstractConfiguration}.
   *
   * @author Emmanuel Bourg
   * @version $Revision: 1.1 $, $Date: 2004/10/14 09:54:35 $
   */
  public abstract class TestAbstractConfiguration extends TestCase
  {
      /**
       * Return an abstract configuration with 2 key/value pairs:<br>
       * <pre>
       * key1 = value1
       * key2 = value2
       * </pre>
       */
      protected abstract AbstractConfiguration getConfiguration();
  
      /**
       * Return an empty configuration.
       */
      protected abstract AbstractConfiguration getEmptyConfiguration();
  
      public void testGetPropertyDirect()
      {
          AbstractConfiguration config = getConfiguration();
          assertEquals("key1", "value1", config.getPropertyDirect("key1"));
          assertEquals("key2", "value2", config.getPropertyDirect("key2"));
          assertNull("key3", config.getPropertyDirect("key3"));
      }
  
      public void testAddPropertyDirect()
      {
          AbstractConfiguration config = getConfiguration();
          config.addPropertyDirect("key3", "value3");
          assertEquals("key3", "value3", config.getPropertyDirect("key3"));
      }
  
      public void testIsEmpty()
      {
          AbstractConfiguration config = getConfiguration();
          assertFalse("the configuration is empty", config.isEmpty());
          assertTrue("the configuration is not empty", getEmptyConfiguration().isEmpty());
      }
  
      public void testContainsKey()
      {
          AbstractConfiguration config = getConfiguration();
          assertTrue("key1 not found", config.containsKey("key1"));
          assertFalse("key3 found", config.containsKey("key3"));
      }
  
      public void testClearProperty()
      {
          AbstractConfiguration config = getConfiguration();
          config.clearProperty("key2");
          assertFalse("key2 not cleared", config.containsKey("key2"));
      }
  
      public void testGetKeys()
      {
          AbstractConfiguration config = getConfiguration();
          Iterator keys = config.getKeys();
  
          assertNotNull("null iterator", keys);
          String k = keys.next() + ":" + keys.next();
          assertTrue("elements", "key1:key2".equals(k) | "key2:key1".equals(k));
          assertFalse("too many elements", keys.hasNext());
  
          keys = getEmptyConfiguration().getKeys();
          assertNotNull("null iterator", keys);
          assertFalse("too many elements", keys.hasNext());
      }
  
  }
  
  
  
  1.1                  jakarta-commons/configuration/src/test/org/apache/commons/configuration/web/TestAppletConfiguration.java
  
  Index: TestAppletConfiguration.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License")
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.commons.configuration.web;
  
  import org.apache.commons.configuration.AbstractConfiguration;
  import org.apache.commons.configuration.TestAbstractConfiguration;
  
  import java.applet.Applet;
  import java.util.Properties;
  
  /**
   * Test case for the {@link AppletConfiguration} class.
   *
   * @author Emmanuel Bourg
   * @version $Revision: 1.1 $, $Date: 2004/10/14 09:54:35 $
   */
  public class TestAppletConfiguration extends TestAbstractConfiguration
  {
      protected AbstractConfiguration getConfiguration()
      {
          final Properties parameters = new Properties();
          parameters.setProperty("key1", "value1");
          parameters.setProperty("key2", "value2");
  
          Applet applet = new Applet()
          {
              public String getParameter(String key)
              {
                  return parameters.getProperty(key);
              }
  
              public String[][] getParameterInfo()
              {
                  return new String[][]
                  {
                      {"key1", "String", ""},
                      {"key2", "String", ""}
                  };
              }
          };
  
          return new AppletConfiguration(applet);
      }
  
      protected AbstractConfiguration getEmptyConfiguration()
      {
          return new AppletConfiguration(new Applet());
      }
  
      public void testAddPropertyDirect()
      {
          try
          {
              super.testAddPropertyDirect();
              fail("addPropertyDirect should throw an UnsupportedException");
          }
          catch (UnsupportedOperationException e)
          {
              // ok
          }
      }
  
      public void testClearProperty()
      {
          try
          {
              super.testClearProperty();
              fail("testClearProperty should throw an UnsupportedException");
          }
          catch (UnsupportedOperationException e)
          {
              // ok
          }
      }
  }
  
  
  
  1.1                  jakarta-commons/configuration/src/test/org/apache/commons/configuration/web/TestServletConfiguration.java
  
  Index: TestServletConfiguration.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License")
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.commons.configuration.web;
  
  import javax.servlet.Servlet;
  import javax.servlet.ServletConfig;
  import javax.servlet.http.HttpServlet;
  
  import com.mockobjects.servlet.MockServletConfig;
  import org.apache.commons.configuration.AbstractConfiguration;
  import org.apache.commons.configuration.TestAbstractConfiguration;
  
  /**
   * Test case for the {@link ServletConfiguration} class.
   *
   * @author Emmanuel Bourg
   * @version $Revision: 1.1 $, $Date: 2004/10/14 09:54:35 $
   */
  public class TestServletConfiguration extends TestAbstractConfiguration
  {
      protected AbstractConfiguration getConfiguration()
      {
          final MockServletConfig config = new MockServletConfig();
          config.setInitParameter("key1", "value1");
          config.setInitParameter("key2", "value2");
  
          Servlet servlet = new HttpServlet() {
              public ServletConfig getServletConfig()
              {
                  return config;
              }
          };
  
          return new ServletConfiguration(servlet);
      }
  
      protected AbstractConfiguration getEmptyConfiguration()
      {
          return new ServletConfiguration(new MockServletConfig());
      }
  
      public void testAddPropertyDirect()
      {
          try
          {
              super.testAddPropertyDirect();
              fail("addPropertyDirect should throw an UnsupportedException");
          }
          catch (UnsupportedOperationException e)
          {
              // ok
          }
      }
  
      public void testClearProperty()
      {
          try
          {
              super.testClearProperty();
              fail("testClearProperty should throw an UnsupportedException");
          }
          catch (UnsupportedOperationException e)
          {
              // ok
          }
      }
  
  }
  
  
  
  1.1                  jakarta-commons/configuration/src/test/org/apache/commons/configuration/web/TestServletContextConfiguration.java
  
  Index: TestServletContextConfiguration.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License")
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.commons.configuration.web;
  
  import java.util.Enumeration;
  import java.util.Properties;
  import javax.servlet.Servlet;
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletContext;
  import javax.servlet.http.HttpServlet;
  
  import com.mockobjects.servlet.MockServletConfig;
  import com.mockobjects.servlet.MockServletContext;
  import org.apache.commons.configuration.AbstractConfiguration;
  import org.apache.commons.configuration.TestAbstractConfiguration;
  
  /**
   * Test case for the {@link ServletContextConfiguration} class.
   *
   * @author Emmanuel Bourg
   * @version $Revision: 1.1 $, $Date: 2004/10/14 09:54:35 $
   */
  public class TestServletContextConfiguration extends TestAbstractConfiguration
  {
      protected AbstractConfiguration getConfiguration()
      {
          final Properties parameters = new Properties();
          parameters.setProperty("key1", "value1");
          parameters.setProperty("key2", "value2");
  
          // create a servlet context
          ServletContext context = new MockServletContext()
          {
              public String getInitParameter(String key)
              {
                  return parameters.getProperty(key);
              }
  
              public Enumeration getInitParameterNames()
              {
                  return parameters.keys();
              }
          };
  
          // create a servlet config
          final MockServletConfig config = new MockServletConfig();
          config.setServletContext(context);
  
          // create a servlet
          Servlet servlet = new HttpServlet()
          {
              public ServletConfig getServletConfig()
              {
                  return config;
              }
          };
  
          return new ServletContextConfiguration(servlet);
      }
  
      protected AbstractConfiguration getEmptyConfiguration()
      {
          // create a servlet context
          ServletContext context = new MockServletContext()
          {
              public Enumeration getInitParameterNames()
              {
                  return new Properties().keys();
              }
          };
  
          return new ServletContextConfiguration(context);
      }
  
      public void testAddPropertyDirect()
      {
          try
          {
              super.testAddPropertyDirect();
              fail("addPropertyDirect should throw an UnsupportedException");
          }
          catch (UnsupportedOperationException e)
          {
              // ok
          }
      }
  
      public void testClearProperty()
      {
          try
          {
              super.testClearProperty();
              fail("testClearProperty should throw an UnsupportedException");
          }
          catch (UnsupportedOperationException e)
          {
              // ok
          }
      }
  
  }
  
  
  
  1.1                  jakarta-commons/configuration/src/test/org/apache/commons/configuration/web/TestServletFilterConfiguration.java
  
  Index: TestServletFilterConfiguration.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License")
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.commons.configuration.web;
  
  import org.apache.commons.configuration.AbstractConfiguration;
  import org.apache.commons.configuration.TestAbstractConfiguration;
  
  import javax.servlet.FilterConfig;
  import javax.servlet.ServletContext;
  import java.util.Enumeration;
  import java.util.Properties;
  
  /**
   * Test case for the {@link ServletFilterConfiguration} class.
   *
   * @author Emmanuel Bourg
   * @version $Revision: 1.1 $, $Date: 2004/10/14 09:54:35 $
   */
  public class TestServletFilterConfiguration extends TestAbstractConfiguration
  {
      protected AbstractConfiguration getConfiguration()
      {
          MockFilterConfig config = new MockFilterConfig();
          config.setInitParameter("key1", "value1");
          config.setInitParameter("key2", "value2");
  
          return new ServletFilterConfiguration(config);
      }
  
      protected AbstractConfiguration getEmptyConfiguration()
      {
          return new ServletFilterConfiguration(new MockFilterConfig());
      }
  
      private class MockFilterConfig implements FilterConfig
      {
          private Properties parameters = new Properties();
  
          public String getFilterName()
          {
              return null;
          }
  
          public ServletContext getServletContext()
          {
              return null;
          }
  
          public String getInitParameter(String key)
          {
              return parameters.getProperty(key);
          }
  
          public Enumeration getInitParameterNames()
          {
              return parameters.keys();
          }
  
          public void setInitParameter(String key, String value)
          {
              parameters.setProperty(key, value);
          }
      }
  
      public void testAddPropertyDirect()
      {
          try
          {
              super.testAddPropertyDirect();
              fail("addPropertyDirect should throw an UnsupportedException");
          }
          catch (UnsupportedOperationException e)
          {
              // ok
          }
      }
  
      public void testClearProperty()
      {
          try
          {
              super.testClearProperty();
              fail("testClearProperty should throw an UnsupportedException");
          }
          catch (UnsupportedOperationException e)
          {
              // ok
          }
      }
  
  }
  
  
  
  1.1                  jakarta-commons/configuration/src/test/org/apache/commons/configuration/web/TestServletRequestConfiguration.java
  
  Index: TestServletRequestConfiguration.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License")
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.commons.configuration.web;
  
  import com.mockobjects.servlet.MockHttpServletRequest;
  import org.apache.commons.configuration.AbstractConfiguration;
  import org.apache.commons.configuration.TestAbstractConfiguration;
  
  import javax.servlet.ServletRequest;
  import java.util.Enumeration;
  import java.util.Properties;
  
  /**
   * Test case for the {@link ServletRequestConfiguration} class.
   *
   * @author Emmanuel Bourg
   * @version $Revision: 1.1 $, $Date: 2004/10/14 09:54:35 $
   */
  public class TestServletRequestConfiguration extends TestAbstractConfiguration
  {
      protected AbstractConfiguration getConfiguration()
      {
          final Properties parameters = new Properties();
          parameters.setProperty("key1", "value1");
          parameters.setProperty("key2", "value2");
  
          ServletRequest request = new MockHttpServletRequest()
          {
              public String getParameter(String key)
              {
                  return parameters.getProperty(key);
              }
  
              public Enumeration getParameterNames()
              {
                  return parameters.keys();
              }
          };
  
          return new ServletRequestConfiguration(request);
      }
  
      protected AbstractConfiguration getEmptyConfiguration()
      {
          final Properties parameters = new Properties();
  
          ServletRequest request = new MockHttpServletRequest()
          {
              public String getParameter(String key)
              {
                  return null;
              }
  
              public Enumeration getParameterNames()
              {
                  return parameters.keys();
              }
          };
  
          return new ServletRequestConfiguration(request);
      }
  
      public void testAddPropertyDirect()
      {
          try
          {
              super.testAddPropertyDirect();
              fail("addPropertyDirect should throw an UnsupportedException");
          }
          catch (UnsupportedOperationException e)
          {
              // ok
          }
      }
  
      public void testClearProperty()
      {
          try
          {
              super.testClearProperty();
              fail("testClearProperty should throw an UnsupportedException");
          }
          catch (UnsupportedOperationException e)
          {
              // ok
          }
      }
  
  }
  
  
  
  1.55      +14 -5     jakarta-commons/configuration/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- changes.xml	11 Oct 2004 10:07:30 -0000	1.54
  +++ changes.xml	14 Oct 2004 09:54:36 -0000	1.55
  @@ -6,6 +6,15 @@
     </properties>
   
     <body>
  +
  +    <release version="1.1-dev" date="in CVS">
  +      <action dev="ebourg" type="update">
  +        Added 5 new configurations to be used in a web environment:
  +        AppletConfiguration, ServletConfiguration, ServletContextConfiguration,
  +        ServletRequestConfiguration, ServletFilterConfiguration.
  +      </action>
  +    </release>
  +
       <release version="1.0.1-dev" date="in CVS">
       </release>
   
  @@ -60,21 +69,21 @@
           can be set and then the getters throw an <code>NoSuchElementException</code>.
           The old default behaviour of returning a <code>null</code> value has
           been restored.
  -      </action>         
  +      </action>
         <action dev="epugh" type="add" issue="29714">
           Allow configurations extending AbstractConfiguration to change the
           delimiter used from "," to something else.
  -      </action>         
  +      </action>
         <action dev="epugh" type="fix">
           PropertiesConfiguration.save() method has issues with preserving the filename
  -      </action>         
  +      </action>
         <action dev="epugh" type="fix" issue="30597" due-to="Mark Woodman">
           Test cases for HierarchicalConfigurationXMLReader stores comments as text nodes
  -      </action>         
  +      </action>
         <action dev="epugh" type="fix" issue="30545" due-to="Ricardo Gladwell">
           Clarify for ConfigurationDynaBean that the get method should throw an
           illegalArgumentException if there is no property specified.
  -      </action>        
  +      </action>
         <action dev="ebourg" type="fix" issue="30839">
           Fixed a ClassCastException when adding a non String property to an XMLConfiguration.
         </action>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message