View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package tests.ext;
20  
21  import junit.framework.TestCase;
22  
23  import java.util.Map;
24  import java.util.Iterator;
25  
26  import tests.Resources;
27  import org.apache.ws.commons.schema.XmlSchemaCollection;
28  import org.apache.ws.commons.schema.XmlSchema;
29  import org.apache.ws.commons.schema.XmlSchemaElement;
30  import org.w3c.dom.Document;
31  
32  import javax.xml.parsers.DocumentBuilderFactory;
33  
34  /**
35   * Test the custom extension dserialization without any specialized
36   * hooks
37   */
38  public class PlainExtensionDeserializerTest extends TestCase {
39  
40       public void testDeserialization() throws Exception {
41  
42             //create a DOM document
43             DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
44             documentBuilderFactory.setNamespaceAware(true);
45             Document doc = documentBuilderFactory.newDocumentBuilder().
46                     parse(Resources.asURI("/external/externalAnnotations.xsd"));
47  
48             XmlSchemaCollection schemaCol = new XmlSchemaCollection();
49             XmlSchema schema = schemaCol.read(doc,null);
50             assertNotNull(schema);
51  
52            // get the elements and check whether their annotations are properly
53            // populated
54             Iterator values = schema.getElements().getValues();
55             while (values.hasNext()) {
56                 XmlSchemaElement elt =  (XmlSchemaElement) values.next();
57                 assertNotNull(elt);
58                 Map metaInfoMap = elt.getMetaInfoMap();
59                 assertNotNull(metaInfoMap);
60  
61             }
62       }
63  
64  
65      public void testDeserialization1() throws Exception {
66  
67             //create a DOM document
68             DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
69             documentBuilderFactory.setNamespaceAware(true);
70             Document doc = documentBuilderFactory.newDocumentBuilder().
71                     parse(Resources.asURI("/external/externalElementAnnotations.xsd"));
72  
73             XmlSchemaCollection schemaCol = new XmlSchemaCollection();
74             XmlSchema schema = schemaCol.read(doc,null);
75             assertNotNull(schema);
76  
77            // get the elements and check whether their annotations are properly
78            // populated
79             Iterator values = schema.getElements().getValues();
80             while (values.hasNext()) {
81                 XmlSchemaElement elt =  (XmlSchemaElement) values.next();
82                 assertNotNull(elt);
83                 Map metaInfoMap = elt.getMetaInfoMap();
84                 assertNotNull(metaInfoMap);
85  
86             }
87       }
88  }