commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1419142 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/builder/combined/ main/java/org/apache/commons/configuration/builder/fluent/ test/java/org/apache/commons/configuration/builder/combined/ test...
Date Sun, 09 Dec 2012 20:28:59 GMT
Author: oheger
Date: Sun Dec  9 20:28:58 2012
New Revision: 1419142

URL: http://svn.apache.org/viewvc?rev=1419142&view=rev
Log:
Extended CombinedBuilderParameters and added a fluent interface for it.

Added:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParametersImpl.java
      - copied, changed from r1417638, commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParameters.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParametersImplBeanInfo.java
  (with props)
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderProperties.java
  (with props)
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/CombinedBuilderParameters.java
  (with props)
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParametersImpl.java
      - copied, changed from r1417638, commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParameters.java
Removed:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParameters.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParameters.java
Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/Parameters.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/fluent/TestParameters.java

Copied: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParametersImpl.java
(from r1417638, commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParameters.java)
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParametersImpl.java?p2=commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParametersImpl.java&p1=commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParameters.java&r1=1417638&r2=1419142&rev=1419142&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParameters.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParametersImpl.java
Sun Dec  9 20:28:58 2012
@@ -21,6 +21,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.configuration.builder.BasicBuilderParameters;
 import org.apache.commons.configuration.builder.BasicConfigurationBuilder;
 import org.apache.commons.configuration.builder.BuilderParameters;
 import org.apache.commons.configuration.builder.ConfigurationBuilder;
@@ -44,23 +45,30 @@ import org.apache.commons.configuration.
  * @version $Id$
  * @since 2.0
  */
-public class CombinedBuilderParameters implements BuilderParameters
+public class CombinedBuilderParametersImpl extends BasicBuilderParameters
+        implements CombinedBuilderProperties<CombinedBuilderParametersImpl>
 {
     /** Constant for the key in the parameters map used by this class. */
     private static final String PARAM_KEY =
             BasicConfigurationBuilder.RESERVED_PARAMETER
-                    + CombinedBuilderParameters.class.getName();
+                    + CombinedBuilderParametersImpl.class.getName();
 
     /** The definition configuration builder. */
     private ConfigurationBuilder<? extends HierarchicalConfiguration> definitionBuilder;
 
+    /** A parameters object for the definition configuration builder. */
+    private BuilderParameters definitionBuilderParameters;
+
     /** A map with registered configuration builder providers. */
     private final Map<String, ConfigurationBuilderProvider> providers;
 
+    /** The base path for configuration sources to be loaded. */
+    private String basePath;
+
     /**
-     * Creates a new instance of {@code CombinedBuilderParameters}.
+     * Creates a new instance of {@code CombinedBuilderParametersImpl}.
      */
-    public CombinedBuilderParameters()
+    public CombinedBuilderParametersImpl()
     {
         providers = new HashMap<String, ConfigurationBuilderProvider>();
     }
@@ -73,7 +81,7 @@ public class CombinedBuilderParameters i
      * @return the instance obtained from the map or <b>null</b>
      * @throws NullPointerException if the map is <b>null</b>
      */
-    public static CombinedBuilderParameters fromParameters(
+    public static CombinedBuilderParametersImpl fromParameters(
             Map<String, Object> params)
     {
         return fromParameters(params, false);
@@ -92,14 +100,14 @@ public class CombinedBuilderParameters i
      * @return the instance obtained from the map or <b>null</b>
      * @throws NullPointerException if the map is <b>null</b>
      */
-    public static CombinedBuilderParameters fromParameters(
+    public static CombinedBuilderParametersImpl fromParameters(
             Map<String, Object> params, boolean createIfMissing)
     {
-        CombinedBuilderParameters result =
-                (CombinedBuilderParameters) params.get(PARAM_KEY);
+        CombinedBuilderParametersImpl result =
+                (CombinedBuilderParametersImpl) params.get(PARAM_KEY);
         if (result == null && createIfMissing)
         {
-            result = new CombinedBuilderParameters();
+            result = new CombinedBuilderParametersImpl();
         }
         return result;
     }
@@ -123,7 +131,7 @@ public class CombinedBuilderParameters i
      * @param builder the definition {@code ConfigurationBuilder}
      * @return a reference to this object for method chaining
      */
-    public CombinedBuilderParameters setDefinitionBuilder(
+    public CombinedBuilderParametersImpl setDefinitionBuilder(
             ConfigurationBuilder<? extends HierarchicalConfiguration> builder)
     {
         definitionBuilder = builder;
@@ -142,7 +150,7 @@ public class CombinedBuilderParameters i
      * @return a reference to this object for method chaining
      * @throws IllegalArgumentException if a required parameter is missing
      */
-    public CombinedBuilderParameters registerProvider(String tagName,
+    public CombinedBuilderParametersImpl registerProvider(String tagName,
             ConfigurationBuilderProvider provider)
     {
         if (tagName == null)
@@ -167,13 +175,13 @@ public class CombinedBuilderParameters i
      * registering a provider object for the same tag name at the parameters
      * object.
      *
-     * @param providers a map with tag names and corresponding providers
-     * @return a reference to this object for method chaining (must not be
-     *         <b>null</b> or contain <b>null</b> entries
+     * @param providers a map with tag names and corresponding providers (must
+     *        not be <b>null</b> or contain <b>null</b> entries)
+     * @return a reference to this object for method chaining
      * @throws IllegalArgumentException if the map with providers is <b>null</b>
      *         or contains <b>null</b> entries
      */
-    public CombinedBuilderParameters registerMissingProviders(
+    public CombinedBuilderParametersImpl registerMissingProviders(
             Map<String, ConfigurationBuilderProvider> providers)
     {
         if (providers == null)
@@ -219,12 +227,74 @@ public class CombinedBuilderParameters i
     }
 
     /**
+     * Returns the base path for relative names of configuration sources. Result
+     * may be <b>null</b> if no base path has been set.
+     *
+     * @return the base path for resolving relative file names
+     */
+    public String getBasePath()
+    {
+        return basePath;
+    }
+
+    /**
+     * Sets the base path for this combined configuration builder. Normally it
+     * it not necessary to set the base path explicitly. Per default, relative
+     * file names of configuration sources are resolved based on the location of
+     * the definition file. If this is not desired or if the definition
+     * configuration is loaded by a different means, the base path for relative
+     * file names can be specified using this method.
+     *
+     * @param path the base path for resolving relative file names
+     * @return a reference to this object for method chaining
+     */
+    public CombinedBuilderParametersImpl setBasePath(String path)
+    {
+        basePath = path;
+        return this;
+    }
+
+    /**
+     * Returns the parameters object for the definition configuration builder if
+     * present.
+     *
+     * @return the parameters object for the definition configuration builder or
+     *         <b>null</b>
+     */
+    public BuilderParameters getDefinitionBuilderParameters()
+    {
+        return definitionBuilderParameters;
+    }
+
+    /**
+     * Sets the parameters object for the definition configuration builder. This
+     * property is evaluated only if the definition configuration builder is not
+     * set explicitly (using the
+     * {@link #setDefinitionBuilder(ConfigurationBuilder)} method). In this
+     * case, a builder for an XML configuration is created and configured with
+     * this parameters object.
+     *
+     * @param params the parameters object for the definition configuration
+     *        builder
+     * @return a reference to this object for method chaining
+     */
+    public CombinedBuilderParametersImpl setDefinitionBuilderParameters(
+            BuilderParameters params)
+    {
+        definitionBuilderParameters = params;
+        return this;
+    }
+
+    /**
      * {@inheritDoc} This implementation returns a map which contains this
      * object itself under a specific key. The static {@code fromParameters()}
      * method can be used to extract an instance from a parameters map.
      */
+    @Override
     public Map<String, Object> getParameters()
     {
-        return Collections.singletonMap(PARAM_KEY, (Object) this);
+        Map<String, Object> params = super.getParameters();
+        params.put(PARAM_KEY, this);
+        return params;
     }
 }

Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParametersImplBeanInfo.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParametersImplBeanInfo.java?rev=1419142&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParametersImplBeanInfo.java
(added)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParametersImplBeanInfo.java
Sun Dec  9 20:28:58 2012
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.builder.combined;
+
+import org.apache.commons.configuration.builder.BuilderParametersBeanInfo;
+
+/**
+ * An additional {@code BeanInfo} class for
+ * {@link CombinedBuilderParametersImpl}.
+ *
+ * @version $Id$
+ * @since 2.0
+ */
+public class CombinedBuilderParametersImplBeanInfo extends
+        BuilderParametersBeanInfo
+{
+    /**
+     * Creates a new instance of {@code CombinedBuilderParametersImplBeanInfo}.
+     */
+    public CombinedBuilderParametersImplBeanInfo()
+    {
+        super(CombinedBuilderParametersImpl.class);
+    }
+}

Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParametersImplBeanInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParametersImplBeanInfo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParametersImplBeanInfo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderProperties.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderProperties.java?rev=1419142&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderProperties.java
(added)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderProperties.java
Sun Dec  9 20:28:58 2012
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.builder.combined;
+
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.configuration.builder.BuilderParameters;
+import org.apache.commons.configuration.builder.ConfigurationBuilder;
+
+/**
+ * <p>
+ * Definition of a properties interface for the parameters of a combined
+ * configuration builder.
+ * </p>
+ * <p>
+ * This interface defines a number of properties for adapting the construction
+ * of a combined configuration based on a definition configuration. Properties
+ * can be set in a fluent style.
+ * </p>
+ *
+ * @version $Id$
+ * @since 2.0
+ * @param <T> the return type of all methods for allowing method chaining
+ */
+public interface CombinedBuilderProperties<T>
+{
+    /**
+     * Sets the {@code ConfigurationBuilder} for the definition configuration.
+     * This is the configuration which contains the configuration sources that
+     * form the combined configuration.
+     *
+     * @param builder the definition {@code ConfigurationBuilder}
+     * @return a reference to this object for method chaining
+     */
+    T setDefinitionBuilder(
+            ConfigurationBuilder<? extends HierarchicalConfiguration> builder);
+
+    /**
+     * Registers the given {@code ConfigurationBuilderProvider} for the
+     * specified tag name. This means that whenever this tag is encountered in a
+     * configuration definition file, the corresponding builder provider is
+     * invoked.
+     *
+     * @param tagName the name of the tag (must not be <b>null</b>)
+     * @param provider the {@code ConfigurationBuilderProvider} (must not be
+     *        <b>null</b>)
+     * @return a reference to this object for method chaining
+     * @throws IllegalArgumentException if a required parameter is missing
+     */
+    T registerProvider(String tagName, ConfigurationBuilderProvider provider);
+
+    /**
+     * Sets the base path for this combined configuration builder. Normally it
+     * it not necessary to set the base path explicitly. Per default, relative
+     * file names of configuration sources are resolved based on the location of
+     * the definition file. If this is not desired or if the definition
+     * configuration is loaded by a different means, the base path for relative
+     * file names can be specified using this method.
+     *
+     * @param path the base path for resolving relative file names
+     * @return a reference to this object for method chaining
+     */
+    T setBasePath(String path);
+
+    /**
+     * Sets the parameters object for the definition configuration builder. This
+     * property is evaluated only if the definition configuration builder is not
+     * set explicitly (using the
+     * {@link #setDefinitionBuilder(ConfigurationBuilder)} method). In this
+     * case, a builder for an XML configuration is created and configured with
+     * this parameters object.
+     *
+     * @param params the parameters object for the definition configuration
+     *        builder
+     * @return a reference to this object for method chaining
+     */
+    T setDefinitionBuilderParameters(BuilderParameters params);
+}

Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderProperties.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderProperties.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderProperties.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java?rev=1419142&r1=1419141&r2=1419142&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
Sun Dec  9 20:28:58 2012
@@ -485,7 +485,7 @@ public class CombinedConfigurationBuilde
     private ConfigurationSourceData sourceData;
 
     /** Stores the current parameters object. */
-    private CombinedBuilderParameters currentParameters;
+    private CombinedBuilderParametersImpl currentParameters;
 
     /** Stores the base path to the configuration sources to load. */
     private String configurationBasePath;
@@ -668,8 +668,8 @@ public class CombinedConfigurationBuilde
     protected ConfigurationBuilder<? extends HierarchicalConfiguration> setupDefinitionBuilder(
             Map<String, Object> params) throws ConfigurationException
     {
-        CombinedBuilderParameters cbParams =
-                CombinedBuilderParameters.fromParameters(params);
+        CombinedBuilderParametersImpl cbParams =
+                CombinedBuilderParametersImpl.fromParameters(params);
         if (cbParams != null)
         {
             ConfigurationBuilder<? extends HierarchicalConfiguration> defBuilder =
@@ -906,7 +906,7 @@ public class CombinedConfigurationBuilde
     private void setUpCurrentParameters()
     {
         currentParameters =
-                CombinedBuilderParameters.fromParameters(getParameters(), true);
+                CombinedBuilderParametersImpl.fromParameters(getParameters(), true);
         currentParameters.registerMissingProviders(DEFAULT_PROVIDERS_MAP);
     }
 

Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/CombinedBuilderParameters.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/CombinedBuilderParameters.java?rev=1419142&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/CombinedBuilderParameters.java
(added)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/CombinedBuilderParameters.java
Sun Dec  9 20:28:58 2012
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.builder.fluent;
+
+import org.apache.commons.configuration.builder.BasicBuilderProperties;
+import org.apache.commons.configuration.builder.BuilderParameters;
+import org.apache.commons.configuration.builder.combined.CombinedBuilderProperties;
+
+/**
+ * <p>
+ * Definition of a parameters interface providing a fluent API for setting all
+ * properties of a builder for a combined configuration.
+ * </p>
+ *
+ * @version $Id$
+ * @since 2.0
+ */
+public interface CombinedBuilderParameters extends
+        BasicBuilderProperties<CombinedBuilderParameters>,
+        CombinedBuilderProperties<CombinedBuilderParameters>, BuilderParameters
+{
+}

Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/CombinedBuilderParameters.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/CombinedBuilderParameters.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/CombinedBuilderParameters.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/Parameters.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/Parameters.java?rev=1419142&r1=1419141&r2=1419142&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/Parameters.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/Parameters.java
Sun Dec  9 20:28:58 2012
@@ -23,6 +23,7 @@ import java.lang.reflect.Proxy;
 import org.apache.commons.configuration.builder.BasicBuilderParameters;
 import org.apache.commons.configuration.builder.BuilderParameters;
 import org.apache.commons.configuration.builder.FileBasedBuilderParametersImpl;
+import org.apache.commons.configuration.builder.combined.CombinedBuilderParametersImpl;
 
 /**
  * <p>
@@ -91,6 +92,18 @@ public final class Parameters
     }
 
     /**
+     * Creates a new instance of a parameters object for combined configuration
+     * builder properties.
+     *
+     * @return the new parameters object
+     */
+    public static CombinedBuilderParameters combined()
+    {
+        return createParametersProxy(CombinedBuilderParameters.class,
+                new CombinedBuilderParametersImpl());
+    }
+
+    /**
      * Creates a proxy object for a given parameters interface based on the
      * given implementation object.
      *

Copied: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParametersImpl.java
(from r1417638, commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParameters.java)
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParametersImpl.java?p2=commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParametersImpl.java&p1=commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParameters.java&r1=1417638&r2=1419142&rev=1419142&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParameters.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParametersImpl.java
Sun Dec  9 20:28:58 2012
@@ -25,18 +25,21 @@ import static org.junit.Assert.assertTru
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.configuration.ConfigurationAssert;
 import org.apache.commons.configuration.XMLConfiguration;
 import org.apache.commons.configuration.builder.BasicConfigurationBuilder;
+import org.apache.commons.configuration.builder.BuilderParameters;
 import org.apache.commons.configuration.builder.ConfigurationBuilder;
 import org.easymock.EasyMock;
 import org.junit.Test;
 
 /**
- * Test class for {@code CombinedBuilderParameters}.
+ * Test class for {@code CombinedBuilderParametersImpl}.
  *
  * @version $Id$
  */
-public class TestCombinedBuilderParameters
+public class TestCombinedBuilderParametersImpl
 {
     /**
      * Tests fromParameters() if the map does not contain an instance.
@@ -45,7 +48,7 @@ public class TestCombinedBuilderParamete
     public void testFromParametersNotFound()
     {
         assertNull("Got an instance",
-                CombinedBuilderParameters
+                CombinedBuilderParametersImpl
                         .fromParameters(new HashMap<String, Object>()));
     }
 
@@ -56,8 +59,8 @@ public class TestCombinedBuilderParamete
     @Test
     public void testFromParametersCreate()
     {
-        CombinedBuilderParameters params =
-                CombinedBuilderParameters.fromParameters(
+        CombinedBuilderParametersImpl params =
+                CombinedBuilderParametersImpl.fromParameters(
                         new HashMap<String, Object>(), true);
         assertNotNull("No instance", params);
         assertNull("Got data", params.getDefinitionBuilder());
@@ -69,10 +72,26 @@ public class TestCombinedBuilderParamete
     @Test
     public void testFromParametersExisting()
     {
-        CombinedBuilderParameters params = new CombinedBuilderParameters();
+        CombinedBuilderParametersImpl params = new CombinedBuilderParametersImpl();
         Map<String, Object> map = params.getParameters();
         assertSame("Wrong result", params,
-                CombinedBuilderParameters.fromParameters(map));
+                CombinedBuilderParametersImpl.fromParameters(map));
+    }
+
+    /**
+     * Tests that inherited properties are also stored in the parameters map.
+     */
+    @Test
+    public void testGetParametersInherited()
+    {
+        CombinedBuilderParametersImpl params =
+                new CombinedBuilderParametersImpl();
+        params.setThrowExceptionOnMissing(true);
+        Map<String, Object> map = params.getParameters();
+        assertEquals("Exception flag not found", Boolean.TRUE,
+                map.get("throwExceptionOnMissing"));
+        assertEquals("Wrong delimiter parsing flag", Boolean.TRUE,
+                map.get("delimiterParsingDisabled"));
     }
 
     /**
@@ -81,7 +100,7 @@ public class TestCombinedBuilderParamete
     @Test
     public void testSetDefinitionBuilder()
     {
-        CombinedBuilderParameters params = new CombinedBuilderParameters();
+        CombinedBuilderParametersImpl params = new CombinedBuilderParametersImpl();
         assertNull("Got a definition builder", params.getDefinitionBuilder());
         ConfigurationBuilder<XMLConfiguration> builder =
                 new BasicConfigurationBuilder<XMLConfiguration>(
@@ -97,7 +116,7 @@ public class TestCombinedBuilderParamete
     @Test
     public void testGetProvidersInitial()
     {
-        CombinedBuilderParameters params = new CombinedBuilderParameters();
+        CombinedBuilderParametersImpl params = new CombinedBuilderParametersImpl();
         assertTrue("Got providers", params.getProviders().isEmpty());
     }
 
@@ -111,7 +130,7 @@ public class TestCombinedBuilderParamete
                 EasyMock.createMock(ConfigurationBuilderProvider.class);
         EasyMock.replay(provider);
         String tagName = "testTag";
-        CombinedBuilderParameters params = new CombinedBuilderParameters();
+        CombinedBuilderParametersImpl params = new CombinedBuilderParametersImpl();
         assertSame("Wrong result", params,
                 params.registerProvider(tagName, provider));
         Map<String, ConfigurationBuilderProvider> providers =
@@ -128,7 +147,7 @@ public class TestCombinedBuilderParamete
     @Test(expected = IllegalArgumentException.class)
     public void testRegisterProviderNoTag()
     {
-        new CombinedBuilderParameters().registerProvider(null,
+        new CombinedBuilderParametersImpl().registerProvider(null,
                 EasyMock.createMock(ConfigurationBuilderProvider.class));
     }
 
@@ -138,7 +157,7 @@ public class TestCombinedBuilderParamete
     @Test(expected = IllegalArgumentException.class)
     public void testRegisterProviderNoProvider()
     {
-        new CombinedBuilderParameters().registerProvider("aTag", null);
+        new CombinedBuilderParametersImpl().registerProvider("aTag", null);
     }
 
     /**
@@ -147,7 +166,7 @@ public class TestCombinedBuilderParamete
     @Test(expected = UnsupportedOperationException.class)
     public void testGetProvidersModify()
     {
-        CombinedBuilderParameters params = new CombinedBuilderParameters();
+        CombinedBuilderParametersImpl params = new CombinedBuilderParametersImpl();
         params.getProviders().put("tag",
                 EasyMock.createMock(ConfigurationBuilderProvider.class));
     }
@@ -165,7 +184,7 @@ public class TestCombinedBuilderParamete
         ConfigurationBuilderProvider provider3 =
                 EasyMock.createMock(ConfigurationBuilderProvider.class);
         String tagPrefix = "testTag";
-        CombinedBuilderParameters params = new CombinedBuilderParameters();
+        CombinedBuilderParametersImpl params = new CombinedBuilderParametersImpl();
         params.registerProvider(tagPrefix, provider1);
         Map<String, ConfigurationBuilderProvider> map =
                 new HashMap<String, ConfigurationBuilderProvider>();
@@ -186,7 +205,7 @@ public class TestCombinedBuilderParamete
     @Test(expected = IllegalArgumentException.class)
     public void testRegisterMissingProvidersNullMap()
     {
-        new CombinedBuilderParameters().registerMissingProviders(null);
+        new CombinedBuilderParametersImpl().registerMissingProviders(null);
     }
 
     /**
@@ -198,7 +217,7 @@ public class TestCombinedBuilderParamete
         Map<String, ConfigurationBuilderProvider> map =
                 new HashMap<String, ConfigurationBuilderProvider>();
         map.put("tag", null);
-        new CombinedBuilderParameters().registerMissingProviders(map);
+        new CombinedBuilderParametersImpl().registerMissingProviders(map);
     }
 
     /**
@@ -207,7 +226,56 @@ public class TestCombinedBuilderParamete
     @Test
     public void testProviderForUnknown()
     {
-        CombinedBuilderParameters params = new CombinedBuilderParameters();
+        CombinedBuilderParametersImpl params = new CombinedBuilderParametersImpl();
         assertNull("Got a provider", params.providerForTag("someTag"));
     }
+
+    /**
+     * Tests whether the base path can be set.
+     */
+    @Test
+    public void testSetBasePath()
+    {
+        CombinedBuilderParametersImpl params =
+                new CombinedBuilderParametersImpl();
+        String basePath = ConfigurationAssert.OUT_DIR.getAbsolutePath();
+        assertSame("Wrong result", params, params.setBasePath(basePath));
+        assertEquals("Wrong base path", basePath, params.getBasePath());
+    }
+
+    /**
+     * Tests whether a parameters object for the definition builder can be set.
+     */
+    @Test
+    public void testSetDefinitionBuilderParameters()
+    {
+        BuilderParameters defparams =
+                EasyMock.createMock(BuilderParameters.class);
+        EasyMock.replay(defparams);
+        CombinedBuilderParametersImpl params =
+                new CombinedBuilderParametersImpl();
+        assertSame("Wrong result", params,
+                params.setDefinitionBuilderParameters(defparams));
+        assertSame("Wrong parameters object", defparams,
+                params.getDefinitionBuilderParameters());
+    }
+
+    /**
+     * Tests whether properties can be set using BeanUtils.
+     */
+    @Test
+    public void testSetBeanProperties() throws Exception
+    {
+        BuilderParameters defparams =
+                EasyMock.createMock(BuilderParameters.class);
+        EasyMock.replay(defparams);
+        CombinedBuilderParametersImpl params =
+                new CombinedBuilderParametersImpl();
+        PropertyUtils.setProperty(params, "basePath", "testPath");
+        PropertyUtils.setProperty(params, "definitionBuilderParameters",
+                defparams);
+        assertEquals("Wrong path", "testPath", params.getBasePath());
+        assertSame("Wrong def parameters", defparams,
+                params.getDefinitionBuilderParameters());
+    }
 }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/fluent/TestParameters.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/fluent/TestParameters.java?rev=1419142&r1=1419141&r2=1419142&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/fluent/TestParameters.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/fluent/TestParameters.java
Sun Dec  9 20:28:58 2012
@@ -24,6 +24,7 @@ import java.util.Map;
 
 import org.apache.commons.configuration.builder.BasicBuilderParameters;
 import org.apache.commons.configuration.builder.FileBasedBuilderParametersImpl;
+import org.apache.commons.configuration.builder.combined.CombinedBuilderParametersImpl;
 import org.junit.Test;
 
 /**
@@ -81,4 +82,25 @@ public class TestParameters
                 s.indexOf(FileBasedBuilderParametersImpl.class.getSimpleName()) >= 0);
         assertTrue("No hash code", params.hashCode() != 0);
     }
+
+    /**
+     * Tests whether a combined parameters object can be created.
+     */
+    @Test
+    public void testCombined()
+    {
+        Map<String, Object> map =
+                Parameters.combined().setThrowExceptionOnMissing(true)
+                        .setBasePath("test").setListDelimiter('~')
+                        .getParameters();
+        CombinedBuilderParametersImpl cparams =
+                CombinedBuilderParametersImpl.fromParameters(map);
+        assertEquals("Wrong base path", "test", cparams.getBasePath());
+        assertEquals("Delimiter flag not set", Boolean.TRUE,
+                map.get("delimiterParsingDisabled"));
+        assertEquals("Wrong delimiter", Character.valueOf('~'),
+                map.get("listDelimiter"));
+        assertEquals("Wrong exception flag value", Boolean.TRUE,
+                map.get("throwExceptionOnMissing"));
+    }
 }



Mime
View raw message