You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2013/03/19 22:09:49 UTC
svn commit: r1458519 - in /commons/proper/configuration/trunk/src:
main/java/org/apache/commons/configuration/builder/
test/java/org/apache/commons/configuration/builder/
Author: oheger
Date: Tue Mar 19 21:09:49 2013
New Revision: 1458519
URL: http://svn.apache.org/r1458519
Log:
Added a parameters class for properties configuration.
Added:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/PropertiesBuilderParametersImpl.java
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/PropertiesBuilderParametersImplBeanInfo.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestPropertiesBuilderParametersImpl.java
Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/PropertiesBuilderParametersImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/PropertiesBuilderParametersImpl.java?rev=1458519&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/PropertiesBuilderParametersImpl.java (added)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/PropertiesBuilderParametersImpl.java Tue Mar 19 21:09:49 2013
@@ -0,0 +1,73 @@
+/*
+ * 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;
+
+import org.apache.commons.configuration.PropertiesConfiguration.IOFactory;
+import org.apache.commons.configuration.PropertiesConfigurationLayout;
+
+/**
+ * <p>
+ * A specialized parameter class for configuring {@code PropertiesConfiguration}
+ * instances.
+ * </p>
+ * <p>
+ * This class allows setting of some properties specific to properties
+ * configuration, e.g. the layout object. By inheriting from
+ * {@link FileBasedBuilderParametersImpl}, basic properties and properties
+ * related to file-based configurations are available, too.
+ * </p>
+ * <p>
+ * This class is not thread-safe. It is intended that an instance is constructed
+ * and initialized by a single thread during configuration of a
+ * {@code ConfigurationBuilder}.
+ * </p>
+ *
+ * @version $Id: $
+ * @since 2.0
+ */
+public class PropertiesBuilderParametersImpl extends
+ FileBasedBuilderParametersImpl implements
+ PropertiesBuilderProperties<PropertiesBuilderParametersImpl>
+{
+ /** The key for the includes allowed property. */
+ private static final String PROP_INCLUDES_ALLOWED = "includesAllowed";
+
+ /** The key for the layout property. */
+ private static final String PROP_LAYOUT = "layout";
+
+ /** The key for the IO factory property. */
+ private static final String PROP_IO_FACTORY = "iOFactory";
+
+ public PropertiesBuilderParametersImpl setIncludesAllowed(boolean f)
+ {
+ storeProperty(PROP_INCLUDES_ALLOWED, Boolean.valueOf(f));
+ return this;
+ }
+
+ public PropertiesBuilderParametersImpl setLayout(
+ PropertiesConfigurationLayout layout)
+ {
+ storeProperty(PROP_LAYOUT, layout);
+ return this;
+ }
+
+ public PropertiesBuilderParametersImpl setIOFactory(IOFactory factory)
+ {
+ storeProperty(PROP_IO_FACTORY, factory);
+ return this;
+ }
+}
Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/PropertiesBuilderParametersImplBeanInfo.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/PropertiesBuilderParametersImplBeanInfo.java?rev=1458519&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/PropertiesBuilderParametersImplBeanInfo.java (added)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/PropertiesBuilderParametersImplBeanInfo.java Tue Mar 19 21:09:49 2013
@@ -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;
+
+/**
+ * An additional {@code BeanInfo} class for {@link XMLBuilderParametersImpl}.
+ *
+ * @version $Id$
+ * @since 2.0
+ */
+public class PropertiesBuilderParametersImplBeanInfo extends
+ BuilderParametersBeanInfo
+{
+ /**
+ * Creates a new instance of {@code PropertiesBuilderParametersImplBeanInfo}
+ * .
+ */
+ public PropertiesBuilderParametersImplBeanInfo()
+ {
+ super(PropertiesBuilderParametersImpl.class);
+ }
+}
Added: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestPropertiesBuilderParametersImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestPropertiesBuilderParametersImpl.java?rev=1458519&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestPropertiesBuilderParametersImpl.java (added)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestPropertiesBuilderParametersImpl.java Tue Mar 19 21:09:49 2013
@@ -0,0 +1,106 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+import java.util.Map;
+
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.configuration.PropertiesConfigurationLayout;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test class for {@code PropertiesBuilderParametersImpl}.
+ *
+ * @version $Id: $
+ */
+public class TestPropertiesBuilderParametersImpl
+{
+ /** The parameters object to be tested. */
+ private PropertiesBuilderParametersImpl params;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ params = new PropertiesBuilderParametersImpl();
+ }
+
+ /**
+ * Tests whether the includesAllowed property can be set.
+ */
+ @Test
+ public void testSetIncludesAllowed()
+ {
+ assertSame("Wrong result", params, params.setIncludesAllowed(true));
+ assertEquals("Value not set", Boolean.TRUE,
+ params.getParameters().get("includesAllowed"));
+ }
+
+ /**
+ * Tests whether the layout object can be set.
+ */
+ @Test
+ public void testSetLayout()
+ {
+ PropertiesConfigurationLayout layout =
+ new PropertiesConfigurationLayout();
+ assertSame("Wrong result", params, params.setLayout(layout));
+ assertSame("Layout not set", layout,
+ params.getParameters().get("layout"));
+ }
+
+ /**
+ * Tests whether the IO factory can be set.
+ */
+ @Test
+ public void testSetIOFactory()
+ {
+ PropertiesConfiguration.IOFactory factory =
+ EasyMock.createMock(PropertiesConfiguration.IOFactory.class);
+ EasyMock.replay(factory);
+ assertSame("Wrong result", params, params.setIOFactory(factory));
+ assertSame("Factory not set", factory,
+ params.getParameters().get("iOFactory"));
+ }
+
+ /**
+ * Tests whether properties can be set using BeanUtils.
+ */
+ @Test
+ public void testBeanPropertiesAccess() throws Exception
+ {
+ PropertiesConfiguration.IOFactory factory =
+ EasyMock.createMock(PropertiesConfiguration.IOFactory.class);
+ EasyMock.replay(factory);
+ PropertyUtils.setProperty(params, "iOFactory", factory);
+ PropertyUtils.setProperty(params, "throwExceptionOnMissing",
+ Boolean.TRUE);
+ PropertyUtils.setProperty(params, "fileName", "test.properties");
+ assertEquals("Wrong file name", "test.properties", params
+ .getFileHandler().getFileName());
+ Map<String, Object> paramsMap = params.getParameters();
+ assertEquals("Wrong exception flag", Boolean.TRUE,
+ paramsMap.get("throwExceptionOnMissing"));
+ assertSame("Factory not set", factory,
+ params.getParameters().get("iOFactory"));
+ }
+}