KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > om > impl > builder > StAXOMBuilderTest


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

16 package org.apache.axis2.om.impl.builder;
17
18 import org.apache.axis2.om.*;
19 import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
20 import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory;
21
22 import javax.xml.stream.XMLInputFactory;
23 import java.io.FileReader JavaDoc;
24 import java.util.Iterator JavaDoc;
25
26 public class StAXOMBuilderTest extends AbstractTestCase {
27     StAXOMBuilder stAXOMBuilder;
28     FileReader JavaDoc testFile;
29     private OMElement rootElement;
30
31     /**
32      * Constructor.
33      */

34     public StAXOMBuilderTest(String JavaDoc testName) {
35         super(testName);
36     }
37
38     protected void setUp() throws Exception JavaDoc {
39         testFile = new FileReader JavaDoc(getTestResourceFile("non_soap.xml"));
40         stAXOMBuilder = OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getSOAP11Factory(), XMLInputFactory.newInstance().createXMLStreamReader(testFile));
41     }
42
43     public void testGetRootElement() throws Exception JavaDoc {
44         rootElement = stAXOMBuilder.getDocumentElement();
45         assertTrue("Root element can not be null", rootElement != null);
46         assertTrue(" Name of the root element is wrong", rootElement.getLocalName().equalsIgnoreCase("Root"));
47         // get the first OMElement child
48
OMNode omnode = rootElement.getFirstChild();
49         while (omnode instanceof OMText) {
50             omnode = omnode.getNextSibling();
51         }
52         Iterator JavaDoc children = ((OMElement) omnode).getChildren();
53         int childrenCount = 0;
54         while (children.hasNext()) {
55             OMNode node = (OMNode) children.next();
56             if (node instanceof OMElement)
57                 childrenCount++;
58         }
59         assertTrue(childrenCount == 5);
60     }
61 }
Popular Tags