KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > xml > dom > test > DefaultDOMParserTestCase


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.excalibur.xml.dom.test;
18
19 import java.io.StringReader JavaDoc;
20
21 import org.apache.avalon.excalibur.testcase.ExcaliburTestCase;
22 import org.apache.avalon.framework.component.ComponentException;
23 import org.apache.excalibur.xml.dom.DOMParser;
24 import org.w3c.dom.Document JavaDoc;
25 import org.w3c.dom.Element JavaDoc;
26 import org.w3c.dom.Node JavaDoc;
27 import org.xml.sax.InputSource JavaDoc;
28
29 /**
30  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
31  */

32 public class DefaultDOMParserTestCase extends ExcaliburTestCase
33 {
34     
35     private static final String JavaDoc CONTENT =
36         "<?xml version=\"1.0\"?>" +
37         "<test:root xmlns:test=\"http://localhost/test\">" +
38             "<test:element1/>" +
39             "<test:element2/>" +
40         "</test:root>";
41     private static final StringReader JavaDoc IN = new StringReader JavaDoc( CONTENT );
42     
43     public DefaultDOMParserTestCase( String JavaDoc name )
44     {
45         super( name );
46     }
47     
48     public void testCreateDOMHandler()
49     {
50         try
51         {
52             final DOMParser parser = (DOMParser)manager.lookup( DOMParser.ROLE );
53
54             final Document JavaDoc document = parser.parseDocument( new InputSource JavaDoc( IN ) );
55             
56             final Element JavaDoc root = document.getDocumentElement();
57             assertEquals( "Wrong root element", "test:root", root.getNodeName() );
58             assertEquals( "Wrong namespace uri", "http://localhost/test", root.getNamespaceURI() );
59             
60             final Node JavaDoc element1 = root.getFirstChild();
61             assertEquals( "Child is not an element", Node.ELEMENT_NODE, element1.getNodeType() );
62             assertEquals( "Wrong first element", "test:element1", element1.getNodeName() );
63             
64             final Node JavaDoc element2 = root.getLastChild();
65             assertEquals( "Child is not an element", Node.ELEMENT_NODE, element2.getNodeType() );
66             assertEquals( "Wrong last element", "test:element2", element2.getNodeName() );
67         }
68         catch ( ComponentException e )
69         {
70             fail( "Failed to lookup components: " + e.getMessage() );
71         }
72         catch ( Exception JavaDoc e )
73         {
74             fail( "Failed to create handler: " + e.getMessage() );
75         }
76     }
77     
78 }
79
Popular Tags