1   package tests;
2   
3   import junit.framework.TestCase;
4   import org.apache.ws.commons.schema.XmlSchemaCollection;
5   import org.w3c.dom.Document;
6   import org.w3c.dom.Element;
7   import org.w3c.dom.Node;
8   import org.w3c.dom.NodeList;
9   
10  import javax.xml.namespace.QName;
11  import javax.xml.parsers.DocumentBuilderFactory;
12  /*
13   * Copyright 2004,2007 The Apache Software Foundation.
14   *
15   * Licensed under the Apache License, Version 2.0 (the "License");
16   * you may not use this file except in compliance with the License.
17   * You may obtain a copy of the License at
18   *
19   *      http://www.apache.org/licenses/LICENSE-2.0
20   *
21   * Unless required by applicable law or agreed to in writing, software
22   * distributed under the License is distributed on an "AS IS" BASIS,
23   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24   * See the License for the specific language governing permissions and
25   * limitations under the License.
26   */
27  
28  public class TwoSchemasTest extends TestCase {
29  
30      public void testTwoSchemas() throws Exception{
31          DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
32          documentBuilderFactory.setNamespaceAware(true);
33          Document doc = documentBuilderFactory.newDocumentBuilder().
34                  parse(Resources.asURI("twoSchemas.wsdl"));
35  
36          XmlSchemaCollection schemaCol = new XmlSchemaCollection();
37  		NodeList schemaNodes = doc.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema","schema");
38          for (int j = 0; j < schemaNodes.getLength(); j++) {
39          	Node schemaNode = schemaNodes.item(j);
40          	if("schema".equals(schemaNode.getLocalName())){
41          		schemaCol.read((Element)schemaNode);
42          	}
43          }
44          
45          assertNotNull(schemaCol.getElementByQName(new QName("http://tns.demo.org","elem1")));
46  
47      }
48  }