Author: oheger Date: Tue Mar 19 21:10:32 2013 New Revision: 1458520 URL: http://svn.apache.org/r1458520 Log: Added a fluent API for setting parameters of a builder for PropertiesConfiguration objects.
Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/PropertiesBuilderParameters.java Modified: 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 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=1458520&r1=1458519&r2=1458520&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 Tue Mar 19 21:10:32 2013 @@ -25,6 +25,7 @@ import org.apache.commons.configuration. import org.apache.commons.configuration.builder.FileBasedBuilderParametersImpl; import org.apache.commons.configuration.builder.HierarchicalBuilderParametersImpl; import org.apache.commons.configuration.builder.JndiBuilderParametersImpl; +import org.apache.commons.configuration.builder.PropertiesBuilderParametersImpl; import org.apache.commons.configuration.builder.XMLBuilderParametersImpl; import org.apache.commons.configuration.builder.combined.CombinedBuilderParametersImpl; import org.apache.commons.configuration.builder.combined.MultiFileBuilderParametersImpl; @@ -142,6 +143,18 @@ public final class Parameters } /** + * Creates a new instance of a parameters object for properties + * configurations. + * + * @return the new parameters object + */ + public static PropertiesBuilderParameters properties() + { + return createParametersProxy(PropertiesBuilderParameters.class, + new PropertiesBuilderParametersImpl()); + } + + /** * Creates a new instance of a parameters object for a builder for multiple * file-based configurations. * Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/PropertiesBuilderParameters.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/PropertiesBuilderParameters.java?rev=1458520&view=auto ============================================================================== --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/PropertiesBuilderParameters.java (added) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/PropertiesBuilderParameters.java Tue Mar 19 21:10:32 2013 @@ -0,0 +1,39 @@ +/* + * 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.FileBasedBuilderProperties; +import org.apache.commons.configuration.builder.PropertiesBuilderProperties; + +/** + * <p> + * Definition of a parameters interface providing a fluent API for setting all + * properties for a properties configuration. + * </p> + * + * @version $Id$ + * @since 2.0 + */ +public interface PropertiesBuilderParameters extends + BasicBuilderProperties<PropertiesBuilderParameters>, + FileBasedBuilderProperties<PropertiesBuilderParameters>, + PropertiesBuilderProperties<PropertiesBuilderParameters>, + BuilderParameters +{ +} 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=1458520&r1=1458519&r2=1458520&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 Tue Mar 19 21:10:32 2013 @@ -23,6 +23,7 @@ import static org.junit.Assert.assertTru import java.util.Map; +import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.commons.configuration.builder.BasicBuilderParameters; import org.apache.commons.configuration.builder.BuilderParameters; import org.apache.commons.configuration.builder.FileBasedBuilderParametersImpl; @@ -177,6 +178,30 @@ public class TestParameters } /** + * Tests whether a parameters object for a properties configuration can be + * created. + */ + @Test + public void testProperties() + { + PropertiesConfiguration.IOFactory factory = + EasyMock.createMock(PropertiesConfiguration.IOFactory.class); + Map<String, Object> map = + Parameters.properties().setThrowExceptionOnMissing(true) + .setFileName("test.properties").setIOFactory(factory) + .setListDelimiter('#').setIncludesAllowed(false) + .getParameters(); + checkBasicProperties(map); + FileBasedBuilderParametersImpl fbp = + FileBasedBuilderParametersImpl.fromParameters(map); + assertEquals("Wrong file name", "test.properties", fbp.getFileHandler() + .getFileName()); + assertEquals("Wrong includes flag", Boolean.FALSE, + map.get("includesAllowed")); + assertSame("Wrong factory", factory, map.get("iOFactory")); + } + + /** * Tests whether a {@code MultiFileBuilderParameters} object can be created. */ @Test