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 2012/12/02 22:21:20 UTC
svn commit: r1416265 [3/3] - in /commons/proper/configuration/trunk/src:
main/java/org/apache/commons/configuration/builder/combined/
test/java/org/apache/commons/configuration/builder/
test/java/org/apache/commons/configuration/builder/combined/ test/...
Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/ConfigurationDeclaration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/ConfigurationDeclaration.java?rev=1416265&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/ConfigurationDeclaration.java (added)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/ConfigurationDeclaration.java Sun Dec 2 21:21:16 2012
@@ -0,0 +1,210 @@
+/*
+ * 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.beanutils.XMLBeanDeclaration;
+import org.apache.commons.configuration.tree.ConfigurationNode;
+
+/**
+ * <p>
+ * A specialized {@code BeanDeclaration} implementation that represents the
+ * declaration of a configuration source.
+ * </p>
+ * <p>
+ * Instances of this class are able to extract all information about a
+ * configuration source from the configuration definition file. The declaration
+ * of a configuration source is very similar to a bean declaration processed by
+ * {@code XMLBeanDeclaration}. There are very few differences, e.g. some
+ * reserved attributes like {@code optional} and {@code at}, and the fact that a
+ * bean factory is never needed.
+ * </p>
+ *
+ * @version $Id$
+ * @since 2.0
+ */
+public class ConfigurationDeclaration extends XMLBeanDeclaration
+{
+ /** Stores a reference to the associated configuration builder. */
+ private final CombinedConfigurationBuilder configurationBuilder;
+
+ /**
+ * Creates a new instance of {@code ConfigurationDeclaration} and
+ * initializes it.
+ *
+ * @param builder the associated configuration builder
+ * @param config the configuration this declaration is based onto
+ */
+ public ConfigurationDeclaration(CombinedConfigurationBuilder builder,
+ HierarchicalConfiguration config)
+ {
+ super(config);
+ configurationBuilder = builder;
+ }
+
+ /**
+ * Returns the associated configuration builder.
+ *
+ * @return the configuration builder
+ */
+ public CombinedConfigurationBuilder getConfigurationBuilder()
+ {
+ return configurationBuilder;
+ }
+
+ /**
+ * Returns the value of the {@code at} attribute.
+ *
+ * @return the value of the {@code at} attribute (can be <b>null</b>)
+ */
+ public String getAt()
+ {
+ String result =
+ this.getConfiguration().getString(
+ CombinedConfigurationBuilder.ATTR_AT_RES);
+ return (result == null) ? this.getConfiguration().getString(
+ CombinedConfigurationBuilder.ATTR_AT) : result;
+ }
+
+ /**
+ * Returns a flag whether this is an optional configuration.
+ *
+ * @return a flag if this declaration points to an optional configuration
+ */
+ public boolean isOptional()
+ {
+ Boolean value =
+ this.getConfiguration().getBoolean(
+ CombinedConfigurationBuilder.ATTR_OPTIONAL_RES, null);
+ if (value == null)
+ {
+ value =
+ this.getConfiguration().getBoolean(
+ CombinedConfigurationBuilder.ATTR_OPTIONAL,
+ Boolean.FALSE);
+ }
+ return value.booleanValue();
+ }
+
+ /**
+ * Returns a flag whether this configuration should always be created and
+ * added to the resulting combined configuration. This flag is evaluated
+ * only for optional configurations whose normal creation has caused an
+ * error. If for such a configuration the {@code forceCreate} attribute is
+ * set and the corresponding configuration provider supports this mode, an
+ * empty configuration will be created and added to the resulting combined
+ * configuration.
+ *
+ * @return the value of the {@code forceCreate} attribute
+ */
+ public boolean isForceCreate()
+ {
+ return this.getConfiguration().getBoolean(
+ CombinedConfigurationBuilder.ATTR_FORCECREATE, false);
+ }
+
+ /**
+ * Returns a flag whether a builder with reloading support should be
+ * created. This may not be supported by all configuration builder
+ * providers.
+ *
+ * @return a flag whether a reloading builder should be created
+ */
+ public boolean isReload()
+ {
+ return getConfiguration().getBoolean(
+ CombinedConfigurationBuilder.ATTR_RELOAD, false);
+ }
+
+ /**
+ * Returns the name for the represented configuration source. The name is
+ * optional, so this method can return <b>null</b>.
+ *
+ * @return the name of the associated configuration source or <b>null</b>
+ */
+ public String getName()
+ {
+ return getConfiguration().getString(
+ CombinedConfigurationBuilder.ATTR_NAME);
+ }
+
+ /**
+ * Returns the name of the bean factory. For configuration source
+ * declarations always a reserved factory is used. This factory's name is
+ * returned by this implementation.
+ *
+ * @return the name of the bean factory
+ */
+ @Override
+ public String getBeanFactoryName()
+ {
+ return CombinedConfigurationBuilder.CONFIG_BEAN_FACTORY_NAME;
+ }
+
+ /**
+ * Returns the bean's class name. This implementation will always return
+ * <b>null</b>.
+ *
+ * @return the name of the bean's class
+ */
+ @Override
+ public String getBeanClassName()
+ {
+ return null;
+ }
+
+ /**
+ * Checks whether the given node is reserved. This method will take further
+ * reserved attributes into account
+ *
+ * @param nd the node
+ * @return a flag whether this node is reserved
+ */
+ @Override
+ protected boolean isReservedNode(ConfigurationNode nd)
+ {
+ if (super.isReservedNode(nd))
+ {
+ return true;
+ }
+
+ return nd.isAttribute()
+ && ((CombinedConfigurationBuilder.ATTR_ATNAME.equals(nd
+ .getName()) && nd.getParentNode().getAttributeCount(
+ RESERVED_PREFIX
+ + CombinedConfigurationBuilder.ATTR_ATNAME) == 0) || (CombinedConfigurationBuilder.ATTR_OPTIONALNAME
+ .equals(nd.getName()) && nd
+ .getParentNode()
+ .getAttributeCount(
+ RESERVED_PREFIX
+ + CombinedConfigurationBuilder.ATTR_OPTIONALNAME) == 0));
+ }
+
+// /**
+// * Performs interpolation. This implementation will delegate interpolation
+// * to the configuration builder, which takes care that the currently
+// * constructed configuration is taken into account, too.
+// *
+// * @param value the value to be interpolated
+// * @return the interpolated value
+// */
+// @Override
+// protected Object interpolate(Object value)
+// {
+// return getConfigurationBuilder().interpolate(value);
+// }
+}
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/ConfigurationDeclaration.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/ConfigurationDeclaration.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/ConfigurationDeclaration.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/FileExtensionConfigurationBuilderProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/FileExtensionConfigurationBuilderProvider.java?rev=1416265&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/FileExtensionConfigurationBuilderProvider.java (added)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/FileExtensionConfigurationBuilderProvider.java Sun Dec 2 21:21:16 2012
@@ -0,0 +1,179 @@
+/*
+ * 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 java.util.Collection;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.builder.BasicBuilderParameters;
+import org.apache.commons.configuration.builder.BuilderParameters;
+import org.apache.commons.configuration.builder.FileBasedBuilderParameters;
+
+/**
+ * <p>
+ * A specialized implementation of {@link ConfigurationBuilderProvider} which
+ * determines the name of the result configuration class based on the extension
+ * of the file to load.
+ * </p>
+ * <p>
+ * This class works analogously to its base class {@link BaseConfigurationBuilderProvider};
+ * especially, the resulting builder is created based on reflection. It extends
+ * the super class's functionality by a specific mechanism for determining the
+ * resulting configuration class: At construction time two configuration class
+ * names and a file extension are passed in. If a file name is provided in the
+ * builder's initialization parameters and this file name has the specified
+ * extension, then the first configuration class name is used; otherwise the
+ * default configuration class name is selected.
+ * </p>
+ * <p>
+ * There are some tags for {@code CombinedConfigurationProvider} which can
+ * produce different results depending on the configuration files they have to
+ * load. This class can be used to implement this feature in a generic way.
+ * </p>
+ *
+ * @version $Id$
+ * @since 2.0
+ */
+public class FileExtensionConfigurationBuilderProvider extends
+ BaseConfigurationBuilderProvider
+{
+ /** Constant for the file extension separator. */
+ private static final char EXT_SEPARATOR = '.';
+
+ /** The matching configuration class. */
+ private final String matchingConfigurationClass;
+
+ /** The file extension. */
+ private final String extension;
+
+ /**
+ * Creates a new instance of
+ * {@code FileExtensionConfigurationBuilderProvider}.
+ *
+ * @param bldrCls the name of the builder class
+ * @param reloadBldrCls the name of a builder class to be used if reloading
+ * support is required (<b>null</b> if reloading is not supported)
+ * @param matchingConfigCls the name of the configuration class to be used
+ * if the provided file extension matches (must not be <b>null</b>)
+ * @param defConfigClass the name of the configuration class to be used if
+ * the provided file extension does not match (must not be
+ * <b>null</b>)
+ * @param ext the file extension to select the configuration class (must not
+ * be <b>null</b>)
+ * @param paramCls a collection with the names of parameters classes; an
+ * instance of {@link BasicBuilderParameters} is created
+ * automatically and does not need to be contained in this list; the
+ * collection can be <b>null</b> if no additional parameter objects
+ * are needed
+ * @throws IllegalArgumentException if a required parameter is missing
+ */
+ public FileExtensionConfigurationBuilderProvider(String bldrCls,
+ String reloadBldrCls, String matchingConfigCls,
+ String defConfigClass, String ext, Collection<String> paramCls)
+ {
+ super(bldrCls, reloadBldrCls, defConfigClass, paramCls);
+ if (matchingConfigCls == null)
+ {
+ throw new IllegalArgumentException(
+ "Matching configuration class must not be null!");
+ }
+ if (ext == null)
+ {
+ throw new IllegalArgumentException(
+ "File extension must not be null!");
+ }
+
+ matchingConfigurationClass = matchingConfigCls;
+ extension = ext;
+ }
+
+ /**
+ * Returns the name of the matching configuration class. This class is used
+ * if the file extension matches the extension of this provider.
+ *
+ * @return the matching configuration class
+ */
+ public String getMatchingConfigurationClass()
+ {
+ return matchingConfigurationClass;
+ }
+
+ /**
+ * Returns the file extension of this provider.
+ *
+ * @return the file extension to match
+ */
+ public String getExtension()
+ {
+ return extension;
+ }
+
+ /**
+ * {@inheritDoc} This implementation tries to find a
+ * {@link FileBasedBuilderParameters} object in the parameter objects. If
+ * one is found, the extension of the file name is obtained and compared
+ * against the stored file extension. In case of a match, the matching
+ * configuration class is selected, otherwise the default one.
+ */
+ @Override
+ protected String determineConfigurationClass(ConfigurationDeclaration decl,
+ Collection<BuilderParameters> params) throws ConfigurationException
+ {
+ String currentExt = extractExtension(fetchCurrentFileName(params));
+ return getExtension().equalsIgnoreCase(currentExt) ? getMatchingConfigurationClass()
+ : getConfigurationClass();
+ }
+
+ /**
+ * Tries to obtain the current file name from the given list of parameter
+ * objects.
+ *
+ * @param params the parameter objects
+ * @return the file name or <b>null</b> if unspecified
+ */
+ private static String fetchCurrentFileName(
+ Collection<BuilderParameters> params)
+ {
+ for (BuilderParameters p : params)
+ {
+ if (p instanceof FileBasedBuilderParameters)
+ {
+ FileBasedBuilderParameters fp = (FileBasedBuilderParameters) p;
+ return fp.getFileHandler().getFileName();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Extracts the extension from the given file name. The name can be
+ * <b>null</b>.
+ *
+ * @param fileName the file name
+ * @return the extension (<b>null</b> if there is none)
+ */
+ private static String extractExtension(String fileName)
+ {
+ if (fileName == null)
+ {
+ return null;
+ }
+
+ int pos = fileName.lastIndexOf(EXT_SEPARATOR);
+ return (pos < 0) ? null : fileName.substring(pos + 1);
+ }
+}
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/FileExtensionConfigurationBuilderProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/FileExtensionConfigurationBuilderProvider.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/FileExtensionConfigurationBuilderProvider.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiWrapDynaBean.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiWrapDynaBean.java?rev=1416265&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiWrapDynaBean.java (added)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiWrapDynaBean.java Sun Dec 2 21:21:16 2012
@@ -0,0 +1,174 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.beanutils.DynaBean;
+import org.apache.commons.beanutils.DynaClass;
+import org.apache.commons.beanutils.DynaProperty;
+import org.apache.commons.beanutils.WrapDynaBean;
+
+/**
+ * <p>
+ * An implementation of the {@code DynaBean} interfaces which wraps multiple
+ * other beans.
+ * </p>
+ * <p>
+ * An instance of this class is constructed with a collection of beans to be
+ * wrapped. When reading or writing a property the wrapped bean which defines
+ * this property is determined, and the operation is executed on this bean.
+ * </p>
+ * <p>
+ * The wrapped beans should have disjunct properties. Otherwise, it is undefined
+ * which bean property is read or written.
+ * </p>
+ *
+ * @version $Id$
+ * @since 2.0
+ */
+class MultiWrapDynaBean implements DynaBean
+{
+ /** Stores the class of this DynaBean. */
+ private final DynaClass dynaClass;
+
+ /** A map which associates property names with their defining beans. */
+ private final Map<String, DynaBean> propsToBeans;
+
+ /**
+ * Creates a new instance of {@code MultiWrapDynaBean} and initializes it
+ * with the given collections of beans to be wrapped.
+ *
+ * @param beans the wrapped beans
+ */
+ public MultiWrapDynaBean(Collection<?> beans)
+ {
+ propsToBeans = new HashMap<String, DynaBean>();
+ Collection<DynaClass> beanClasses =
+ new ArrayList<DynaClass>(beans.size());
+
+ for (Object bean : beans)
+ {
+ DynaBean dynaBean = createDynaBean(bean);
+ DynaClass beanClass = dynaBean.getDynaClass();
+ for (DynaProperty prop : beanClass.getDynaProperties())
+ {
+ propsToBeans.put(prop.getName(), dynaBean);
+ }
+ beanClasses.add(beanClass);
+ }
+
+ dynaClass = new MultiWrapDynaClass(beanClasses);
+ }
+
+ /**
+ * {@inheritDoc} This operation is not supported by the {@code WrapDynaBean}
+ * objects used internally by this class. Therefore, just an exception is
+ * thrown.
+ */
+ public boolean contains(String name, String key)
+ {
+ throw new UnsupportedOperationException(
+ "contains() operation not supported!");
+ }
+
+ public Object get(String name)
+ {
+ return fetchBean(name).get(name);
+ }
+
+ public Object get(String name, int index)
+ {
+ return fetchBean(name).get(name, index);
+ }
+
+ public Object get(String name, String key)
+ {
+ return fetchBean(name).get(name, key);
+ }
+
+ /**
+ * {@inheritDoc} This implementation returns an instance of
+ * {@code MultiWrapDynaClass}.
+ */
+ public DynaClass getDynaClass()
+ {
+ return dynaClass;
+ }
+
+ /**
+ * {@inheritDoc} This operation is not supported by the {@code WrapDynaBean}
+ * objects used internally by this class. Therefore, just an exception is
+ * thrown.
+ */
+ public void remove(String name, String key)
+ {
+ throw new UnsupportedOperationException(
+ "remove() operation not supported!");
+ }
+
+ public void set(String name, Object value)
+ {
+ fetchBean(name).set(name, value);
+ }
+
+ public void set(String name, int index, Object value)
+ {
+ fetchBean(name).set(name, index, value);
+ }
+
+ public void set(String name, String key, Object value)
+ {
+ fetchBean(name).set(name, key, value);
+ }
+
+ /**
+ * Returns the bean instance to which the given property belongs. If no such
+ * bean is found, an arbitrary bean is returned. (This causes the operation
+ * on this bean to fail with a meaningful error message.)
+ *
+ * @param property the property name
+ * @return the bean defining this property
+ */
+ private DynaBean fetchBean(String property)
+ {
+ DynaBean dynaBean = propsToBeans.get(property);
+ if (dynaBean == null)
+ {
+ dynaBean = propsToBeans.values().iterator().next();
+ }
+ return dynaBean;
+ }
+
+ /**
+ * Creates a {@code DynaBean} object for the given bean.
+ *
+ * @param bean the bean
+ * @return the {@code DynaBean} for this bean
+ */
+ private static DynaBean createDynaBean(Object bean)
+ {
+ if (bean instanceof DynaBean)
+ {
+ return (DynaBean) bean;
+ }
+ return new WrapDynaBean(bean);
+ }
+}
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiWrapDynaBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiWrapDynaBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiWrapDynaBean.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiWrapDynaClass.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiWrapDynaClass.java?rev=1416265&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiWrapDynaClass.java (added)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiWrapDynaClass.java Sun Dec 2 21:21:16 2012
@@ -0,0 +1,107 @@
+/*
+ * 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 java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+
+import org.apache.commons.beanutils.DynaBean;
+import org.apache.commons.beanutils.DynaClass;
+import org.apache.commons.beanutils.DynaProperty;
+
+/**
+ * <p>
+ * An implementation of {@code DynaClass} which combines the properties of
+ * multiple other {@code DynaClass} instances.
+ * </p>
+ *
+ * @version $Id$
+ * @since 2.0
+ */
+class MultiWrapDynaClass implements DynaClass
+{
+ /** An empty array for converting the properties collection to an array. */
+ private static final DynaProperty[] EMPTY_PROPS = new DynaProperty[0];
+
+ /** A collection with all properties of this class. */
+ private final Collection<DynaProperty> properties;
+
+ /** A map for accessing properties by name. */
+ private final Map<String, DynaProperty> namedProperties;
+
+ /**
+ * Creates a new instance of {@code MultiWrapDynaClass} and initializes it
+ * with the collection of classes to be wrapped.
+ *
+ * @param wrappedCls the collection with wrapped classes
+ */
+ public MultiWrapDynaClass(Collection<? extends DynaClass> wrappedCls)
+ {
+ properties = new LinkedList<DynaProperty>();
+ namedProperties = new HashMap<String, DynaProperty>();
+ initProperties(wrappedCls);
+ }
+
+ /**
+ * {@inheritDoc} The name of this class is not relevant.
+ */
+ public String getName()
+ {
+ return null;
+ }
+
+ public DynaProperty getDynaProperty(String name)
+ {
+ return namedProperties.get(name);
+ }
+
+ public DynaProperty[] getDynaProperties()
+ {
+ return properties.toArray(EMPTY_PROPS);
+ }
+
+ /**
+ * {@inheritDoc} This implementation always throws an exception because it
+ * is not possible to instantiate a bean of multiple classes.
+ */
+ public DynaBean newInstance() throws IllegalAccessException,
+ InstantiationException
+ {
+ throw new UnsupportedOperationException(
+ "Cannot create an instance of MultiWrapDynaBean!");
+ }
+
+ /**
+ * Initializes the members related to the properties of the wrapped classes.
+ *
+ * @param wrappedCls the collection with the wrapped classes
+ */
+ private void initProperties(Collection<? extends DynaClass> wrappedCls)
+ {
+ for (DynaClass cls : wrappedCls)
+ {
+ DynaProperty[] props = cls.getDynaProperties();
+ for (DynaProperty p : props)
+ {
+ properties.add(p);
+ namedProperties.put(p.getName(), p);
+ }
+ }
+ }
+}
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiWrapDynaClass.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiWrapDynaClass.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiWrapDynaClass.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImpl.java?rev=1416265&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImpl.java (added)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImpl.java Sun Dec 2 21:21:16 2012
@@ -0,0 +1,55 @@
+/*
+ * 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;
+
+/**
+ * A test bean used to check whether all properties can be found.
+ *
+ * @version $Id$
+ */
+public class ParametersBeanTestImpl extends BasicBuilderParameters
+{
+ private int intProperty;
+
+ private String stringProperty;
+
+ public int getIntProperty()
+ {
+ return intProperty;
+ }
+
+ public void setIntProperty(int intProperty)
+ {
+ this.intProperty = intProperty;
+ }
+
+ public String getStringProperty()
+ {
+ return stringProperty;
+ }
+
+ public void setStringProperty(String stringProperty)
+ {
+ this.stringProperty = stringProperty;
+ }
+
+ public ParametersBeanTestImpl setFluentProperty(String value)
+ {
+ setStringProperty(value);
+ return this;
+ }
+}
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImplBeanInfo.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImplBeanInfo.java?rev=1416265&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImplBeanInfo.java (added)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImplBeanInfo.java Sun Dec 2 21:21:16 2012
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+/**
+ * A BeanInfo class for the test bean.
+ *
+ * @version $Id$
+ */
+public class ParametersBeanTestImplBeanInfo extends BuilderParametersBeanInfo
+{
+ public ParametersBeanTestImplBeanInfo()
+ {
+ super(ParametersBeanTestImpl.class);
+ }
+}
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImplBeanInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImplBeanInfo.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImplBeanInfo.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBuilderParametersBeanInfo.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBuilderParametersBeanInfo.java?rev=1416265&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBuilderParametersBeanInfo.java (added)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBuilderParametersBeanInfo.java Sun Dec 2 21:21:16 2012
@@ -0,0 +1,75 @@
+/*
+ * 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.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+
+/**
+ * Test class for {@code BuilderParametersBeanInfo}.
+ *
+ * @version $Id$
+ */
+public class TestBuilderParametersBeanInfo
+{
+ /**
+ * Tests whether additional BeanInfo for all properties is available.
+ */
+ @Test
+ public void testFindAllProperties() throws IntrospectionException
+ {
+ BeanInfo info = Introspector.getBeanInfo(ParametersBeanTestImpl.class);
+ Map<String, PropertyDescriptor> properties =
+ new HashMap<String, PropertyDescriptor>();
+ for (PropertyDescriptor pd : info.getPropertyDescriptors())
+ {
+ properties.put(pd.getName(), pd);
+ }
+ PropertyDescriptor pd = fetchDescriptor(properties, "intProperty");
+ assertNotNull("No read method", pd.getReadMethod());
+ pd = fetchDescriptor(properties, "logger");
+ assertNull("Got a read method for logger", pd.getReadMethod());
+ fetchDescriptor(properties, "throwExceptionOnMissing");
+ pd = fetchDescriptor(properties, "fluentProperty");
+ assertNull("Got a read method for fluentProperty", pd.getReadMethod());
+ }
+
+ /**
+ * Returns the descriptor for the property with the given name from the map
+ * or fails if property is unknown.
+ *
+ * @param properties the map with property descriptors
+ * @param name the name of the property
+ * @return the descriptor for this property
+ */
+ private static PropertyDescriptor fetchDescriptor(
+ Map<String, PropertyDescriptor> properties, String name)
+ {
+ assertTrue("Property not found: " + name, properties.containsKey(name));
+ return properties.get(name);
+ }
+}
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBuilderParametersBeanInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBuilderParametersBeanInfo.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBuilderParametersBeanInfo.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestBaseConfigurationBuilderProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestBaseConfigurationBuilderProvider.java?rev=1416265&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestBaseConfigurationBuilderProvider.java (added)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestBaseConfigurationBuilderProvider.java Sun Dec 2 21:21:16 2012
@@ -0,0 +1,274 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+
+import org.apache.commons.configuration.BaseHierarchicalConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationAssert;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.configuration.builder.BasicBuilderParameters;
+import org.apache.commons.configuration.builder.BasicConfigurationBuilder;
+import org.apache.commons.configuration.builder.ConfigurationBuilder;
+import org.apache.commons.configuration.builder.FileBasedBuilderParameters;
+import org.apache.commons.configuration.builder.FileBasedConfigurationBuilder;
+import org.apache.commons.configuration.builder.ReloadingFileBasedConfigurationBuilder;
+import org.junit.Test;
+
+/**
+ * Test class for {@code BaseConfigurationBuilderProvider}.
+ *
+ * @version $Id$
+ */
+public class TestBaseConfigurationBuilderProvider
+{
+ /**
+ * Creates a configuration object describing a configuration source.
+ *
+ * @param reload a flag whether reload operations are supported
+ * @return the configuration object
+ */
+ private HierarchicalConfiguration setUpConfig(boolean reload)
+ {
+ HierarchicalConfiguration config = new BaseHierarchicalConfiguration();
+ config.addProperty(CombinedConfigurationBuilder.ATTR_RELOAD,
+ Boolean.valueOf(reload));
+ config.addProperty("[@delimiterParsingDisabled]", Boolean.TRUE);
+ config.addProperty("[@listDelimiter]", ';');
+ config.addProperty("[@path]",
+ ConfigurationAssert.getTestFile("test.properties")
+ .getAbsolutePath());
+ return config;
+ }
+
+ /**
+ * Creates a configuration declaration based on the given configuration.
+ *
+ * @param declConfig the configuration for the declaration
+ * @return the declaration
+ */
+ private ConfigurationDeclaration createDeclaration(
+ HierarchicalConfiguration declConfig)
+ {
+ ConfigurationDeclaration decl =
+ new ConfigurationDeclaration(null, declConfig)
+ {
+ @Override
+ protected Object interpolate(Object value)
+ {
+ return value;
+ }
+ };
+ return decl;
+ }
+
+ /**
+ * Creates a default test instance.
+ *
+ * @return the test instance
+ */
+ private BaseConfigurationBuilderProvider createProvider()
+ {
+ return new BaseConfigurationBuilderProvider(
+ FileBasedConfigurationBuilder.class.getName(),
+ ReloadingFileBasedConfigurationBuilder.class.getName(),
+ PropertiesConfiguration.class.getName(),
+ Arrays.asList(FileBasedBuilderParameters.class.getName()));
+ }
+
+ /**
+ * Helper method for setting up a builder and checking properties of the
+ * created configuration object.
+ *
+ * @param reload a flag whether reloading is supported
+ * @return the builder created by the provider
+ * @throws ConfigurationException if an error occurs
+ */
+ private ConfigurationBuilder<? extends Configuration> checkBuilder(
+ boolean reload) throws ConfigurationException
+ {
+ HierarchicalConfiguration declConfig = setUpConfig(reload);
+ ConfigurationDeclaration decl = createDeclaration(declConfig);
+ ConfigurationBuilder<? extends Configuration> builder =
+ createProvider().getConfiguration(decl);
+ Configuration config = builder.getConfiguration();
+ assertEquals("Wrong configuration class",
+ PropertiesConfiguration.class, config.getClass());
+ PropertiesConfiguration pconfig = (PropertiesConfiguration) config;
+ assertTrue("Wrong delimiter parsing flag",
+ pconfig.isDelimiterParsingDisabled());
+ assertEquals("Wrong list delimiter", ';', pconfig.getListDelimiter());
+ assertTrue("Configuration not loaded",
+ pconfig.getBoolean("configuration.loaded"));
+ return builder;
+ }
+
+ /**
+ * Tries to create an instance without a builder class.
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testInitNoBuilderClass()
+ {
+ new BaseConfigurationBuilderProvider(null, null,
+ PropertiesConfiguration.class.getName(), null);
+ }
+
+ /**
+ * Tries to create an instance without a configuration class.
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testInitNoConfigurationClass()
+ {
+ new BaseConfigurationBuilderProvider(BasicConfigurationBuilder.class.getName(),
+ null, null, null);
+ }
+
+ /**
+ * Tests whether a builder without reloading support can be created.
+ */
+ @Test
+ public void testGetBuilderNotReloading() throws ConfigurationException
+ {
+ ConfigurationBuilder<? extends Configuration> builder =
+ checkBuilder(false);
+ assertEquals("Wrong builder class",
+ FileBasedConfigurationBuilder.class, builder.getClass());
+ }
+
+ /**
+ * Tests whether a builder with reloading support can be created.
+ */
+ @Test
+ public void testGetBuilderReloading() throws ConfigurationException
+ {
+ ConfigurationBuilder<? extends Configuration> builder =
+ checkBuilder(true);
+ assertEquals("Wrong builder class",
+ ReloadingFileBasedConfigurationBuilder.class,
+ builder.getClass());
+ }
+
+ /**
+ * Tries to create a reloading builder if this is not supported by the
+ * provider.
+ */
+ @Test(expected = ConfigurationException.class)
+ public void testGetReloadingBuilderNotSupported()
+ throws ConfigurationException
+ {
+ BaseConfigurationBuilderProvider provider =
+ new BaseConfigurationBuilderProvider(
+ FileBasedConfigurationBuilder.class.getName(), null,
+ PropertiesConfiguration.class.getName(),
+ Arrays.asList(FileBasedBuilderParameters.class
+ .getName()));
+ HierarchicalConfiguration declConfig = setUpConfig(true);
+ ConfigurationDeclaration decl = createDeclaration(declConfig);
+ provider.getConfiguration(decl);
+ }
+
+ /**
+ * Helper method for testing whether the builder's allowFailOnInit flag is
+ * set correctly.
+ *
+ * @param expFlag the expected flag value
+ * @param props the properties to set in the configuration for the
+ * declaration
+ * @throws ConfigurationException if an error occurs
+ */
+ private void checkAllowFailOnInit(boolean expFlag, String... props)
+ throws ConfigurationException
+ {
+ HierarchicalConfiguration declConfig = setUpConfig(false);
+ for (String key : props)
+ {
+ declConfig.addProperty(key, Boolean.TRUE);
+ }
+ ConfigurationDeclaration decl = createDeclaration(declConfig);
+ BasicConfigurationBuilder<? extends Configuration> builder =
+ (BasicConfigurationBuilder<? extends Configuration>) createProvider()
+ .getConfiguration(decl);
+ assertEquals("Wrong flag value", expFlag, builder.isAllowFailOnInit());
+ }
+
+ /**
+ * Tests that the allowFailOnInit flag is not set per default on the
+ * builder.
+ */
+ @Test
+ public void testGetBuilderNoFailOnInit() throws ConfigurationException
+ {
+ checkAllowFailOnInit(false);
+ }
+
+ /**
+ * Tests that the allowFailOnInit flag is not set for builders which are not
+ * optional.
+ */
+ public void testGetBuilderAllowFailOnInitNotOptional()
+ throws ConfigurationException
+ {
+ checkAllowFailOnInit(false,
+ CombinedConfigurationBuilder.ATTR_FORCECREATE);
+ }
+
+ /**
+ * Tests whether the allowFailOnInit flag can be enabled on the builder.
+ */
+ @Test
+ public void testGetBuilderAllowFailOnInit() throws ConfigurationException
+ {
+ checkAllowFailOnInit(true,
+ CombinedConfigurationBuilder.ATTR_OPTIONAL_RES,
+ CombinedConfigurationBuilder.ATTR_FORCECREATE);
+ }
+
+ /**
+ * Tests whether a null collection of parameter classes is handled
+ * correctly.
+ */
+ @Test
+ public void testInitNoParameterClasses()
+ {
+ BaseConfigurationBuilderProvider provider =
+ new BaseConfigurationBuilderProvider(
+ BasicConfigurationBuilder.class.getName(), null,
+ PropertiesConfiguration.class.getName(), null);
+ assertTrue("Got parameter classes", provider.getParameterClasses()
+ .isEmpty());
+ }
+
+ /**
+ * Tests that the collection with parameter classes cannot be modified.
+ */
+ @Test(expected = UnsupportedOperationException.class)
+ public void testGetParameterClassesModify()
+ {
+ BaseConfigurationBuilderProvider provider =
+ new BaseConfigurationBuilderProvider(
+ BasicConfigurationBuilder.class.getName(), null,
+ PropertiesConfiguration.class.getName(),
+ Arrays.asList(BasicBuilderParameters.class.getName()));
+ provider.getParameterClasses().clear();
+ }
+}
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestBaseConfigurationBuilderProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestBaseConfigurationBuilderProvider.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestBaseConfigurationBuilderProvider.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: 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/TestCombinedBuilderParameters.java?rev=1416265&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParameters.java (added)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParameters.java Sun Dec 2 21:21:16 2012
@@ -0,0 +1,90 @@
+/*
+ * 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 static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.configuration.builder.BasicConfigurationBuilder;
+import org.apache.commons.configuration.builder.ConfigurationBuilder;
+import org.junit.Test;
+
+/**
+ * Test class for {@code CombinedBuilderParameters}.
+ *
+ * @version $Id$
+ */
+public class TestCombinedBuilderParameters
+{
+ /**
+ * Tests fromParameters() if the map does not contain an instance.
+ */
+ @Test
+ public void testFromParametersNotFound()
+ {
+ assertNull("Got an instance",
+ CombinedBuilderParameters
+ .fromParameters(new HashMap<String, Object>()));
+ }
+
+ /**
+ * Tests whether a new instance can be created if none is found in the
+ * parameters map.
+ */
+ @Test
+ public void testFromParametersCreate()
+ {
+ CombinedBuilderParameters params =
+ CombinedBuilderParameters.fromParameters(
+ new HashMap<String, Object>(), true);
+ assertNotNull("No instance", params);
+ assertNull("Got data", params.getDefinitionBuilder());
+ }
+
+ /**
+ * Tests whether an instance can be obtained from a parameters map.
+ */
+ @Test
+ public void testFromParametersExisting()
+ {
+ CombinedBuilderParameters params = new CombinedBuilderParameters();
+ Map<String, Object> map = params.getParameters();
+ assertSame("Wrong result", params,
+ CombinedBuilderParameters.fromParameters(map));
+ }
+
+ /**
+ * Tests whether the definition builder can be set.
+ */
+ @Test
+ public void testSetDefinitionBuilder()
+ {
+ CombinedBuilderParameters params = new CombinedBuilderParameters();
+ assertNull("Got a definition builder", params.getDefinitionBuilder());
+ ConfigurationBuilder<XMLConfiguration> builder =
+ new BasicConfigurationBuilder<XMLConfiguration>(
+ XMLConfiguration.class);
+ assertSame("Wrong result", params, params.setDefinitionBuilder(builder));
+ assertSame("Builder was not set", builder,
+ params.getDefinitionBuilder());
+ }
+}
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParameters.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParameters.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParameters.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestConfigurationDeclaration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestConfigurationDeclaration.java?rev=1416265&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestConfigurationDeclaration.java (added)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestConfigurationDeclaration.java Sun Dec 2 21:21:16 2012
@@ -0,0 +1,165 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.commons.configuration.BaseHierarchicalConfiguration;
+import org.apache.commons.configuration.ConfigurationRuntimeException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.configuration.tree.DefaultConfigurationNode;
+import org.junit.Test;
+
+/**
+ * Test class for {@code ConfigurationDeclaration}.
+ *
+ * @version $Id$
+ */
+public class TestConfigurationDeclaration
+{
+ /**
+ * Creates a default test instance.
+ *
+ * @param conf the configuration to be used (may be <b>null</b> for a
+ * default one)
+ * @return the test object
+ */
+ private static ConfigurationDeclaration createDeclaration(
+ HierarchicalConfiguration conf)
+ {
+ HierarchicalConfiguration config =
+ (conf != null) ? conf : new BaseHierarchicalConfiguration();
+ return new ConfigurationDeclaration(null, config);
+ }
+
+ /**
+ * Tests the isReservedNode() method of ConfigurationDeclaration.
+ */
+ @Test
+ public void testConfigurationDeclarationIsReserved()
+ {
+ ConfigurationDeclaration decl = createDeclaration(null);
+ DefaultConfigurationNode parent = new DefaultConfigurationNode();
+ DefaultConfigurationNode nd = new DefaultConfigurationNode("at");
+ parent.addAttribute(nd);
+ assertTrue("Attribute at not recognized", decl.isReservedNode(nd));
+ nd = new DefaultConfigurationNode("optional");
+ parent.addAttribute(nd);
+ assertTrue("Attribute optional not recognized", decl.isReservedNode(nd));
+ nd = new DefaultConfigurationNode("config-class");
+ parent.addAttribute(nd);
+ assertTrue("Inherited attribute not recognized",
+ decl.isReservedNode(nd));
+ nd = new DefaultConfigurationNode("different");
+ parent.addAttribute(nd);
+ assertFalse("Wrong reserved attribute", decl.isReservedNode(nd));
+ nd = new DefaultConfigurationNode("at");
+ parent.addChild(nd);
+ assertFalse("Node type not evaluated", decl.isReservedNode(nd));
+ }
+
+ /**
+ * Tests if the at attribute is correctly detected as reserved attribute.
+ */
+ @Test
+ public void testConfigurationDeclarationIsReservedAt()
+ {
+ checkOldReservedAttribute("at");
+ }
+
+ /**
+ * Tests if the optional attribute is correctly detected as reserved
+ * attribute.
+ */
+ @Test
+ public void testConfigurationDeclarationIsReservedOptional()
+ {
+ checkOldReservedAttribute("optional");
+ }
+
+ /**
+ * Tests if special reserved attributes are recognized by the
+ * isReservedNode() method. For compatibility reasons the attributes "at"
+ * and "optional" are also treated as reserved attributes, but only if there
+ * are no corresponding attributes with the "config-" prefix.
+ *
+ * @param name the attribute name
+ */
+ private void checkOldReservedAttribute(String name)
+ {
+ ConfigurationDeclaration decl = createDeclaration(null);
+ DefaultConfigurationNode parent = new DefaultConfigurationNode();
+ DefaultConfigurationNode nd =
+ new DefaultConfigurationNode("config-" + name);
+ parent.addAttribute(nd);
+ assertTrue("config-" + name + " attribute not recognized",
+ decl.isReservedNode(nd));
+ DefaultConfigurationNode nd2 = new DefaultConfigurationNode(name);
+ parent.addAttribute(nd2);
+ assertFalse(name + " is reserved though config- exists",
+ decl.isReservedNode(nd2));
+ assertTrue("config- attribute not recognized when " + name + " exists",
+ decl.isReservedNode(nd));
+ }
+
+ /**
+ * Tests access to certain reserved attributes of a
+ * ConfigurationDeclaration.
+ */
+ @Test
+ public void testConfigurationDeclarationGetAttributes()
+ {
+ HierarchicalConfiguration config = new BaseHierarchicalConfiguration();
+ config.addProperty("xml.fileName", "test.xml");
+ ConfigurationDeclaration decl =
+ createDeclaration(config.configurationAt("xml"));
+ assertNull("Found an at attribute", decl.getAt());
+ assertFalse("Found an optional attribute", decl.isOptional());
+ config.addProperty("xml[@config-at]", "test1");
+ assertEquals("Wrong value of at attribute", "test1", decl.getAt());
+ config.addProperty("xml[@at]", "test2");
+ assertEquals("Wrong value of config-at attribute", "test1",
+ decl.getAt());
+ config.clearProperty("xml[@config-at]");
+ assertEquals("Old at attribute not detected", "test2", decl.getAt());
+ config.addProperty("xml[@config-optional]", "true");
+ assertTrue("Wrong value of optional attribute", decl.isOptional());
+ config.addProperty("xml[@optional]", "false");
+ assertTrue("Wrong value of config-optional attribute",
+ decl.isOptional());
+ config.clearProperty("xml[@config-optional]");
+ config.setProperty("xml[@optional]", Boolean.TRUE);
+ assertTrue("Old optional attribute not detected", decl.isOptional());
+ }
+
+ /**
+ * Tests whether an invalid value of an optional attribute is detected.
+ */
+ @Test(expected = ConfigurationRuntimeException.class)
+ public void testConfigurationDeclarationOptionalAttributeInvalid()
+ {
+ HierarchicalConfiguration factory = new BaseHierarchicalConfiguration();
+ factory.addProperty("xml.fileName", "test.xml");
+ ConfigurationDeclaration decl =
+ createDeclaration(factory.configurationAt("xml"));
+ factory.setProperty("xml[@optional]", "invalid value");
+ decl.isOptional();
+ }
+}
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestConfigurationDeclaration.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestConfigurationDeclaration.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestConfigurationDeclaration.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestFileExtensionConfigurationBuilderProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestFileExtensionConfigurationBuilderProvider.java?rev=1416265&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestFileExtensionConfigurationBuilderProvider.java (added)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestFileExtensionConfigurationBuilderProvider.java Sun Dec 2 21:21:16 2012
@@ -0,0 +1,246 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Locale;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.configuration.XMLPropertiesConfiguration;
+import org.apache.commons.configuration.builder.BasicConfigurationBuilder;
+import org.apache.commons.configuration.builder.BuilderParameters;
+import org.apache.commons.configuration.builder.FileBasedBuilderParameters;
+import org.apache.commons.configuration.builder.ReloadingFileBasedConfigurationBuilder;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+/**
+ * Test class for {@code FileExtensionConfigurationBuilderProvider}.
+ *
+ * @version $Id$
+ */
+public class TestFileExtensionConfigurationBuilderProvider
+{
+ /** Constant for the name of the default configuration class. */
+ private static final String DEF_CLASS = PropertiesConfiguration.class
+ .getName();
+
+ /** Constant for the name of the matching class. */
+ private static final String MATCH_CLASS = XMLPropertiesConfiguration.class
+ .getName();
+
+ /** The test file extension. */
+ private static final String EXT = "xml";
+
+ /**
+ * Creates a test instance with default settings.
+ *
+ * @return the test object
+ */
+ private static FileExtensionConfigurationBuilderProvider setUpProvider()
+ {
+ FileExtensionConfigurationBuilderProvider provider =
+ new FileExtensionConfigurationBuilderProvider(
+ BasicConfigurationBuilder.class.getName(), null,
+ MATCH_CLASS, DEF_CLASS, EXT, null);
+ return provider;
+ }
+
+ /**
+ * Creates a mock for the configuration declaration.
+ *
+ * @return the mock object
+ */
+ private ConfigurationDeclaration setUpDecl()
+ {
+ ConfigurationDeclaration decl =
+ EasyMock.createMock(ConfigurationDeclaration.class);
+ EasyMock.replay(decl);
+ return decl;
+ }
+
+ /**
+ * Tries to create an instance without the matching configuration class.
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testInitNoMatchingConfigClass()
+ {
+ new FileExtensionConfigurationBuilderProvider(
+ BasicConfigurationBuilder.class.getName(), null, null,
+ DEF_CLASS, EXT, null);
+ }
+
+ /**
+ * Tries to create an instance without the default configuration class.
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testInitNoDefaultConfigClass()
+ {
+ new FileExtensionConfigurationBuilderProvider(
+ BasicConfigurationBuilder.class.getName(), null, MATCH_CLASS,
+ null, EXT, null);
+ }
+
+ /**
+ * Tries to create an instance without a file extension.
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testInitNoExt()
+ {
+ new FileExtensionConfigurationBuilderProvider(
+ BasicConfigurationBuilder.class.getName(), null, MATCH_CLASS,
+ DEF_CLASS, null, null);
+ }
+
+ /**
+ * Tests whether the super class is correctly initialized.
+ */
+ @Test
+ public void testInitSuper()
+ {
+ FileExtensionConfigurationBuilderProvider provider =
+ new FileExtensionConfigurationBuilderProvider(
+ BasicConfigurationBuilder.class.getName(),
+ ReloadingFileBasedConfigurationBuilder.class.getName(),
+ MATCH_CLASS, DEF_CLASS, EXT, null);
+ assertEquals("Wrong builder class",
+ BasicConfigurationBuilder.class.getName(),
+ provider.getBuilderClass());
+ assertEquals("Wrong reloading builder class",
+ ReloadingFileBasedConfigurationBuilder.class.getName(),
+ provider.getReloadingBuilderClass());
+ assertEquals("Wrong configuration class", DEF_CLASS,
+ provider.getConfigurationClass());
+ }
+
+ /**
+ * Tests whether the correct configuration class is selected if no
+ * file-based parameters are provided.
+ */
+ @Test
+ public void testDetermineConfigurationClassNoParams()
+ throws ConfigurationException
+ {
+ ConfigurationDeclaration decl = setUpDecl();
+ FileExtensionConfigurationBuilderProvider provider = setUpProvider();
+ assertEquals("Wrong class", DEF_CLASS,
+ provider.determineConfigurationClass(decl,
+ new ArrayList<BuilderParameters>()));
+ }
+
+ /**
+ * Tests whether the correct configuration class is selected if the file
+ * name does not have an extension.
+ */
+ @Test
+ public void testDetermineConfigurationClassNoExtension()
+ throws ConfigurationException
+ {
+ ConfigurationDeclaration decl = setUpDecl();
+ BuilderParameters params =
+ new FileBasedBuilderParameters()
+ .setPath("C:\\Test\\someTestConfiguration");
+ FileExtensionConfigurationBuilderProvider provider = setUpProvider();
+ assertEquals(
+ "Wrong class",
+ DEF_CLASS,
+ provider.determineConfigurationClass(decl,
+ Collections.singleton(params)));
+ }
+
+ /**
+ * Tests whether the correct configuration class is selected if the file
+ * extension does not match.
+ */
+ @Test
+ public void testDetermineConfigurationClassExtensionNoMatch()
+ throws ConfigurationException
+ {
+ ConfigurationDeclaration decl = setUpDecl();
+ BuilderParameters params =
+ new FileBasedBuilderParameters()
+ .setPath("C:\\Test\\someTestConfiguration.properties");
+ FileExtensionConfigurationBuilderProvider provider = setUpProvider();
+ assertEquals(
+ "Wrong class",
+ DEF_CLASS,
+ provider.determineConfigurationClass(decl,
+ Collections.singleton(params)));
+ }
+
+ /**
+ * Tests whether the correct configuration class is selected if no file name
+ * is set.
+ */
+ @Test
+ public void testDeterminieConfigurationClassNoFileName()
+ throws ConfigurationException
+ {
+ ConfigurationDeclaration decl = setUpDecl();
+ BuilderParameters params = new FileBasedBuilderParameters();
+ FileExtensionConfigurationBuilderProvider provider = setUpProvider();
+ assertEquals(
+ "Wrong class",
+ DEF_CLASS,
+ provider.determineConfigurationClass(decl,
+ Collections.singleton(params)));
+ }
+
+ /**
+ * Tests whether the correct configuration class is selected if the file
+ * extension matches.
+ */
+ @Test
+ public void testDetermineConfigurationClassExtensionMatch()
+ throws ConfigurationException
+ {
+ ConfigurationDeclaration decl = setUpDecl();
+ BuilderParameters params =
+ new FileBasedBuilderParameters()
+ .setPath("C:\\Test\\someTestConfiguration." + EXT);
+ FileExtensionConfigurationBuilderProvider provider = setUpProvider();
+ assertEquals(
+ "Wrong class",
+ MATCH_CLASS,
+ provider.determineConfigurationClass(decl,
+ Collections.singleton(params)));
+ }
+
+ /**
+ * Tests that matches of file extensions are case insensitive.
+ */
+ @Test
+ public void testDetermineConfigurationClassMatchCase()
+ throws ConfigurationException
+ {
+ ConfigurationDeclaration decl = setUpDecl();
+ BuilderParameters params =
+ new FileBasedBuilderParameters()
+ .setPath("C:\\Test\\someTestConfiguration."
+ + EXT.toUpperCase(Locale.ENGLISH));
+ FileExtensionConfigurationBuilderProvider provider = setUpProvider();
+ assertEquals(
+ "Wrong class",
+ MATCH_CLASS,
+ provider.determineConfigurationClass(decl,
+ Collections.singleton(params)));
+ }
+}
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestFileExtensionConfigurationBuilderProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestFileExtensionConfigurationBuilderProvider.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestFileExtensionConfigurationBuilderProvider.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiWrapDynaBean.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiWrapDynaBean.java?rev=1416265&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiWrapDynaBean.java (added)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiWrapDynaBean.java Sun Dec 2 21:21:16 2012
@@ -0,0 +1,255 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.beanutils.DynaClass;
+import org.apache.commons.beanutils.LazyDynaBean;
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.configuration.builder.BasicBuilderParameters;
+import org.junit.Test;
+
+/**
+ * Test class for {@code MultiWrapDynaBean} and {@code MultiWrapDynaClass}.
+ *
+ * @version $Id$
+ */
+public class TestMultiWrapDynaBean
+{
+ /** Constant for a mapped property. */
+ private static final String MAPPED_PROPERTY = "testMappedProperty";
+
+ /** A test wrapped bean. */
+ private BasicBuilderParameters params;
+
+ /** Another test wrapped bean. */
+ private WrappedBeanTestImpl wrapBean;
+
+ /** A wrapped DynaBean. */
+ private LazyDynaBean wrapDynaBean;
+
+ /**
+ * Creates a new test object with a list of wrapped beans.
+ *
+ * @param withDynaBean a flag whether also a DynaBean should be added to the
+ * wrapped beans
+ * @return the test bean
+ */
+ private MultiWrapDynaBean createBean(boolean withDynaBean)
+ {
+ params = new BasicBuilderParameters();
+ wrapBean = new WrappedBeanTestImpl();
+ Collection<Object> beans = new ArrayList<Object>();
+ beans.add(params);
+ beans.add(wrapBean);
+ if (withDynaBean)
+ {
+ wrapDynaBean = new LazyDynaBean();
+ wrapDynaBean.set(MAPPED_PROPERTY, "someKey", "somValue");
+ beans.add(wrapDynaBean);
+ }
+ return new MultiWrapDynaBean(beans);
+ }
+
+ /**
+ * Tests whether a simple property can be set.
+ */
+ @Test
+ public void testSetSimpleProperty() throws Exception
+ {
+ PropertyUtils.setProperty(createBean(false), "throwExceptionOnMissing",
+ Boolean.TRUE);
+ assertEquals("Property not set", Boolean.TRUE, params.getParameters()
+ .get("throwExceptionOnMissing"));
+ }
+
+ /**
+ * Tests whether a simple property can be read.
+ */
+ @Test
+ public void testGetSimpleProperty() throws Exception
+ {
+ MultiWrapDynaBean bean = createBean(false);
+ String text = "testText";
+ wrapBean.setText(text);
+ assertEquals("Wrong value", text,
+ PropertyUtils.getProperty(bean, "text"));
+ }
+
+ /**
+ * Tests whether an indexed property can be set.
+ */
+ @Test
+ public void testSetIndexedProperty() throws Exception
+ {
+ PropertyUtils.setIndexedProperty(createBean(false), "indexedProperty",
+ 1, 42);
+ assertEquals("Property not set", 42, wrapBean.getIndexedProperty(1));
+ }
+
+ /**
+ * Tests whether an indexed property can be read.
+ */
+ @Test
+ public void testGetIndexedProperty() throws Exception
+ {
+ MultiWrapDynaBean bean = createBean(false);
+ wrapBean.setIndexedProperty(3, 20121117);
+ assertEquals("Wrong value", 20121117,
+ PropertyUtils.getIndexedProperty(bean, "indexedProperty", 3));
+ }
+
+ /**
+ * Tests whether a map property can be set.
+ */
+ @Test
+ public void testSetMappedProperty() throws Exception
+ {
+ MultiWrapDynaBean bean = createBean(true);
+ String key = "testKey";
+ String text = "Hello World";
+ PropertyUtils.setMappedProperty(bean, MAPPED_PROPERTY, key, text);
+ assertEquals("Property not set", text,
+ wrapDynaBean.get(MAPPED_PROPERTY, key));
+ }
+
+ /**
+ * Tests whether a map property can be read.
+ */
+ @Test
+ public void testGetMappedProperty() throws Exception
+ {
+ MultiWrapDynaBean bean = createBean(true);
+ String key = "testKey";
+ String value = "Hello World";
+ wrapDynaBean.set(MAPPED_PROPERTY, key, value);
+ assertEquals("Wrong value", value,
+ PropertyUtils.getMappedProperty(bean, MAPPED_PROPERTY, key));
+ }
+
+ /**
+ * Tries to access an unknown property.
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetPropertyUnknown()
+ {
+ createBean(false).get("unknown property");
+ }
+
+ /**
+ * Tests whether the class of bean can be queried.
+ */
+ @Test
+ public void testGetDynaClass()
+ {
+ DynaClass cls = createBean(false).getDynaClass();
+ assertNotNull("Property not found (1)",
+ cls.getDynaProperty("throwExceptionOnMissing"));
+ assertNotNull("Property not found (2)", cls.getDynaProperty("text"));
+ }
+
+ /**
+ * Tries to create a new instance of the DynaClass. This is not possible.
+ */
+ @Test(expected = UnsupportedOperationException.class)
+ public void testGetDynaClassNewInstance() throws Exception
+ {
+ createBean(false).getDynaClass().newInstance();
+ }
+
+ /**
+ * Checks the name of the DynaClass.
+ */
+ @Test
+ public void testGetDynaClassName()
+ {
+ assertNull("Got a class name", createBean(false).getDynaClass()
+ .getName());
+ }
+
+ /**
+ * Tests the remove() implementation. This operation is not available.
+ */
+ @Test(expected = UnsupportedOperationException.class)
+ public void testRemove()
+ {
+ createBean(false).remove(MAPPED_PROPERTY, "someKey");
+ }
+
+ /**
+ * Tests the contains() implementation. This operation is not available.
+ */
+ @Test(expected = UnsupportedOperationException.class)
+ public void testContains()
+ {
+ createBean(false).contains(MAPPED_PROPERTY, "someKey");
+ }
+
+ /**
+ * A simple test bean class used as wrapped bean.
+ */
+ public static class WrappedBeanTestImpl
+ {
+ /** Stores mapped properties. */
+ private final Map<String, String> mapProperties =
+ new HashMap<String, String>();
+
+ /** Stores indexed properties. */
+ private final int[] indexedValues = new int[8];
+
+ /** A simple property. */
+ private String text;
+
+ public String getMapProperty(String key)
+ {
+ return mapProperties.get(key);
+ }
+
+ public void setMapProperty(String key, String value)
+ {
+ mapProperties.put(key, value);
+ }
+
+ public int getIndexedProperty(int idx)
+ {
+ return indexedValues[idx];
+ }
+
+ public void setIndexedProperty(int idx, int value)
+ {
+ indexedValues[idx] = value;
+ }
+
+ public String getText()
+ {
+ return text;
+ }
+
+ public void setText(String text)
+ {
+ this.text = text;
+ }
+ }
+}
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiWrapDynaBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiWrapDynaBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiWrapDynaBean.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: commons/proper/configuration/trunk/src/test/resources/testDigesterConfiguration.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/resources/testDigesterConfiguration.xml?rev=1416265&r1=1416264&r2=1416265&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/resources/testDigesterConfiguration.xml (original)
+++ commons/proper/configuration/trunk/src/test/resources/testDigesterConfiguration.xml Sun Dec 2 21:21:16 2012
@@ -17,7 +17,7 @@
-->
<configuration>
- <properties fileName="test.properties"/>
+ <properties fileName="test.properties" config-name="props"/>
<properties fileName="test.properties.xml"/>
- <xml fileName="test.xml"/>
+ <xml fileName="test.xml" config-name="xml"/>
</configuration>