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.springframework.core.io.ClassPathResource;
22 import org.springframework.core.io.Resource;
23 import org.springframework.xml.sax.SaxUtils;
24 import org.springframework.xml.xsd.AbstractXsdSchemaTestCase;
25 import org.springframework.xml.xsd.XsdSchema;
26
27 import org.apache.ws.commons.schema.XmlSchema;
28 import org.apache.ws.commons.schema.XmlSchemaCollection;
29 import org.junit.Test;
30 import org.w3c.dom.Document;
31 import org.w3c.dom.Element;
32
33 import static org.junit.Assert.assertEquals;
34 import static org.junit.Assert.assertNotNull;
35
36 public class CommonsXsdSchemaTest extends AbstractXsdSchemaTestCase {
37
38 @Override
39 protected XsdSchema createSchema(Resource resource) throws Exception {
40 XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
41 XmlSchema schema = schemaCollection.read(SaxUtils.createInputSource(resource));
42 return new CommonsXsdSchema(schema);
43 }
44
45 @Test
46 public void testXmime() throws Exception {
47 Resource resource = new ClassPathResource("xmime.xsd", AbstractXsdSchemaTestCase.class);
48 XsdSchema schema = createSchema(resource);
49 String namespace = "urn:test";
50 assertEquals("Invalid target namespace", namespace, schema.getTargetNamespace());
51 Document result = (Document) ((DOMSource) schema.getSource()).getNode();
52 Element schemaElement = result.getDocumentElement();
53 Element elementElement = (Element) schemaElement.getFirstChild();
54 assertNotNull("No expectedContentTypes found",
55 elementElement.getAttributeNS("http://www.w3.org/2005/05/xmlmime", "expectedContentTypes"));
56 }
57
58
59 }