avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosu...@apache.org
Subject cvs commit: avalon/framework/impl/src/test/org/apache/avalon/framework/configuration/test DefaultConfigurationTestCase.java
Date Thu, 29 Jan 2004 16:28:21 GMT
leosutic    2004/01/29 08:28:21

  Modified:    framework/impl/src/test/org/apache/avalon/framework/configuration/test
                        DefaultConfigurationTestCase.java
  Log:
  Added unit tests for the MutableConfiguration interface of the
  DefaultConfiguration class.
  
  Revision  Changes    Path
  1.12      +48 -0     avalon/framework/impl/src/test/org/apache/avalon/framework/configuration/test/DefaultConfigurationTestCase.java
  
  Index: DefaultConfigurationTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon/framework/impl/src/test/org/apache/avalon/framework/configuration/test/DefaultConfigurationTestCase.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DefaultConfigurationTestCase.java	26 Jan 2004 19:50:55 -0000	1.11
  +++ DefaultConfigurationTestCase.java	29 Jan 2004 16:28:21 -0000	1.12
  @@ -21,6 +21,7 @@
   import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.configuration.ConfigurationUtil;
   import org.apache.avalon.framework.configuration.DefaultConfiguration;
  +import org.apache.avalon.framework.configuration.MutableConfiguration;
   
   /**
    * Test the basic public methods of DefaultConfiguration.
  @@ -187,8 +188,55 @@
               // OK, this is what we expect - the attribute wasn't found.
           }
       }
  +    
  +    public void testMutability() throws Exception
  +    {
  +        MutableConfiguration root = new DefaultConfiguration( "root", "-" );
  +        root.setAttribute( "root1", "root1" );
  +        root.setAttribute( "root2", "root2" );
  +        root.getMutableChild( "child1" ).setAttribute( "child1-attr1", "child1-attr1" );
  +        root.getMutableChild( "child1" ).setAttribute( "child1-attr2", "child1-attr2" );
  +        root.getMutableChild( "child2" ).setAttribute( "child2-attr1", "child2-attr1" );
  +        root.getMutableChild( "child2" ).setAttribute( "child2-attr2", "child2-attr2" );
  +        
  +        assertEquals( "root1", root.getAttribute( "root1" ) );
  +        assertEquals( "root2", root.getAttribute( "root2" ) );
  +        assertEquals( "child1-attr1", root.getChild( "child1" ).getAttribute( "child1-attr1"
) );
  +        assertEquals( "child1-attr2", root.getChild( "child1" ).getAttribute( "child1-attr2"
) );
  +        assertEquals( "child2-attr1", root.getChild( "child2" ).getAttribute( "child2-attr1"
) );
  +        assertEquals( "child2-attr2", root.getChild( "child2" ).getAttribute( "child2-attr2"
) );
  +        
  +        assertEquals( null, root.getMutableChild( "child3", false ) );
  +        
  +        assertEquals( 2, root.getChildren().length );
  +        
  +        assertEquals( 2, root.getMutableChildren().length );
  +        assertEquals( 1, root.getMutableChildren( "child1" ).length );
  +        assertEquals( 1, root.getMutableChildren( "child2" ).length );
  +        assertTrue( root.getMutableChildren( "child1" )[0] == root.getChild( "child1" )
);
  +        
  +        // Add an immutable child.
  +        DefaultConfiguration immutableChild = new DefaultConfiguration( "immutable-child",
"-" );
  +        immutableChild.makeReadOnly();
           
  +        try 
  +        {
  +            immutableChild.setAttribute( "attr", "attr" );
  +            fail( "Read-only DefaultConfiguration wasn't read-only!" );
  +        } 
  +        catch (IllegalStateException ise) 
  +        { 
  +            // expected 
  +        }
  +        
  +        root.addChild( immutableChild );
           
  +        // OK, ask to have it back.
  +        root.getMutableChild( "immutable-child" ).setAttribute( "attr", "attr" );
  +        
  +        assertEquals( 1, root.getChildren( "immutable-child" ).length );
  +        assertEquals( "attr", root.getChild( "immutable-child" ).getAttribute( "attr" )
);
  +    }
   }
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message