You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by eb...@apache.org on 2005/09/26 19:15:39 UTC
svn commit: r291679 - in /jakarta/commons/proper/configuration/trunk:
src/java/org/apache/commons/configuration/
src/java/org/apache/commons/configuration/beanutils/
src/test/org/apache/commons/configuration/
src/test/org/apache/commons/configuration/b...
Author: ebourg
Date: Mon Sep 26 10:15:28 2005
New Revision: 291679
URL: http://svn.apache.org/viewcvs?rev=291679&view=rev
Log:
Interpolation for getList()
Custom list delimiter for ConfigurationConverter.getProperties();
Modified:
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationConverter.java
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/ConfigurationDynaBean.java
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationConverter.java
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestConfigurationDynaBean.java
jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java?rev=291679&r1=291678&r2=291679&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java Mon Sep 26 10:15:28 2005
@@ -114,9 +114,9 @@
* provide write acces to underlying Configuration store.
*
* @param key key to use for mapping
- * @param obj object to store
+ * @param value object to store
*/
- protected abstract void addPropertyDirect(String key, Object obj);
+ protected abstract void addPropertyDirect(String key, Object value);
/**
* interpolate key names to handle ${key} stuff
@@ -161,7 +161,6 @@
int begin = -1;
int end = -1;
int prec = 0 - END_TOKEN.length();
- String variable = null;
StringBuffer result = new StringBuffer();
// FIXME: we should probably allow the escaping of the start token
@@ -169,7 +168,7 @@
&& ((end = base.indexOf(END_TOKEN, begin)) > -1))
{
result.append(base.substring(prec + END_TOKEN.length(), begin));
- variable = base.substring(begin + START_TOKEN.length(), end);
+ String variable = base.substring(begin + START_TOKEN.length(), end);
// if we've got a loop, create a useful exception message and throw
if (priorVariables.contains(variable))
@@ -872,16 +871,30 @@
public List getList(String key, List defaultValue)
{
Object value = getProperty(key);
- List list = null;
+ List list;
if (value instanceof String)
{
list = new ArrayList(1);
- list.add(value);
+ list.add(interpolate((String) value));
}
else if (value instanceof List)
{
- list = (List) value;
+ list = new ArrayList();
+ List l = (List) value;
+
+ // add the interpolated elements in the new list
+ Iterator it = l.iterator();
+ while (it.hasNext())
+ {
+ Object element = it.next();
+ if (element instanceof String) {
+ list.add(interpolate((String) element));
+ } else {
+ list.add(element);
+ }
+ }
+
}
else if (value == null)
{
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationConverter.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationConverter.java?rev=291679&r1=291678&r2=291679&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationConverter.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationConverter.java Mon Sep 26 10:15:28 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
import java.util.Vector;
import org.apache.commons.collections.ExtendedProperties;
+import org.apache.commons.lang.StringUtils;
/**
* Configuration converter. Helper class to convert between Configuration,
@@ -90,8 +91,9 @@
}
/**
- * Convert a Configuration class into a Properties class. Multivalue keys
- * will be collapsed into comma separated values.
+ * Convert a Configuration class into a Properties class. List properties
+ * are joined into a string using the delimiter of the configuration if it
+ * extends AbstractConfiguration, and a comma otherwise.
*
* @param config Configuration object to convert
* @return Properties created from the Configuration
@@ -100,26 +102,16 @@
{
Properties props = new Properties();
- Iterator keys = config.getKeys();
+ char delimiter = (config instanceof AbstractConfiguration) ? ((AbstractConfiguration) config).getDelimiter() : ',';
+ Iterator keys = config.getKeys();
while (keys.hasNext())
{
String key = (String) keys.next();
List list = config.getList(key);
- // turn lists into a string
- StringBuffer property = new StringBuffer();
- Iterator it = list.iterator();
- while (it.hasNext())
- {
- property.append(String.valueOf(it.next()));
- if (it.hasNext())
- {
- property.append(", ");
- }
- }
-
- props.setProperty(key, property.toString());
+ // turn the list into a string
+ props.setProperty(key, StringUtils.join(list.iterator(), delimiter));
}
return props;
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/ConfigurationDynaBean.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/ConfigurationDynaBean.java?rev=291679&r1=291678&r2=291679&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/ConfigurationDynaBean.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/ConfigurationDynaBean.java Mon Sep 26 10:15:28 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -126,14 +126,6 @@
configuration.addProperty(name, new Short(array[i]));
}
}
- else if (value instanceof int[])
- {
- int[] array = (int[]) value;
- for (int i = 0; i < array.length; i++)
- {
- configuration.addProperty(name, new Integer(array[i]));
- }
- }
else if (value instanceof long[])
{
long[] array = (long[]) value;
@@ -283,13 +275,30 @@
{
try
{
- List list = configuration.getList(name);
- if (list == null)
+ Object property = configuration.getProperty(name);
+
+ if (property == null)
{
throw new IllegalArgumentException("Property '" + name + "' does not exist.");
}
-
- list.set(index, value);
+ else if (property instanceof List)
+ {
+ List list = (List) property;
+ list.set(index, value);
+ }
+ else if (property.getClass().isArray())
+ {
+ Object[] array = (Object[]) property;
+ array[index] = value;
+ }
+ else if (index == 0)
+ {
+ configuration.setProperty(name, value);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Property '" + name + "' is not indexed.");
+ }
}
catch (ConversionException e)
{
Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java?rev=291679&r1=291678&r2=291679&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java Mon Sep 26 10:15:28 2005
@@ -27,6 +27,7 @@
import java.util.StringTokenizer;
import junit.framework.TestCase;
+import junitx.framework.ListAssert;
import junitx.framework.ObjectAssert;
/**
@@ -333,8 +334,8 @@
public void testGetString()
{
config.setProperty("testString", "The quick brown fox");
- String string = new String("The quick brown fox");
- String defaultValue = new String("jumps over the lazy dog");
+ String string = "The quick brown fox";
+ String defaultValue = "jumps over the lazy dog";
assertEquals("Existing key", string, config.getString("testString"));
assertEquals("Existing key with default value", string, config.getString("testString", defaultValue));
@@ -415,6 +416,19 @@
}
}
+ public void testGetInterpolatedList()
+ {
+ config.addProperty("number", "1");
+ config.addProperty("array", "${number}");
+ config.addProperty("array", "${number}");
+
+ List list = new ArrayList();
+ list.add("1");
+ list.add("1");
+
+ ListAssert.assertEquals("'array' property", list, config.getList("array"));
+ }
+
public void testCommaSeparatedString()
{
String prop = "hey, that's a test";
@@ -441,7 +455,7 @@
}
}
-
+
public void testAddProperty() throws Exception
{
Collection props = new ArrayList();
@@ -450,12 +464,12 @@
props.add(new String[] { "5.1", "5.2", "5.3,5.4", "5.5" });
props.add("six");
config.addProperty("complex.property", props);
-
+
Object val = config.getProperty("complex.property");
assertTrue(val instanceof Collection);
Collection col = (Collection) val;
assertEquals(10, col.size());
-
+
props = new ArrayList();
props.add("quick");
props.add("brown");
@@ -475,7 +489,7 @@
assertEquals(tok.nextToken(), it.next());
}
assertFalse(it.hasNext());
-
+
config.setProperty("complex.property", null);
assertFalse(config.containsKey("complex.property"));
}
@@ -570,7 +584,7 @@
"check first entry was interpolated",
"/home/applicationRoot/1",
arrayInt[0]);
-
+
config.addProperty("path", "/temp,C:\\Temp,/usr/local/tmp");
config.setProperty("path.current", "${path}");
assertEquals("Interpolation with multi-valued property", "/temp", superProp.getString("path.current"));
Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationConverter.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationConverter.java?rev=291679&r1=291678&r2=291679&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationConverter.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationConverter.java Mon Sep 26 10:15:28 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
import java.util.Properties;
import junit.framework.TestCase;
-
import org.apache.commons.collections.ExtendedProperties;
/**
@@ -84,16 +83,26 @@
public void testConfigurationToProperties()
{
- Configuration config = new BaseConfiguration();
+ BaseConfiguration config = new BaseConfiguration();
config.addProperty("string", "teststring");
config.addProperty("array", "item 1");
config.addProperty("array", "item 2");
+ config.addProperty("interpolated", "${string}");
+ config.addProperty("interpolated-array", "${interpolated}");
+ config.addProperty("interpolated-array", "${interpolated}");
Properties props = ConfigurationConverter.getProperties(config);
assertNotNull("null properties", props);
assertEquals("'string' property", "teststring", props.getProperty("string"));
- assertEquals("'array' property", "item 1, item 2", props.getProperty("array"));
+ assertEquals("'interpolated' property", "teststring", props.getProperty("interpolated"));
+ assertEquals("'array' property", "item 1,item 2", props.getProperty("array"));
+ assertEquals("'interpolated-array' property", "teststring,teststring", props.getProperty("interpolated-array"));
+
+ // change the list delimiter
+ BaseConfiguration.setDelimiter(';');
+ props = ConfigurationConverter.getProperties(config);
+ assertEquals("'array' property", "item 1;item 2", props.getProperty("array"));
}
public void testConfigurationToMap()
Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestConfigurationDynaBean.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestConfigurationDynaBean.java?rev=291679&r1=291678&r2=291679&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestConfigurationDynaBean.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestConfigurationDynaBean.java Mon Sep 26 10:15:28 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,9 +21,10 @@
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
-
+import junitx.framework.ObjectAssert;
import org.apache.commons.beanutils.DynaProperty;
import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.configuration.Configuration;
/**
* <p>Test Case for the <code>ConfigurationDynaBean</code> implementation class.
@@ -38,7 +39,7 @@
/**
* The basic test bean for each test.
*/
- protected ConfigurationDynaBean bean = null;
+ private ConfigurationDynaBean bean;
/**
* The set of property names we expect to have returned when calling
@@ -46,37 +47,37 @@
* when new properties are added to TestBean.
*/
String[] properties = {
- "booleanProperty",
- "booleanSecond",
- "doubleProperty",
- "floatProperty",
- "intProperty",
- "longProperty",
- "mappedProperty.key1",
- "mappedProperty.key2",
- "mappedProperty.key3",
- "mappedIntProperty.key1",
- "shortProperty",
- "stringProperty",
- "byteProperty",
- "charProperty"
+ "booleanProperty",
+ "booleanSecond",
+ "doubleProperty",
+ "floatProperty",
+ "intProperty",
+ "longProperty",
+ "mappedProperty.key1",
+ "mappedProperty.key2",
+ "mappedProperty.key3",
+ "mappedIntProperty.key1",
+ "shortProperty",
+ "stringProperty",
+ "byteProperty",
+ "charProperty"
};
Object[] values = {
- Boolean.TRUE,
- Boolean.TRUE,
- new Double(Double.MAX_VALUE),
- new Float(Float.MAX_VALUE),
- new Integer(Integer.MAX_VALUE),
- new Long(Long.MAX_VALUE),
- "First Value",
- "Second Value",
- "Third Value",
- new Integer(Integer.MAX_VALUE),
- new Short(Short.MAX_VALUE),
- "This is a string",
- new Byte(Byte.MAX_VALUE),
- new Character(Character.MAX_VALUE)
+ Boolean.TRUE,
+ Boolean.TRUE,
+ new Double(Double.MAX_VALUE),
+ new Float(Float.MAX_VALUE),
+ new Integer(Integer.MAX_VALUE),
+ new Long(Long.MAX_VALUE),
+ "First Value",
+ "Second Value",
+ "Third Value",
+ new Integer(Integer.MAX_VALUE),
+ new Short(Short.MAX_VALUE),
+ "This is a string",
+ new Byte(Byte.MAX_VALUE),
+ new Character(Character.MAX_VALUE)
};
int[] intArray = {0, 10, 20, 30, 40};
@@ -89,21 +90,13 @@
double[] doubleArray = {0.0, 10.0, 20.0, 30.0, 40.0};
String[] stringArray = {"String 0", "String 1", "String 2", "String 3", "String 4"};
- /**
- * Construct a new instance of this test case.
- * @param name Name of the test case
- */
- public TestConfigurationDynaBean(String name)
- {
- super(name);
- }
/**
* Set up instance variables required by this test case.
*/
public void setUp() throws Exception
{
- BaseConfiguration configuration = new BaseConfiguration();
+ Configuration configuration = new BaseConfiguration();
for (int i = 0; i < properties.length; i++)
{
@@ -143,27 +136,12 @@
/**
- * Tear down instance variables required by this test case.
- */
- public void tearDown()
- {
- bean = null;
- }
-
- /**
* Corner cases on getDynaProperty invalid arguments.
*/
public void testGetDescriptorArguments()
{
- try
- {
- DynaProperty descriptor = bean.getDynaClass().getDynaProperty("unknown");
- assertNull("Unknown property descriptor should be null", descriptor);
- }
- catch (Throwable t)
- {
- fail("Threw " + t + " instead of returning null");
- }
+ DynaProperty descriptor = bean.getDynaClass().getDynaProperty("unknown");
+ assertNull("Unknown property descriptor should be null", descriptor);
try
{
@@ -172,11 +150,11 @@
}
catch (java.lang.IllegalArgumentException e)
{
- ; // Expected response
+ // Expected response
}
catch (AssertionFailedError e)
{
- ; // ignore other failed responses
+ // ignore other failed responses
}
catch (Throwable t)
{
@@ -269,7 +247,7 @@
}
}
}
-
+
for (int j = 0; j < properties.length; j++)
{
if (count[j] < 0)
@@ -310,77 +288,37 @@
*/
public void testGetIndexedValues()
{
- Object value = null;
-
for (int i = 0; i < 5; i++)
{
- try
- {
- value = bean.get("intArray", i);
- }
- catch (Throwable t)
- {
- fail("intArray " + i + " threw " + t);
- }
+ Object value = bean.get("intArray", i);
assertNotNull("intArray index " + i + " did not return value.", value);
- assertTrue("intArray index " + i + " did not return Integer.", (value instanceof Integer));
+ ObjectAssert.assertInstanceOf("intArray index " + i, Integer.class, value);
assertEquals("intArray " + i + " returned incorrect value.", i * 10, ((Integer) value).intValue());
- try
- {
- value = bean.get("intIndexed", i);
- }
- catch (Throwable t)
- {
- fail("intIndexed index " + i + " threw " + t);
- }
+ value = bean.get("intIndexed", i);
assertNotNull("intIndexed index " + i + "returned value " + i, value);
- assertTrue("intIndexed index " + i + "returned Integer " + i, value instanceof Integer);
+ ObjectAssert.assertInstanceOf("intIndexed index " + i, Integer.class, value);
assertEquals("intIndexed index " + i + "returned correct " + i, i * 10, ((Integer) value).intValue());
- try
- {
- value = bean.get("listIndexed", i);
- }
- catch (Throwable t)
- {
- fail("listIndexed index " + i + " threw " + t);
- }
+ value = bean.get("listIndexed", i);
assertNotNull("listIndexed index " + i + "returned value " + i, value);
- assertTrue("list index " + i + "returned String " + i, value instanceof String);
+ ObjectAssert.assertInstanceOf("list index " + i, String.class, value);
assertEquals("listIndexed index " + i + "returned correct " + i, "String " + i, (String) value);
- try
- {
- value = bean.get("stringArray", i);
- }
- catch (Throwable t)
- {
- fail("stringArray index " + i + " threw " + t);
- }
+ value = bean.get("stringArray", i);
assertNotNull("stringArray index " + i + " returnde null.", value);
assertFalse("stringArray index " + i + " returned array instead of String.", value.getClass().isArray());
- assertTrue("stringArray index " + i + " returned "
- + value.getClass().getName() + "=[" + value + "]"
- + " instead of String.",
- value instanceof String);
+ ObjectAssert.assertInstanceOf("stringArray index " + i, String.class, value);
assertEquals("stringArray returned correct " + i, "String " + i, (String) value);
- try
- {
- value = bean.get("stringIndexed", i);
- }
- catch (Throwable t)
- {
- fail("stringIndexed " + i + " threw " + t);
- }
+ value = bean.get("stringIndexed", i);
assertNotNull("stringIndexed returned value " + i, value);
- assertTrue("stringIndexed returned String " + i, value instanceof String);
+ ObjectAssert.assertInstanceOf("stringIndexed", String.class, value);
assertEquals("stringIndexed returned correct " + i, "String " + i, (String) value);
}
}
@@ -406,37 +344,14 @@
*/
public void testGetMappedValues()
{
- Object value = null;
-
- try
- {
- value = bean.get("mappedProperty", "key1");
- assertEquals("Can find first value", "First Value", value);
- }
- catch (Throwable t)
- {
- fail("Finding first value threw " + t);
- }
+ Object value = bean.get("mappedProperty", "key1");
+ assertEquals("Can find first value", "First Value", value);
- try
- {
- value = bean.get("mappedProperty", "key2");
- assertEquals("Can find second value", "Second Value", value);
- }
- catch (Throwable t)
- {
- fail("Finding second value threw " + t);
- }
+ value = bean.get("mappedProperty", "key2");
+ assertEquals("Can find second value", "Second Value", value);
- try
- {
- value = bean.get("mappedProperty", "key3");
- assertNotNull("Cannot find third value", value);
- }
- catch (Throwable t)
- {
- fail("Finding third value threw " + t);
- }
+ value = bean.get("mappedProperty", "key3");
+ assertNotNull("Cannot find third value", value);
}
/**
@@ -464,17 +379,10 @@
*/
public void testGetSimpleBoolean()
{
- try
- {
- Object value = bean.get("booleanProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", (value instanceof Boolean));
- assertTrue("Got correct value", ((Boolean) value).booleanValue() == true);
- }
- catch (Throwable e)
- {
- fail("Exception: " + e);
- }
+ Object value = bean.get("booleanProperty");
+ assertNotNull("Got a value", value);
+ ObjectAssert.assertInstanceOf("Got correct type", Boolean.class, value);
+ assertTrue("Got correct value", ((Boolean) value).booleanValue());
}
/**
@@ -482,17 +390,10 @@
*/
public void testGetSimpleDouble()
{
- try
- {
- Object value = bean.get("doubleProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", (value instanceof Double));
- assertEquals("Got correct value", ((Double) value).doubleValue(), Double.MAX_VALUE, 0.005);
- }
- catch (Throwable t)
- {
- fail("Exception: " + t);
- }
+ Object value = bean.get("doubleProperty");
+ assertNotNull("Got a value", value);
+ ObjectAssert.assertInstanceOf("Got correct type", Double.class, value);
+ assertEquals("Got correct value", ((Double) value).doubleValue(), Double.MAX_VALUE, 0.005);
}
/**
@@ -500,17 +401,10 @@
*/
public void testGetSimpleFloat()
{
- try
- {
- Object value = bean.get("floatProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", (value instanceof Float));
- assertEquals("Got correct value", ((Float) value).floatValue(), Float.MAX_VALUE, 0.005f);
- }
- catch (Throwable t)
- {
- fail("Exception: " + t);
- }
+ Object value = bean.get("floatProperty");
+ assertNotNull("Got a value", value);
+ ObjectAssert.assertInstanceOf("Got correct type", Float.class, value);
+ assertEquals("Got correct value", ((Float) value).floatValue(), Float.MAX_VALUE, 0.005f);
}
/**
@@ -518,17 +412,10 @@
*/
public void testGetSimpleInt()
{
- try
- {
- Object value = bean.get("intProperty");
- assertNotNull("Failed to get value", value);
- assertTrue("Incorrect type", (value instanceof Integer));
- assertEquals("Incorrect value", ((Integer) value).intValue(), Integer.MAX_VALUE);
- }
- catch (Throwable t)
- {
- fail("Exception: " + t);
- }
+ Object value = bean.get("intProperty");
+ assertNotNull("Failed to get value", value);
+ ObjectAssert.assertInstanceOf("Incorrect type", Integer.class, value);
+ assertEquals("Incorrect value", ((Integer) value).intValue(), Integer.MAX_VALUE);
}
/**
@@ -536,17 +423,10 @@
*/
public void testGetSimpleLong()
{
- try
- {
- Object value = bean.get("longProperty");
- assertNotNull("Got a value", value);
- assertTrue("Returned incorrect type", (value instanceof Long));
- assertEquals("Returned value of Incorrect value", ((Long) value).longValue(), Long.MAX_VALUE);
- }
- catch (Throwable t)
- {
- fail("Exception: " + t);
- }
+ Object value = bean.get("longProperty");
+ assertNotNull("Got a value", value);
+ ObjectAssert.assertInstanceOf("Returned incorrect type", Long.class, value);
+ assertEquals("Returned value of Incorrect value", ((Long) value).longValue(), Long.MAX_VALUE);
}
/**
@@ -554,17 +434,10 @@
*/
public void testGetSimpleShort()
{
- try
- {
- Object value = bean.get("shortProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", (value instanceof Short));
- assertEquals("Got correct value", ((Short) value).shortValue(), Short.MAX_VALUE);
- }
- catch (Throwable t)
- {
- fail("Exception: " + t);
- }
+ Object value = bean.get("shortProperty");
+ assertNotNull("Got a value", value);
+ ObjectAssert.assertInstanceOf("Got correct type", Short.class, value);
+ assertEquals("Got correct value", ((Short) value).shortValue(), Short.MAX_VALUE);
}
/**
@@ -572,17 +445,10 @@
*/
public void testGetSimpleString()
{
- try
- {
- Object value = bean.get("stringProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", (value instanceof String));
- assertEquals("Got correct value", (String) value, "This is a string");
- }
- catch (Throwable t)
- {
- fail("Exception: " + t);
- }
+ Object value = bean.get("stringProperty");
+ assertNotNull("Got a value", value);
+ ObjectAssert.assertInstanceOf("Got correct type", String.class, value);
+ assertEquals("Got correct value", (String) value, "This is a string");
}
/**
@@ -590,23 +456,8 @@
*/
public void testMappedContains()
{
- try
- {
- assertTrue("Can't see first key", bean.contains("mappedProperty", "key1"));
- }
- catch (Exception e)
- {
- fail("Exception: " + e);
- }
-
- try
- {
- assertTrue("Can see unknown key", !bean.contains("mappedProperty", "Unknown Key"));
- }
- catch (Throwable t)
- {
- fail("Exception: " + t);
- }
+ assertTrue("Can't see first key", bean.contains("mappedProperty", "key1"));
+ assertTrue("Can see unknown key", !bean.contains("mappedProperty", "Unknown Key"));
}
/**
@@ -614,27 +465,13 @@
*/
public void testMappedRemove()
{
- try
- {
- assertTrue("Can see first key", bean.contains("mappedProperty", "key1"));
- bean.remove("mappedProperty", "key1");
- assertTrue("Can not see first key", !bean.contains("mappedProperty", "key1"));
- }
- catch (Throwable t)
- {
- fail("Exception: " + t);
- }
-
- try
- {
- assertTrue("Can not see unknown key", !bean.contains("mappedProperty", "key4"));
- bean.remove("mappedProperty", "key4");
- assertTrue("Can not see unknown key", !bean.contains("mappedProperty", "key4"));
- }
- catch (Throwable t)
- {
- fail("Exception: " + t);
- }
+ assertTrue("Can see first key", bean.contains("mappedProperty", "key1"));
+ bean.remove("mappedProperty", "key1");
+ assertTrue("Can not see first key", !bean.contains("mappedProperty", "key1"));
+
+ assertTrue("Can not see unknown key", !bean.contains("mappedProperty", "key4"));
+ bean.remove("mappedProperty", "key4");
+ assertTrue("Can not see unknown key", !bean.contains("mappedProperty", "key4"));
}
/**
@@ -663,76 +500,43 @@
*/
public void testSetIndexedValues()
{
- Object value = null;
-
- try
- {
- bean.set("intArray", 0, new Integer(1));
- value = bean.get("intArray", 0);
- }
- catch (Throwable t)
- {
- fail("Threw " + t);
- }
+ bean.set("intArray", 0, new Integer(1));
+ Object value = bean.get("intArray", 0);
assertNotNull("Returned new value 0", value);
- assertTrue("Returned Integer new value 0", value instanceof Integer);
+ ObjectAssert.assertInstanceOf("Returned Integer new value 0", Integer.class, value);
assertEquals("Returned correct new value 0", 1, ((Integer) value).intValue());
- try
- {
- bean.set("intIndexed", 1, new Integer(11));
- value = bean.get("intIndexed", 1);
- }
- catch (Throwable t)
- {
- fail("Threw " + t);
- }
+
+ bean.set("intIndexed", 1, new Integer(11));
+ value = bean.get("intIndexed", 1);
assertNotNull("Returned new value 1", value);
- assertTrue("Returned Integer new value 1", value instanceof Integer);
+ ObjectAssert.assertInstanceOf("Returned Integer new value 1", Integer.class, value);
assertEquals("Returned correct new value 1", 11, ((Integer) value).intValue());
- try
- {
- bean.set("listIndexed", 2, "New Value 2");
- value = bean.get("listIndexed", 2);
- }
- catch (Throwable t)
- {
- fail("Threw " + t);
- }
+
+ bean.set("listIndexed", 2, "New Value 2");
+ value = bean.get("listIndexed", 2);
assertNotNull("Returned new value 2", value);
- assertTrue("Returned String new value 2", value instanceof String);
+ ObjectAssert.assertInstanceOf("Returned String new value 2", String.class, value);
assertEquals("Returned correct new value 2", "New Value 2", (String) value);
- try
- {
- bean.set("stringArray", 3, "New Value 3");
- value = bean.get("stringArray", 3);
- }
- catch (Throwable t)
- {
- fail("Threw " + t);
- }
+
+ bean.set("stringArray", 3, "New Value 3");
+ value = bean.get("stringArray", 3);
assertNotNull("Returned new value 3", value);
- assertTrue("Returned String new value 3", value instanceof String);
+ ObjectAssert.assertInstanceOf("Returned String new value 3", String.class, value);
assertEquals("Returned correct new value 3", "New Value 3", (String) value);
- try
- {
- bean.set("stringIndexed", 4, "New Value 4");
- value = bean.get("stringIndexed", 4);
- }
- catch (Throwable t)
- {
- fail("Threw " + t);
- }
+
+ bean.set("stringIndexed", 4, "New Value 4");
+ value = bean.get("stringIndexed", 4);
assertNotNull("Returned new value 4", value);
- assertTrue("Returned String new value 4", value instanceof String);
+ ObjectAssert.assertInstanceOf("Returned String new value 4", String.class, value);
assertEquals("Returned correct new value 4", "New Value 4", (String) value);
}
@@ -741,25 +545,11 @@
*/
public void testSetMappedValues()
{
- try
- {
- bean.set("mappedProperty", "First Key", "New First Value");
- assertEquals("Can replace old value", "New First Value", (String) bean.get("mappedProperty", "First Key"));
- }
- catch (Throwable t)
- {
- fail("Finding fourth value threw " + t);
- }
+ bean.set("mappedProperty", "First Key", "New First Value");
+ assertEquals("Can replace old value", "New First Value", (String) bean.get("mappedProperty", "First Key"));
- try
- {
- bean.set("mappedProperty", "Fourth Key", "Fourth Value");
- assertEquals("Can set new value", "Fourth Value", (String) bean.get("mappedProperty", "Fourth Key"));
- }
- catch (Throwable t)
- {
- fail("Finding fourth value threw " + t);
- }
+ bean.set("mappedProperty", "Fourth Key", "Fourth Value");
+ assertEquals("Can set new value", "Fourth Value", (String) bean.get("mappedProperty", "Fourth Key"));
}
/**
@@ -767,17 +557,10 @@
*/
public void testSetSimpleBoolean()
{
- try
- {
- boolean oldValue = ((Boolean) bean.get("booleanProperty")).booleanValue();
- boolean newValue = !oldValue;
- bean.set("booleanProperty", new Boolean(newValue));
- assertTrue("Matched new value", newValue == ((Boolean) bean.get("booleanProperty")).booleanValue());
- }
- catch (Throwable e)
- {
- fail("Exception: " + e);
- }
+ boolean oldValue = ((Boolean) bean.get("booleanProperty")).booleanValue();
+ boolean newValue = !oldValue;
+ bean.set("booleanProperty", new Boolean(newValue));
+ assertTrue("Matched new value", newValue == ((Boolean) bean.get("booleanProperty")).booleanValue());
}
/**
@@ -785,17 +568,10 @@
*/
public void testSetSimpleDouble()
{
- try
- {
- double oldValue = ((Double) bean.get("doubleProperty")).doubleValue();
- double newValue = oldValue + 1.0;
- bean.set("doubleProperty", new Double(newValue));
- assertEquals("Matched new value", newValue, ((Double) bean.get("doubleProperty")).doubleValue(), 0.005);
- }
- catch (Throwable e)
- {
- fail("Exception: " + e);
- }
+ double oldValue = ((Double) bean.get("doubleProperty")).doubleValue();
+ double newValue = oldValue + 1.0;
+ bean.set("doubleProperty", new Double(newValue));
+ assertEquals("Matched new value", newValue, ((Double) bean.get("doubleProperty")).doubleValue(), 0.005);
}
/**
@@ -803,17 +579,10 @@
*/
public void testSetSimpleFloat()
{
- try
- {
- float oldValue = ((Float) bean.get("floatProperty")).floatValue();
- float newValue = oldValue + (float) 1.0;
- bean.set("floatProperty", new Float(newValue));
- assertEquals("Matched new value", newValue, ((Float) bean.get("floatProperty")).floatValue(), 0.005f);
- }
- catch (Throwable e)
- {
- fail("Exception: " + e);
- }
+ float oldValue = ((Float) bean.get("floatProperty")).floatValue();
+ float newValue = oldValue + (float) 1.0;
+ bean.set("floatProperty", new Float(newValue));
+ assertEquals("Matched new value", newValue, ((Float) bean.get("floatProperty")).floatValue(), 0.005f);
}
/**
@@ -821,17 +590,10 @@
*/
public void testSetSimpleInt()
{
- try
- {
- int oldValue = ((Integer) bean.get("intProperty")).intValue();
- int newValue = oldValue + 1;
- bean.set("intProperty", new Integer(newValue));
- assertEquals("Matched new value", newValue, ((Integer) bean.get("intProperty")).intValue());
- }
- catch (Throwable e)
- {
- fail("Exception: " + e);
- }
+ int oldValue = ((Integer) bean.get("intProperty")).intValue();
+ int newValue = oldValue + 1;
+ bean.set("intProperty", new Integer(newValue));
+ assertEquals("Matched new value", newValue, ((Integer) bean.get("intProperty")).intValue());
}
/**
@@ -839,17 +601,10 @@
*/
public void testSetSimpleLong()
{
- try
- {
- long oldValue = ((Long) bean.get("longProperty")).longValue();
- long newValue = oldValue + 1;
- bean.set("longProperty", new Long(newValue));
- assertEquals("Matched new value", newValue, ((Long) bean.get("longProperty")).longValue());
- }
- catch (Throwable e)
- {
- fail("Exception: " + e);
- }
+ long oldValue = ((Long) bean.get("longProperty")).longValue();
+ long newValue = oldValue + 1;
+ bean.set("longProperty", new Long(newValue));
+ assertEquals("Matched new value", newValue, ((Long) bean.get("longProperty")).longValue());
}
/**
@@ -857,17 +612,10 @@
*/
public void testSetSimpleShort()
{
- try
- {
- short oldValue = ((Short) bean.get("shortProperty")).shortValue();
- short newValue = (short) (oldValue + 1);
- bean.set("shortProperty", new Short(newValue));
- assertEquals("Matched new value", newValue, ((Short) bean.get("shortProperty")).shortValue());
- }
- catch (Throwable e)
- {
- fail("Exception: " + e);
- }
+ short oldValue = ((Short) bean.get("shortProperty")).shortValue();
+ short newValue = (short) (oldValue + 1);
+ bean.set("shortProperty", new Short(newValue));
+ assertEquals("Matched new value", newValue, ((Short) bean.get("shortProperty")).shortValue());
}
/**
@@ -875,17 +623,10 @@
*/
public void testSetSimpleString()
{
- try
- {
- String oldValue = (String) bean.get("stringProperty");
- String newValue = oldValue + " Extra Value";
- bean.set("stringProperty", newValue);
- assertEquals("Matched new value", newValue, (String) bean.get("stringProperty"));
- }
- catch (Throwable e)
- {
- fail("Exception: " + e);
- }
+ String oldValue = (String) bean.get("stringProperty");
+ String newValue = oldValue + " Extra Value";
+ bean.set("stringProperty", newValue);
+ assertEquals("Matched new value", newValue, (String) bean.get("stringProperty"));
}
/**
@@ -938,15 +679,7 @@
*/
protected void testGetDescriptorBase(String name, Class type)
{
- DynaProperty descriptor = null;
- try
- {
- descriptor = bean.getDynaClass().getDynaProperty(name);
- }
- catch (Throwable t)
- {
- fail("Threw an exception: " + t);
- }
+ DynaProperty descriptor = bean.getDynaClass().getDynaProperty(name);
assertNotNull("Failed to get descriptor", descriptor);
assertEquals("Got incorrect type", type, descriptor.getType());
@@ -960,25 +693,12 @@
public void testNonIndexedPropeties()
{
ConfigurationDynaBean nested = (ConfigurationDynaBean) bean.get("mappedProperty");
- try
- {
- String value = (String) nested.get("key1");
- assertEquals("Can find first value", "First Value", value);
- }
- catch (Throwable t)
- {
- fail("Finding first value threw " + t);
- }
- try
- {
- nested.set("key1", "undefined");
- assertEquals("Incorrect value returned", "undefined", bean.get("mappedProperty.key1"));
- }
- catch (Throwable t)
- {
- fail("Finding setting first value threw " + t);
- }
+ String value = (String) nested.get("key1");
+ assertEquals("Can find first value", "First Value", value);
+
+ nested.set("key1", "undefined");
+ assertEquals("Incorrect value returned", "undefined", bean.get("mappedProperty.key1"));
}
/**
@@ -1006,7 +726,7 @@
try
{
- bean.set("booleanProperty", 0, new Boolean(true));
+ bean.set("booleanProperty", 0, Boolean.TRUE);
}
catch (IllegalArgumentException e)
{
Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?rev=291679&r1=291678&r2=291679&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Mon Sep 26 10:15:28 2005
@@ -23,6 +23,15 @@
<body>
<release version="1.2-dev" date="in SVN">
+ <action dev="ebourg" type="update" issue="36784 ">
+ ConfigurationConverter.getProperties() now uses the delimiter of the
+ specified configuration to convert the list properties into strings.
+ </action>
+ <action dev="ebourg" type="update" issue="36784 ">
+ getList() now returns a list of interpolated values. As a side effect
+ the Properties returned by ConfigurationConverter.getProperties()
+ contains only interpolated values.
+ </action>
<action dev="ebourg" type="update" issue="36699">
PropertiesConfiguration now uses the ISO-8859-1 encoding by default
instead of the system encoding to comply with the specification of
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org