cvs commit: jakarta-commons/configuration/src/test/org/apache/commons/configuration TestBaseConfiguration.java

2004-10-18 Thread ebourg
ebourg  2004/10/18 03:44:31

  Modified:configuration/xdocs changes.xml
   configuration/src/java/org/apache/commons/configuration
PropertyConverter.java
   configuration/src/test/org/apache/commons/configuration
TestBaseConfiguration.java
  Log:
  Numeric properties can now be specified in hexadecimal format (bug 28026)
  
  Revision  ChangesPath
  1.58  +4 -0  jakarta-commons/configuration/xdocs/changes.xml
  
  Index: changes.xml
  ===
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
  retrieving revision 1.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- changes.xml   18 Oct 2004 10:19:26 -  1.57
  +++ changes.xml   18 Oct 2004 10:44:31 -  1.58
  @@ -8,6 +8,10 @@
 body
   
   release version=1.1-dev date=in CVS
  +  action dev=ebourg type=add issue=28026
  +Numeric properties can now be specified in hexadecimal format,
  +for example number = 0xC5F0.
  +  /action
 action dev=oheger type=fix issue=31745
   Fixed HierarchicalConfiguration.getKeys(String), it returned an empty
   iterator if the prefix string contained indices.
  
  
  
  1.2   +47 -6 
jakarta-commons/configuration/src/java/org/apache/commons/configuration/PropertyConverter.java
  
  Index: PropertyConverter.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/PropertyConverter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PropertyConverter.java18 Oct 2004 09:54:37 -  1.1
  +++ PropertyConverter.java18 Oct 2004 10:44:31 -  1.2
  @@ -84,7 +84,15 @@
   {
   try
   {
  -return new Byte((String) value);
  +String string = (String) value;
  +if (string.startsWith(0x))
  +{
  +return new Byte((byte) Integer.parseInt(string.substring(2), 
16));
  +}
  +else
  +{
  +return new Byte(string);
  +}
   }
   catch (NumberFormatException e)
   {
  @@ -113,7 +121,16 @@
   {
   try
   {
  -return new Short((String) value);
  +String string = (String) value;
  +if (string.startsWith(0x))
  +{
  +return new Short((short) Integer.parseInt(string.substring(2), 
16));
  +}
  +else
  +{
  +return new Short(string);
  +}
  +
   }
   catch (NumberFormatException e)
   {
  @@ -142,7 +159,15 @@
   {
   try
   {
  -return new Integer((String) value);
  +String string = (String) value;
  +if (string.startsWith(0x))
  +{
  +return new Integer((int) Long.parseLong(string.substring(2), 
16));
  +}
  +else
  +{
  +return new Integer(string);
  +}
   }
   catch (NumberFormatException e)
   {
  @@ -171,7 +196,15 @@
   {
   try
   {
  -return new Long((String) value);
  +String string = (String) value;
  +if (string.startsWith(0x))
  +{
  +return new Long(new BigInteger(string.substring(2), 
16).longValue());
  +}
  +else
  +{
  +return new Long(string);
  +}
   }
   catch (NumberFormatException e)
   {
  @@ -258,7 +291,15 @@
   {
   try
   {
  -return new BigInteger((String) value);
  +String string = (String) value;
  +if (string.startsWith(0x))
  +{
  +return new BigInteger(string.substring(2), 16);
  +}
  +else
  +{
  +return new BigInteger(string);
  +}
   }
   catch (NumberFormatException e)
   {
  
  
  
  1.16  +570 -504  
jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestBaseConfiguration.java
  
  Index: TestBaseConfiguration.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestBaseConfiguration.java,v
  

RE: cvs commit: jakarta-commons/configuration/src/test/org/apache/commons/configuration TestBaseConfiguration.java

2004-10-18 Thread Eric Pugh
Good fix.. However, ins;t there a class in commons lang that does that for
us?

Eric

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 Sent: Monday, October 18, 2004 11:45 AM
 To: [EMAIL PROTECTED]
 Subject: cvs commit:
 jakarta-commons/configuration/src/test/org/apache/commons/configuration
 TestBaseConfiguration.java


 ebourg  2004/10/18 03:44:31

   Modified:configuration/xdocs changes.xml
configuration/src/java/org/apache/commons/configuration
 PropertyConverter.java
configuration/src/test/org/apache/commons/configuration
 TestBaseConfiguration.java
   Log:
   Numeric properties can now be specified in hexadecimal format
 (bug 28026)

   Revision  ChangesPath
   1.58  +4 -0  jakarta-commons/configuration/xdocs/changes.xml

   Index: changes.xml
   ===
   RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
   retrieving revision 1.57
   retrieving revision 1.58
   diff -u -r1.57 -r1.58
   --- changes.xml 18 Oct 2004 10:19:26 -  1.57
   +++ changes.xml 18 Oct 2004 10:44:31 -  1.58
   @@ -8,6 +8,10 @@
  body

release version=1.1-dev date=in CVS
   +  action dev=ebourg type=add issue=28026
   +Numeric properties can now be specified in hexadecimal format,
   +for example number = 0xC5F0.
   +  /action
  action dev=oheger type=fix issue=31745
Fixed HierarchicalConfiguration.getKeys(String), it
 returned an empty
iterator if the prefix string contained indices.



   1.2   +47 -6
 jakarta-commons/configuration/src/java/org/apache/commons/configur
 ation/PropertyConverter.java

   Index: PropertyConverter.java
   ===
   RCS file:
 /home/cvs/jakarta-commons/configuration/src/java/org/apache/common
 s/configuration/PropertyConverter.java,v
   retrieving revision 1.1
   retrieving revision 1.2
   diff -u -r1.1 -r1.2
   --- PropertyConverter.java  18 Oct 2004 09:54:37 -  1.1
   +++ PropertyConverter.java  18 Oct 2004 10:44:31 -  1.2
   @@ -84,7 +84,15 @@
{
try
{
   -return new Byte((String) value);
   +String string = (String) value;
   +if (string.startsWith(0x))
   +{
   +return new Byte((byte)
 Integer.parseInt(string.substring(2), 16));
   +}
   +else
   +{
   +return new Byte(string);
   +}
}
catch (NumberFormatException e)
{
   @@ -113,7 +121,16 @@
{
try
{
   -return new Short((String) value);
   +String string = (String) value;
   +if (string.startsWith(0x))
   +{
   +return new Short((short)
 Integer.parseInt(string.substring(2), 16));
   +}
   +else
   +{
   +return new Short(string);
   +}
   +
}
catch (NumberFormatException e)
{
   @@ -142,7 +159,15 @@
{
try
{
   -return new Integer((String) value);
   +String string = (String) value;
   +if (string.startsWith(0x))
   +{
   +return new Integer((int)
 Long.parseLong(string.substring(2), 16));
   +}
   +else
   +{
   +return new Integer(string);
   +}
}
catch (NumberFormatException e)
{
   @@ -171,7 +196,15 @@
{
try
{
   -return new Long((String) value);
   +String string = (String) value;
   +if (string.startsWith(0x))
   +{
   +return new Long(new
 BigInteger(string.substring(2), 16).longValue());
   +}
   +else
   +{
   +return new Long(string);
   +}
}
catch (NumberFormatException e)
{
   @@ -258,7 +291,15 @@
{
try
{
   -return new BigInteger((String) value);
   +String string = (String) value;
   +if (string.startsWith(0x))
   +{
   +return new BigInteger(string.substring(2), 16);
   +}
   +else
   +{
   +return new BigInteger(string

cvs commit: jakarta-commons/configuration/src/test/org/apache/commons/configuration TestBaseConfiguration.java

2004-06-21 Thread ebourg
ebourg  2004/06/21 06:49:24

  Modified:configuration/src/java/org/apache/commons/configuration
AbstractConfiguration.java
   configuration/src/test/org/apache/commons/configuration
TestBaseConfiguration.java
  Log:
  renamed the processString(String) method to split(String)
  
  Revision  ChangesPath
  1.13  +13 -13
jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractConfiguration.java
  
  Index: AbstractConfiguration.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractConfiguration.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- AbstractConfiguration.java21 Jun 2004 12:37:40 -  1.12
  +++ AbstractConfiguration.java21 Jun 2004 13:49:24 -  1.13
  @@ -71,14 +71,16 @@
   {
   if (token instanceof String)
   {
  -for(Iterator it = processString((String) token).iterator(); 
it.hasNext();)
  +Iterator it = split((String) token).iterator();
  +while (it.hasNext())
   {
   addPropertyDirect(key, it.next());
   }
   }
   else if (token instanceof Collection)
   {
  -for (Iterator it = ((Collection) token).iterator(); it.hasNext();)
  +Iterator it = ((Collection) token).iterator();
  +while (it.hasNext())
   {
   addProperty(key, it.next());
   }
  @@ -219,18 +221,17 @@
   }
   
   /**
  - * Returns a List of Strings built from the supplied
  - * String. Splits up CSV lists. If no commas are in the
  - * String, simply returns a List with the String as its
  - * first element
  + * Returns a List of Strings built from the supplied String. Splits up CSV
  + * lists. If no commas are in the String, simply returns a List with the
  + * String as its first element.
*
* @param token The String to tokenize
*
* @return A List of Strings
*/
  -protected List processString(String token)
  +protected List split(String token)
   {
  -List retList = new ArrayList(INITIAL_LIST_SIZE);
  +List list = new ArrayList(INITIAL_LIST_SIZE);
   
   if (token.indexOf(DELIMITER)  0)
   {
  @@ -238,13 +239,12 @@
   
   while (tokenizer.hasMoreTokens())
   {
  -String value = tokenizer.nextToken();
  -retList.add(value);
  +list.add(tokenizer.nextToken());
   }
   }
   else
   {
  -retList.add(token);
  +list.add(token);
   }
   
   //
  @@ -252,7 +252,7 @@
   // we also keep it in the Container. So the
   // Keys are added to the store in the sequence that
   // is given in the properties
  -return retList;
  +return list;
   }
   
   /**
  
  
  
  1.13  +4 -4  
jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestBaseConfiguration.java
  
  Index: TestBaseConfiguration.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestBaseConfiguration.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- TestBaseConfiguration.java21 Jun 2004 09:51:41 -  1.12
  +++ TestBaseConfiguration.java21 Jun 2004 13:49:24 -  1.13
  @@ -481,16 +481,16 @@
fail(IllegalStateException should have been thrown for looped 
property references);
}
   
  -public void testProcessString()
  +public void testSplit()
   {
   String s1 = abc,xyz;
  -List tokens = config.processString(s1);
  +List tokens = config.split(s1);
   assertEquals(number of tokens in ' + s1 + ', 2, tokens.size());
   assertEquals(1st token for ' + s1 + ', abc, tokens.get(0));
   assertEquals(2nd token for ' + s1 + ', xyz, tokens.get(1));
   
   String s2 = abc\\,xyz;
  -tokens = config.processString(s2);
  +tokens = config.split(s2);
   assertEquals(number of tokens in ' + s2 + ', 1, tokens.size());
   assertEquals(1st token for ' + s2 + ', abc,xyz, tokens.get(0));
   }
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



cvs commit: jakarta-commons/configuration/src/test/org/apache/commons/configuration TestBaseConfiguration.java

2004-06-15 Thread ebourg
ebourg  2004/06/15 08:53:58

  Modified:configuration/src/java/org/apache/commons/configuration
AbstractConfiguration.java
CompositeConfiguration.java Configuration.java
JNDIConfiguration.java
   configuration/xdocs changes.xml
   configuration/src/test/org/apache/commons/configuration
TestBaseConfiguration.java
  Log:
  Introduced a ConversionException thrown when the value of a property is not 
compatible the type requested. It replaces the ClassCastException and the 
NumberFormatException thrown previously.
  
  Revision  ChangesPath
  1.10  +121 -67   
jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractConfiguration.java
  
  Index: AbstractConfiguration.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractConfiguration.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- AbstractConfiguration.java3 Jun 2004 15:32:46 -   1.9
  +++ AbstractConfiguration.java15 Jun 2004 15:53:58 -  1.10
  @@ -348,7 +348,7 @@
*
* @return The associated properties if key is found.
*
  - * @throws ClassCastException is thrown if the key maps to an
  + * @throws ConversionException is thrown if the key maps to an
* object that is not a String/List.
* @throws IllegalArgumentException if one of the tokens is
* malformed (does not contain an equals sign).
  @@ -370,7 +370,7 @@
*
* @return The associated properties if key is found.
*
  - * @throws ClassCastException is thrown if the key maps to an
  + * @throws ConversionException is thrown if the key maps to an
* object that is not a String/List of Strings.
* @throws IllegalArgumentException if one of the tokens is
* malformed (does not contain an equals sign).
  @@ -446,7 +446,7 @@
*
* @throws NoSuchElementException is thrown if the key doesn't
* map to an existing object.
  - * @throws ClassCastException is thrown if the key maps to an
  + * @throws ConversionException is thrown if the key maps to an
* object that is not a Boolean.
*/
   public boolean getBoolean(String key)
  @@ -471,7 +471,7 @@
*
* @return The associated boolean.
*
  - * @throws ClassCastException is thrown if the key maps to an
  + * @throws ConversionException is thrown if the key maps to an
* object that is not a Boolean.
*/
   public boolean getBoolean(String key, boolean defaultValue)
  @@ -488,7 +488,7 @@
* @return The associated boolean if key is found and has valid
* format, default value otherwise.
*
  - * @throws ClassCastException is thrown if the key maps to an
  + * @throws ConversionException is thrown if the key maps to an
* object that is not a Boolean.
*/
   public Boolean getBoolean(String key, Boolean defaultValue)
  @@ -501,15 +501,20 @@
   }
   else if (value instanceof String)
   {
  -return BooleanUtils.toBooleanObject((String) value);
  +Boolean b = BooleanUtils.toBooleanObject((String) value);
  +if (b == null)
  +{
  +throw new ConversionException('\'' + key + ' doesn't map to a 
Boolean object);
  +}
  +return b;
   }
   else if (value == null)
  -{   
  +{
   return defaultValue;
   }
   else
   {
  -throw new ClassCastException(
  +throw new ConversionException(
   '\'' + key + ' doesn't map to a Boolean object);
   }
   }
  @@ -523,7 +528,7 @@
*
* @throws NoSuchElementException is thrown if the key doesn't
* map to an existing object.
  - * @throws ClassCastException is thrown if the key maps to an
  + * @throws ConversionException is thrown if the key maps to an
* object that is not a Byte.
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
  @@ -550,7 +555,7 @@
*
* @return The associated byte.
*
  - * @throws ClassCastException is thrown if the key maps to an
  + * @throws ConversionException is thrown if the key maps to an
* object that is not a Byte.
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
  @@ -569,7 +574,7 @@
* @return The associated byte if key is found and has valid format, default
* value otherwise.
*
  - * @throws ClassCastException is thrown if the key 

cvs commit: jakarta-commons/configuration/src/test/org/apache/commons/configuration TestBaseConfiguration.java

2004-06-03 Thread ebourg
ebourg  2004/06/03 07:04:52

  Modified:configuration/src/test/org/apache/commons/configuration
TestBaseConfiguration.java
  Log:
  Added a test for the AbstractConfiguration.processString() method
  
  Revision  ChangesPath
  1.10  +15 -2 
jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestBaseConfiguration.java
  
  Index: TestBaseConfiguration.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestBaseConfiguration.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestBaseConfiguration.java13 May 2004 12:19:16 -  1.9
  +++ TestBaseConfiguration.java3 Jun 2004 14:04:52 -   1.10
  @@ -481,6 +481,19 @@
fail(IllegalStateException should have been thrown for looped 
property references);
}
   
  -
  +public void testProcessString()
  +{
  +String s1 = abc,xyz;
  +List tokens = config.processString(s1);
  +assertEquals(number of tokens in ' + s1 + ', 2, tokens.size());
  +assertEquals(1st token for ' + s1 + ', abc, tokens.get(0));
  +assertEquals(2nd token for ' + s1 + ', xyz, tokens.get(1));
  +
  +String s2 = abc\\,xyz;
  +tokens = config.processString(s2);
  +assertEquals(number of tokens in ' + s2 + ', 1, tokens.size());
  +assertEquals(1st token for ' + s2 + ', abc,xyz, tokens.get(0));
  +}
  +
   }
   
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



cvs commit: jakarta-commons/configuration/src/test/org/apache/commons/configuration TestBaseConfiguration.java

2004-05-13 Thread epugh
epugh   2004/05/13 05:19:16

  Modified:configuration/src/test/org/apache/commons/configuration
TestBaseConfiguration.java
  Log:
  Extend unit test to verify exception types throw
  
  Revision  ChangesPath
  1.9   +446 -346  
jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestBaseConfiguration.java
  
  Index: TestBaseConfiguration.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestBaseConfiguration.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestBaseConfiguration.java9 Mar 2004 15:34:02 -   1.8
  +++ TestBaseConfiguration.java13 May 2004 12:19:16 -  1.9
  @@ -24,6 +24,7 @@
   import java.util.Properties;
   
   import junit.framework.TestCase;
  +import junitx.framework.ObjectAssert;
   
   /**
* Tests some basic functions of the BaseConfiguration class
  @@ -32,355 +33,454 @@
*/
   public class TestBaseConfiguration extends TestCase
   {
  -protected BaseConfiguration eprop = new BaseConfiguration();
  + protected BaseConfiguration config = new BaseConfiguration();
   
  -public void testGetProperty()
  -{
  -/* should be empty and return null */
  -assertEquals(This returns null, eprop.getProperty(foo), null);
  -
  -/* add a real value, and get it two different ways */
  -eprop.setProperty(number, 1);
  -assertEquals(This returns '1', eprop.getProperty(number), 1);
  -assertEquals(This returns '1', eprop.getString(number), 1);
  -}
  -
  -public void testGetByte()
  -{
  -eprop.setProperty(number, 1);
  -byte oneB = 1, twoB = 2;
  -assertEquals(This returns 1(byte), eprop.getByte(number), oneB);
  -assertEquals(
  -This returns 1(byte),
  -eprop.getByte(number, twoB),
  -oneB);
  -assertEquals(
  -This returns 2(default byte),
  -eprop.getByte(numberNotInConfig, twoB),
  -twoB);
  -assertEquals(
  -This returns 1(Byte),
  -eprop.getByte(number, new Byte(2)),
  -new Byte(oneB));
  -}
  -
  -public void testGetShort()
  -{
  -eprop.setProperty(numberS, 1);
  -short oneS = 1, twoS = 2;
  -assertEquals(This returns 1(short), eprop.getShort(numberS), oneS);
  -assertEquals(
  -This returns 1(short),
  -eprop.getShort(numberS, twoS),
  -oneS);
  -assertEquals(
  -This returns 2(default short),
  -eprop.getShort(numberNotInConfig, twoS),
  -twoS);
  -assertEquals(
  -This returns 1(Short),
  -eprop.getShort(numberS, new Short(2)),
  -new Short(oneS));
  -}
  -
  -public void testGetLong()
  -{
  -eprop.setProperty(numberL, 1);
  -long oneL = 1, twoL = 2;
  -assertEquals(This returns 1(long), eprop.getLong(numberL), oneL);
  -assertEquals(
  -This returns 1(long),
  -eprop.getLong(numberL, twoL),
  -oneL);
  -assertEquals(
  -This returns 2(default long),
  -eprop.getLong(numberNotInConfig, twoL),
  -twoL);
  -assertEquals(
  -This returns 1(Long),
  -eprop.getLong(numberL, new Long(2)),
  -new Long(oneL));
  -}
  -
  -public void testGetFloat()
  -{
  -eprop.setProperty(numberF, 1.0);
  -float oneF = 1, twoF = 2;
  -assertEquals(
  -This returns 1(float),
  -eprop.getFloat(numberF),
  -oneF,
  -0);
  -assertEquals(
  -This returns 1(float),
  -eprop.getFloat(numberF, twoF),
  -oneF,
  -0);
  -assertEquals(
  -This returns 2(default float),
  -eprop.getFloat(numberNotInConfig, twoF),
  -twoF,
  -0);
  -assertEquals(
  -This returns 1(Float),
  -eprop.getFloat(numberF, new Float(2)),
  -new Float(oneF));
  -}
  -
  -public void testGetDouble()
  -{
  -eprop.setProperty(numberD, 1.0);
  -double oneD = 1, twoD = 2;
  -assertEquals(
  -This returns 1(double),
  -eprop.getDouble(numberD),
  -oneD,
  -0);
  -assertEquals(
  -This returns 1(double),
  -eprop.getDouble(numberD, twoD),
  -oneD,
  -0);
  -assertEquals(
  -This returns 2(default double),
  -eprop.getDouble(numberNotInConfig, twoD),
  -twoD,
  -0);
  -assertEquals(
  -This returns