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.apache.ws.commons.schema.XmlSchemaElement;
7   import org.apache.ws.commons.schema.XmlSchemaType;
8   import org.w3c.dom.Document;
9   
10  import javax.xml.parsers.DocumentBuilderFactory;
11  import java.util.Iterator;
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 AllSimpleTypeTest extends TestCase {
29  
30      public void testSimpleTypeSchemaGeneration() throws Exception {
31          //create a DOM document
32          DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
33          documentBuilderFactory.setNamespaceAware(true);
34          Document doc = documentBuilderFactory.newDocumentBuilder().
35                  parse(Resources.asURI("allSimpleTypes.xsd"));
36  
37          XmlSchemaCollection schemaCol = new XmlSchemaCollection();
38          XmlSchema schema = schemaCol.read(doc,null);
39          assertNotNull(schema);
40  
41          //loop through the schema elements and inspect the SchemaTypeObject
42          //if the type is registered, then getSchemaType should return a SchemaType
43          //object
44          Iterator values = schema.getElements().getValues();
45          while (values.hasNext()) {
46              XmlSchemaElement elt =  (XmlSchemaElement) values.next();
47              XmlSchemaType schemaType = elt.getSchemaType();
48              assertNotNull(schemaType);
49  
50          }
51  
52  
53      }
54  }