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