1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }