1   /*
2    * Copyright 2004,2007 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 tests.ext;
17  
18  import junit.framework.TestCase;
19  
20  import java.util.Map;
21  import java.util.Iterator;
22  
23  import tests.Resources;
24  import org.apache.ws.commons.schema.XmlSchemaCollection;
25  import org.apache.ws.commons.schema.XmlSchema;
26  import org.apache.ws.commons.schema.XmlSchemaElement;
27  import org.w3c.dom.Document;
28  
29  import javax.xml.parsers.DocumentBuilderFactory;
30  
31  /**
32   * Test the custom extension dserialization without any specialized
33   * hooks
34   */
35  public class PlainExtensionDeserializerTest extends TestCase {
36  
37       public void testDeserialization() throws Exception {
38  
39             //create a DOM document
40             DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
41             documentBuilderFactory.setNamespaceAware(true);
42             Document doc = documentBuilderFactory.newDocumentBuilder().
43                     parse(Resources.asURI("/external/externalAnnotations.xsd"));
44  
45             XmlSchemaCollection schemaCol = new XmlSchemaCollection();
46             XmlSchema schema = schemaCol.read(doc,null);
47             assertNotNull(schema);
48  
49            // get the elements and check whether their annotations are properly
50            // populated
51             Iterator values = schema.getElements().getValues();
52             while (values.hasNext()) {
53                 XmlSchemaElement elt =  (XmlSchemaElement) values.next();
54                 assertNotNull(elt);
55                 Map metaInfoMap = elt.getMetaInfoMap();
56                 assertNotNull(metaInfoMap);
57  
58             }
59       }
60  
61  
62      public void testDeserialization1() throws Exception {
63  
64             //create a DOM document
65             DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
66             documentBuilderFactory.setNamespaceAware(true);
67             Document doc = documentBuilderFactory.newDocumentBuilder().
68                     parse(Resources.asURI("/external/externalElementAnnotations.xsd"));
69  
70             XmlSchemaCollection schemaCol = new XmlSchemaCollection();
71             XmlSchema schema = schemaCol.read(doc,null);
72             assertNotNull(schema);
73  
74            // get the elements and check whether their annotations are properly
75            // populated
76             Iterator values = schema.getElements().getValues();
77             while (values.hasNext()) {
78                 XmlSchemaElement elt =  (XmlSchemaElement) values.next();
79                 assertNotNull(elt);
80                 Map metaInfoMap = elt.getMetaInfoMap();
81                 assertNotNull(metaInfoMap);
82  
83             }
84       }
85  }