package org.apache.avalon.framework.configuration.test;


import java.util.List;
import junit.framework.TestCase;
import org.apache.avalon.framework.configuration.SAXConfigurationHandler;
import org.apache.avalon.framework.configuration.Configuration;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.Attributes;
/**
 * Test the basic public methods of SAXConfigurationHandlerTestCase ,
 * @author <a href="mailto:rantene@hotmail.com">Ran Tene</a>
 */

public final class SAXConfigurationHandlerTestCase extends TestCase
{
 
	private SAXConfigurationHandler mHandler;
	
    public SAXConfigurationHandlerTestCase()
    {
        this("SAXConfigurationHandler Test Case ");
    }


    public SAXConfigurationHandlerTestCase( String name )
     {
         super( name );
     }
	 
    public void setUp()
    {
		mHandler = new SAXConfigurationHandler( );
    }
	
	public void tearDowm()
	{
		mHandler =null;
	}
	
	public void testHandling() throws Exception
	{						
		final String namespaceURI = "namespaceURI";
    	final String localName = "localName";
	    final String rawName = "rawName";
	    final String value = "value";	
		final String attUri = "attUri";
	    final String attLocalName = "attLocalName";
	    final String attqName = "attqName";
	    final String attType = "attType";
	    final String attValue = "attValue";	
	    final String childfix = "child";		
		
	    final AttributesImpl attributes  = new AttributesImpl();
		attributes.addAttribute(attUri,attLocalName,attqName,
                         attType,attValue);
		final AttributesImpl childAttributes  = new AttributesImpl();	 
		mHandler.startDocument();	 
		mHandler.startElement( namespaceURI,  localName, rawName, attributes );
		mHandler.startElement( namespaceURI+childfix,  localName+childfix,
                              rawName+childfix, childAttributes );
	  
		mHandler.characters( value.toCharArray(), 0, value.length());	
		mHandler.endElement(namespaceURI+childfix,localName+childfix,rawName+childfix);	  
		mHandler.endElement(namespaceURI,localName,rawName);	  
		mHandler.endDocument();	
		
		
		
		Configuration configuration = mHandler.getConfiguration();				
		assertEquals( attValue, configuration.getAttribute(attqName));
		assertEquals( value, configuration.getChild(rawName+childfix).getValue());		
		assertEquals( rawName, configuration.getName());					  
	}
	
}





