1   /*
2    * Copyright ${YEAR} the original author or authors.
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  
17  package org.springframework.xml.xsd.commons;
18  
19  import javax.xml.transform.dom.DOMSource;
20  
21  import org.apache.ws.commons.schema.XmlSchema;
22  import org.apache.ws.commons.schema.XmlSchemaCollection;
23  import org.w3c.dom.Document;
24  import org.w3c.dom.Element;
25  
26  import org.springframework.core.io.ClassPathResource;
27  import org.springframework.core.io.Resource;
28  import org.springframework.xml.sax.SaxUtils;
29  import org.springframework.xml.xsd.AbstractXsdSchemaTestCase;
30  import org.springframework.xml.xsd.XsdSchema;
31  
32  public class CommonsXsdSchemaTest extends AbstractXsdSchemaTestCase {
33  
34      protected XsdSchema createSchema(Resource resource) throws Exception {
35          XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
36          XmlSchema schema = schemaCollection.read(SaxUtils.createInputSource(resource), null);
37          return new CommonsXsdSchema(schema);
38      }
39  
40      public void testXmime() throws Exception {
41          Resource resource = new ClassPathResource("xmime.xsd", AbstractXsdSchemaTestCase.class);
42          XsdSchema schema = createSchema(resource);
43          String namespace = "urn:test";
44          assertEquals("Invalid target namespace", namespace, schema.getTargetNamespace());
45          Document result = (Document) ((DOMSource) schema.getSource()).getNode();
46          Element schemaElement = result.getDocumentElement();
47          Element elementElement = (Element) schemaElement.getFirstChild();
48          assertNotNull("No expectedContentTypes found",
49                  elementElement.getAttributeNS("http://www.w3.org/2005/05/xmlmime", "expectedContentTypes"));
50      }
51  
52  
53  }