You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by sc...@apache.org on 2009/03/06 17:46:01 UTC

svn commit: r750970 - in /incubator/etch/branches/config/services/config/src: main/java/org/apache/etch/services/config/YamlConfig.java test/java/org/apache/etch/services/config/TestYamlConfig.java

Author: sccomer
Date: Fri Mar  6 16:46:00 2009
New Revision: 750970

URL: http://svn.apache.org/viewvc?rev=750970&view=rev
Log:
updated. bug fix and more tests.

Modified:
    incubator/etch/branches/config/services/config/src/main/java/org/apache/etch/services/config/YamlConfig.java
    incubator/etch/branches/config/services/config/src/test/java/org/apache/etch/services/config/TestYamlConfig.java

Modified: incubator/etch/branches/config/services/config/src/main/java/org/apache/etch/services/config/YamlConfig.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/config/services/config/src/main/java/org/apache/etch/services/config/YamlConfig.java?rev=750970&r1=750969&r2=750970&view=diff
==============================================================================
--- incubator/etch/branches/config/services/config/src/main/java/org/apache/etch/services/config/YamlConfig.java (original)
+++ incubator/etch/branches/config/services/config/src/main/java/org/apache/etch/services/config/YamlConfig.java Fri Mar  6 16:46:00 2009
@@ -356,46 +356,64 @@
 
 	public Boolean hasValue( Object id )
 	{
+		if (id == null)
+			return false;
 		return getConf( id ).hasValue();
 	}
 
 	public Object getValue( Object id )
 	{
+		if (id == null)
+			return null;
 		return getConf( id ).getValue();
 	}
 
 	public Boolean getBoolean( Object id )
 	{
+		if (id == null)
+			return null;
 		return getConf( id ).getBoolean();
 	}
 
 	public Integer getInteger( Object id )
 	{
+		if (id == null)
+			return null;
 		return getConf( id ).getInteger();
 	}
 
 	public Double getDouble( Object id )
 	{
+		if (id == null)
+			return null;
 		return getConf( id ).getDouble();
 	}
 
 	public String getString( Object id )
 	{
+		if (id == null)
+			return null;
 		return getConf( id ).getString();
 	}
 
 	public Date getDate( Object id )
 	{
+		if (id == null)
+			return null;
 		return getConf( id ).getDate();
 	}
 
 	public List<?> getList( Object id, Integer depth )
 	{
+		if (id == null)
+			return null;
 		return getConf( id ).getList( depth );
 	}
 
 	public Map<?, ?> getMap( Object id, Integer depth )
 	{
+		if (id == null)
+			return null;
 		return getConf( id ).getMap( depth );
 	}
 	
@@ -494,7 +512,7 @@
 	{
 		if (iid == null)
 			return null;
-		return "#"+Integer.toString( 0, ID_RADIX )+"#";
+		return "#"+Integer.toString( iid, ID_RADIX )+"#";
 	}
 
 	private int fromId( Object id )

Modified: incubator/etch/branches/config/services/config/src/test/java/org/apache/etch/services/config/TestYamlConfig.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/config/services/config/src/test/java/org/apache/etch/services/config/TestYamlConfig.java?rev=750970&r1=750969&r2=750970&view=diff
==============================================================================
--- incubator/etch/branches/config/services/config/src/test/java/org/apache/etch/services/config/TestYamlConfig.java (original)
+++ incubator/etch/branches/config/services/config/src/test/java/org/apache/etch/services/config/TestYamlConfig.java Fri Mar  6 16:46:00 2009
@@ -395,6 +395,104 @@
 		c.getConfigPath( r, "primes/12" );
 	}
 	
+	/** @throws Exception */
+	@Test
+	public void hasValuePath() throws Exception
+	{
+		ConfigurationServer c = new YamlConfig( null, REMOTE );
+		Object r = c.getRoot();
+		Assert.assertNotNull( r );
+
+		Assert.assertTrue( c.hasValuePath( r, "." ) );
+		Assert.assertTrue( c.hasValuePath( r, "bool" ) );
+		Assert.assertFalse( c.hasValuePath( r, "blah" ) );
+	}
+	
+	/** @throws Exception */
+	@Test
+	public void getValuePath() throws Exception
+	{
+		ConfigurationServer c = new YamlConfig( null, REMOTE );
+		Object r = c.getRoot();
+		Assert.assertNotNull( r );
+
+		Assert.assertNotNull( c.getValuePath( r, "." ) );
+		Assert.assertNotNull( c.getValuePath( r, "bool" ) );
+		Assert.assertNull( c.getValuePath( r, "blah" ) );
+	}
+	
+	/** @throws Exception */
+	@Test
+	public void getBooleanPath1() throws Exception
+	{
+		ConfigurationServer c = new YamlConfig( null, REMOTE );
+		Object r = c.getRoot();
+		Assert.assertNotNull( r );
+
+		Assert.assertEquals( true, c.getBooleanPath( r, "bool" ) );
+		Assert.assertNull( c.getBooleanPath( r, "blah" ) );
+	}
+	
+	/** @throws Exception */
+	@Test( expected = IllegalArgumentException.class )
+	public void getBooleanPath2() throws Exception
+	{
+		ConfigurationServer c = new YamlConfig( null, REMOTE );
+		Object r = c.getRoot();
+		Assert.assertNotNull( r );
+
+		// cannot convert value to Boolean
+		c.getBooleanPath( r, "." );
+	}
+	
+	/** @throws Exception */
+	@Test( expected = IllegalArgumentException.class )
+	public void getBooleanPath3() throws Exception
+	{
+		ConfigurationServer c = new YamlConfig( null, REMOTE );
+		Object r = c.getRoot();
+		Assert.assertNotNull( r );
+		
+		// cannot convert value to Boolean
+		c.getBooleanPath( r, "int" );
+	}
+	
+	/** @throws Exception */
+	@Test
+	public void getIntegerPath1() throws Exception
+	{
+		ConfigurationServer c = new YamlConfig( null, REMOTE );
+		Object r = c.getRoot();
+		Assert.assertNotNull( r );
+
+		Assert.assertEquals( 23, c.getIntegerPath( r, "int" ) );
+		Assert.assertNull( c.getIntegerPath( r, "blah" ) );
+	}
+	
+	/** @throws Exception */
+	@Test( expected = IllegalArgumentException.class )
+	public void getIntegerPath2() throws Exception
+	{
+		ConfigurationServer c = new YamlConfig( null, REMOTE );
+		Object r = c.getRoot();
+		Assert.assertNotNull( r );
+
+		// cannot convert value to Integer
+		c.getIntegerPath( r, "." );
+	}
+	
+	/** @throws Exception */
+	@Test( expected = IllegalArgumentException.class )
+	public void getIntegerPath3() throws Exception
+	{
+		ConfigurationServer c = new YamlConfig( null, REMOTE );
+		Object r = c.getRoot();
+		Assert.assertNotNull( r );
+		
+		// cannot convert value to Integer
+		c.getIntegerPath( r, "bool" );
+	}
+	
 	private static class MyConfigurationClient implements ConfigurationClient
 	{
 		public void configValuesChanged( Object[] updated )