1   package tests;
2   
3   import junit.framework.TestCase;
4   import org.apache.ws.commons.schema.XmlSchema;
5   import org.apache.ws.commons.schema.XmlSchemaCollection;
6   import org.w3c.dom.Document;
7   
8   import javax.xml.parsers.DocumentBuilderFactory;
9   import java.io.File;
10  /*
11   * Copyright 2004,2007 The Apache Software Foundation.
12   *
13   * Licensed under the Apache License, Version 2.0 (the "License");
14   * you may not use this file except in compliance with the License.
15   * You may obtain a copy of the License at
16   *
17   *      http://www.apache.org/licenses/LICENSE-2.0
18   *
19   * Unless required by applicable law or agreed to in writing, software
20   * distributed under the License is distributed on an "AS IS" BASIS,
21   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22   * See the License for the specific language governing permissions and
23   * limitations under the License.
24   */
25  
26  public class ImportTest extends TestCase {
27  
28      public void testSchemaImport() throws Exception{
29          //create a DOM document
30          DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
31          documentBuilderFactory.setNamespaceAware(true);
32          Document doc = documentBuilderFactory.newDocumentBuilder().
33                  parse(Resources.asURI("importBase.xsd"));
34  
35          XmlSchemaCollection schemaCol = new XmlSchemaCollection();
36          schemaCol.setBaseUri(Resources.TEST_RESOURCES);
37          XmlSchema schema = schemaCol.read(doc,null);
38          assertNotNull(schema);
39  
40          // attempt with slash now
41          schemaCol = new XmlSchemaCollection();
42          schemaCol.setBaseUri(Resources.TEST_RESOURCES + "/");
43          schema = schemaCol.read(doc,null);
44          assertNotNull(schema);
45      }
46  
47      /**
48       * variation of above don't set the base uri.
49       * @throws Exception
50       */
51      public void testSchemaImport2() throws Exception{
52          File file = new File(Resources.asURI("importBase.xsd"));
53          //create a DOM document
54          DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
55          documentBuilderFactory.setNamespaceAware(true);
56          Document doc = documentBuilderFactory.newDocumentBuilder().
57                  parse(file.toURL().toString());
58  
59          XmlSchemaCollection schemaCol = new XmlSchemaCollection();
60          XmlSchema schema = schemaCol.read(doc,file.toURL().toString(),null);
61          assertNotNull(schema);
62  
63      }
64  }