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/08/19 16:31:01 UTC
svn commit: r1515442 - in
/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration:
TestAbstractConfigurationBasicFeatures.java
convert/TestPropertyConverter.java
Author: oheger
Date: Mon Aug 19 14:31:01 2013
New Revision: 1515442
URL: http://svn.apache.org/r1515442
Log:
Moved tests related to interpolation.
The tests affected test basic interpolation functionality. Therefore, they were
moved from TestPropertyConverter to TestAbstractConfigurationBasicFeatures.
Modified:
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/convert/TestPropertyConverter.java
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java?rev=1515442&r1=1515441&r2=1515442&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java Mon Aug 19 14:31:01 2013
@@ -47,6 +47,9 @@ import org.junit.Test;
*/
public class TestAbstractConfigurationBasicFeatures
{
+ /** Constant for text to be used in tests for variable substitution. */
+ private static final String SUBST_TXT = "The ${animal} jumps over the ${target}.";
+
/** Constant for the prefix of test keys.*/
private static final String KEY_PREFIX = "key";
@@ -549,6 +552,85 @@ public class TestAbstractConfigurationBa
}
/**
+ * Tests the interpolation features.
+ */
+ @Test
+ public void testInterpolateString()
+ {
+ PropertiesConfiguration config = new PropertiesConfiguration();
+ config.addProperty("animal", "quick brown fox");
+ config.addProperty("target", "lazy dog");
+ config.addProperty(KEY_PREFIX, SUBST_TXT);
+ assertEquals("Wrong interpolation",
+ "The quick brown fox jumps over the lazy dog.",
+ config.getString(KEY_PREFIX));
+ }
+
+ /**
+ * Tests complex interpolation where the variables' values contain in turn
+ * other variables.
+ */
+ @Test
+ public void testInterpolateRecursive()
+ {
+ PropertiesConfiguration config = new PropertiesConfiguration();
+ config.addProperty("animal", "${animal_attr} fox");
+ config.addProperty("target", "${target_attr} dog");
+ config.addProperty("animal_attr", "quick brown");
+ config.addProperty("target_attr", "lazy");
+ config.addProperty(KEY_PREFIX, SUBST_TXT);
+ assertEquals("Wrong complex interpolation",
+ "The quick brown fox jumps over the lazy dog.",
+ config.getString(KEY_PREFIX));
+ }
+
+ /**
+ * Tests an interpolation that leads to a cycle. This should throw an
+ * exception.
+ */
+ @Test(expected = IllegalStateException.class)
+ public void testCyclicInterpolation()
+ {
+ PropertiesConfiguration config = new PropertiesConfiguration();
+ config.addProperty("animal", "${animal_attr} ${species}");
+ config.addProperty("animal_attr", "quick brown");
+ config.addProperty("species", "${animal}");
+ config.addProperty(KEY_PREFIX, "This is a ${animal}");
+ config.getString(KEY_PREFIX);
+ }
+
+ /**
+ * Tests interpolation if a variable is unknown. Then the variable won't be
+ * substituted.
+ */
+ @Test
+ public void testInterpolationUnknownVariable()
+ {
+ PropertiesConfiguration config = new PropertiesConfiguration();
+ config.addProperty("animal", "quick brown fox");
+ config.addProperty(KEY_PREFIX, SUBST_TXT);
+ assertEquals("Wrong interpolation",
+ "The quick brown fox jumps over the ${target}.",
+ config.getString(KEY_PREFIX));
+ }
+
+ /**
+ * Tests interpolate() if the configuration does not have a
+ * {@code ConfigurationInterpolator}.
+ */
+ @Test
+ public void testInterpolationNoInterpolator()
+ {
+ PropertiesConfiguration config = new PropertiesConfiguration();
+ config.addProperty("animal", "quick brown fox");
+ config.addProperty("target", "lazy dog");
+ config.addProperty(KEY_PREFIX, SUBST_TXT);
+ config.setInterpolator(null);
+ assertEquals("Interpolation was performed", SUBST_TXT,
+ config.getString(KEY_PREFIX));
+ }
+
+ /**
* Creates the source configuration for testing the copy() and append()
* methods. This configuration contains keys with an odd index and values
* starting with the prefix "src". There are also some list properties.
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/convert/TestPropertyConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/convert/TestPropertyConverter.java?rev=1515442&r1=1515441&r2=1515442&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/convert/TestPropertyConverter.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/convert/TestPropertyConverter.java Mon Aug 19 14:31:01 2013
@@ -23,9 +23,6 @@ import static org.junit.Assert.assertSam
import java.lang.annotation.ElementType;
import java.math.BigDecimal;
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.commons.configuration.convert.ConversionException;
-import org.apache.commons.configuration.convert.PropertyConverter;
import org.junit.Test;
/**
@@ -40,91 +37,6 @@ public class TestPropertyConverter
private static final Class<ElementType> ENUM_CLASS = ElementType.class;
/**
- * Tests the interpolation features.
- */
- @Test
- public void testInterpolateString()
- {
- PropertiesConfiguration config = new PropertiesConfiguration();
- config.addProperty("animal", "quick brown fox");
- config.addProperty("target", "lazy dog");
- assertEquals("Wrong interpolation",
- "The quick brown fox jumps over the lazy dog.",
- PropertyConverter.interpolate("The ${animal} jumps over the ${target}.", config));
- }
-
- /**
- * Tests interpolation of an object. Here nothing should be substituted.
- */
- @Test
- public void testInterpolateObject()
- {
- assertEquals("Object was not correctly interpolated", new Integer(42),
- PropertyConverter.interpolate(new Integer(42), new PropertiesConfiguration()));
- }
-
- /**
- * Tests complex interpolation where the variables' values contain in turn
- * other variables.
- */
- @Test
- public void testInterpolateRecursive()
- {
- PropertiesConfiguration config = new PropertiesConfiguration();
- config.addProperty("animal", "${animal_attr} fox");
- config.addProperty("target", "${target_attr} dog");
- config.addProperty("animal_attr", "quick brown");
- config.addProperty("target_attr", "lazy");
- assertEquals("Wrong complex interpolation",
- "The quick brown fox jumps over the lazy dog.",
- PropertyConverter.interpolate("The ${animal} jumps over the ${target}.", config));
- }
-
- /**
- * Tests an interpolation that leads to a cycle. This should throw an
- * exception.
- */
- @Test(expected = IllegalStateException.class)
- public void testCyclicInterpolation()
- {
- PropertiesConfiguration config = new PropertiesConfiguration();
- config.addProperty("animal", "${animal_attr} ${species}");
- config.addProperty("animal_attr", "quick brown");
- config.addProperty("species", "${animal}");
- PropertyConverter.interpolate("This is a ${animal}", config);
- }
-
- /**
- * Tests interpolation if a variable is unknown. Then the variable won't be
- * substituted.
- */
- @Test
- public void testInterpolationUnknownVariable()
- {
- PropertiesConfiguration config = new PropertiesConfiguration();
- config.addProperty("animal", "quick brown fox");
- assertEquals("Wrong interpolation",
- "The quick brown fox jumps over ${target}.",
- PropertyConverter.interpolate("The ${animal} jumps over ${target}.", config));
- }
-
- /**
- * Tests interpolate() if the configuration does not have a
- * {@code ConfigurationInterpolator}.
- */
- @Test
- public void testInterpolationNoInterpolator()
- {
- PropertiesConfiguration config = new PropertiesConfiguration();
- config.addProperty("animal", "quick brown fox");
- config.addProperty("target", "lazy dog");
- config.setInterpolator(null);
- String txt = "The ${animal} jumps over the ${target}.";
- assertEquals("Interpolation was performed", txt,
- PropertyConverter.interpolate(txt, config));
- }
-
- /**
* Tests interpolate() if the passed in configuration is null.
*/
@Test