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.customext.attrib;
20  
21  import junit.framework.TestCase;
22  import org.apache.ws.commons.schema.XmlSchema;
23  import org.apache.ws.commons.schema.XmlSchemaCollection;
24  import org.apache.ws.commons.schema.XmlSchemaElement;
25  import org.apache.ws.commons.schema.constants.Constants;
26  import org.w3c.dom.Document;
27  import tests.Resources;
28  
29  import javax.xml.parsers.DocumentBuilderFactory;
30  import java.util.Iterator;
31  import java.util.Map;
32  
33  /**
34   * Deserialize the custom extension types
35   */
36  public class CustomExtDeserializerTest extends TestCase {
37  
38  
39      public void testDeserialization() throws Exception {
40              //set the system property for the custom extension registry
41              System.setProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY,
42                      CustomExtensionRegistry.class.getName());
43  
44             //create a DOM document
45             DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
46             documentBuilderFactory.setNamespaceAware(true);
47             Document doc = documentBuilderFactory.newDocumentBuilder().
48                     parse(Resources.asURI("/external/externalAnnotations.xsd"));
49  
50             XmlSchemaCollection schemaCol = new XmlSchemaCollection();
51             XmlSchema schema = schemaCol.read(doc,null);
52             assertNotNull(schema);
53  
54            // get the elements and check whether their annotations are properly
55            // populated
56             Iterator values = schema.getElements().getValues();
57             while (values.hasNext()) {
58                 XmlSchemaElement elt =  (XmlSchemaElement) values.next();
59                 assertNotNull(elt);
60                 Map metaInfoMap = elt.getMetaInfoMap();
61                 assertNotNull(metaInfoMap);
62  
63                 CustomAttribute customAttrib = (CustomAttribute)metaInfoMap.get(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME);
64                 assertNotNull(customAttrib);
65  
66             }
67  
68                   //remove our system property
69              System.getProperties().remove(Constants.SystemConstants.EXTENSION_REGISTRY_KEY);;
70  
71      }
72  }