avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mirceat...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/xmlutil/src/test/org/apache/avalon/excalibur/xml/test DefaultDOMHandlerFactoryTestCase.xtest DefaultDOMHandlerFactoryTestCase.java
Date Tue, 06 Aug 2002 18:18:58 GMT
mirceatoma    2002/08/06 11:18:58

  Added:       xmlutil/src/test/org/apache/avalon/excalibur/xml/test
                        DefaultDOMHandlerFactoryTestCase.xtest
                        DefaultDOMHandlerFactoryTestCase.java
  Log:
  Adde test case for DefaultDOMHandlerFactory.
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/xmlutil/src/test/org/apache/avalon/excalibur/xml/test/DefaultDOMHandlerFactoryTestCase.xtest
  
  Index: DefaultDOMHandlerFactoryTestCase.xtest
  ===================================================================
  <!-- edited with XML Spy v4.4 U (http://www.xmlspy.com) by Mircea Toma (Allstar Tech)
-->
  <testcase>
  	<annotation><![CDATA[DOMHandler factory test
      ]]></annotation>
  	<logkit>
  		<factories>
  			<factory type="file" class="org.apache.avalon.excalibur.logger.factory.FileTargetFactory"/>
  		</factories>
  		<targets>
  			<file id="root">
  				<filename>domhandler-factory-test.log</filename>
  				<format type="extended">
            %7.7{priority} %5.5{time}   [%8.8{category}] (%{context}): %{message}\n%{throwable}
          </format>
  			</file>
  		</targets>
  		<categories>
  			<category name="test" log-level="INFO">
  				<log-target id-ref="root"/>
  			</category>
  			<category name="" log-level="INFO">
  				<log-target id-ref="root"/>
  			</category>
  		</categories>
  	</logkit>
  	<roles>
  		<role name="org.apache.avalon.excalibur.xml.DOMHandlerFactory" shorthand="domhandler-factory"
default-class="org.apache.avalon.excalibur.xml.DefaultDOMHandlerFactory"/>
  		<role name="org.apache.avalon.excalibur.xml.Parser" shorthand="parser" default-class="org.apache.avalon.excalibur.xml.JaxpParser"/>
  	</roles>
  	<components>
  		<parser logger="test">
  			<parameter name="namespace-prefixes" value="false"/>
  		</parser>
  		<domhandler-factory logger="test">
  			<namespace-aware>false</namespace-aware>
  		</domhandler-factory>
  	</components>
  </testcase>
  
  
  
  1.1                  jakarta-avalon-excalibur/xmlutil/src/test/org/apache/avalon/excalibur/xml/test/DefaultDOMHandlerFactoryTestCase.java
  
  Index: DefaultDOMHandlerFactoryTestCase.java
  ===================================================================
  package org.apache.avalon.excalibur.xml.test;
  
  import java.io.StringReader;
  import org.w3c.dom.Element;
  import org.w3c.dom.Document;
  import org.w3c.dom.Node;
  import org.xml.sax.InputSource;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.excalibur.testcase.ExcaliburTestCase;
  import org.apache.avalon.excalibur.xml.Parser;
  import org.apache.avalon.excalibur.xml.DOMHandler;
  import org.apache.avalon.excalibur.xml.DOMHandlerFactory;
  
  public class DefaultDOMHandlerFactoryTestCase extends ExcaliburTestCase
  {
      
      private static final String CONTENT = 
          "<?xml version=\"1.0\"?>" + 
          "<test:root xmlns:test=\"http://localhost/test\">" +
              "<test:element1/>" +
              "<test:element2/>" +
          "</test:root>";
      private static final StringReader IN = new StringReader( CONTENT );
      
      public DefaultDOMHandlerFactoryTestCase( String name )
      {
          super( name );
      }
      
      public void testCreateDOMHandler()
      {
          try 
          {
              final Parser parser = (Parser)manager.lookup( Parser.ROLE );
              final DOMHandlerFactory handlerFactory = (DOMHandlerFactory)manager.lookup(
DOMHandlerFactory.ROLE );        
  
              final DOMHandler handler = handlerFactory.createDOMHandler();
              parser.parse( new InputSource( IN ), handler );            
              final Document document = handler.getDocument();
              
              final Element root = document.getDocumentElement();
              this.assertEquals( "Wrong root element", "test:root", root.getNodeName() );
              this.assertEquals( "Wrong namespace uri", "http://localhost/test", root.getNamespaceURI()
);
              
              final Node element1 = root.getFirstChild();
              this.assertEquals( "Child is not an element", Document.ELEMENT_NODE, element1.getNodeType()
);
              this.assertEquals( "Wrong first element", "test:element1", element1.getNodeName()
);
              
              final Node element2 = root.getLastChild();
              this.assertEquals( "Child is not an element", Document.ELEMENT_NODE, element2.getNodeType()
);
              this.assertEquals( "Wrong last element", "test:element2", element2.getNodeName()
);                        
          }
          catch ( ComponentException e )
          {
              this.fail( "Failed to lookup components: " + e.getMessage() );
          }
          catch ( Exception e )
          {
              this.fail( "Failed to create handler: " + e.getMessage() );
          }
      }
      
  }
  
  
  

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


Mime
View raw message