1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.spring;
12
13 import org.mule.tck.AbstractMuleTestCase;
14 import org.mule.util.IOUtils;
15
16 import java.io.IOException;
17 import java.io.InputStream;
18
19 import javax.xml.XMLConstants;
20 import javax.xml.transform.Source;
21 import javax.xml.transform.stream.StreamSource;
22 import javax.xml.validation.Schema;
23 import javax.xml.validation.SchemaFactory;
24
25 import org.xml.sax.SAXException;
26
27
28
29
30 public class SchemaValidationMule2225TestCase extends AbstractMuleTestCase
31 {
32
33
34
35
36
37
38
39 public void testValidation() throws SAXException, IOException
40 {
41 SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
42 schemaFactory.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
43 Source muleXsd = new StreamSource(load("META-INF/mule.xsd"));
44 Schema schema = schemaFactory.newSchema(muleXsd);
45 Source muleRootTestXml = new StreamSource(load("org/mule/test/spring/mule-root-test.xml"));
46 schema.newValidator().validate(muleRootTestXml);
47 }
48
49 protected InputStream load(String name) throws IOException
50 {
51 InputStream stream = IOUtils.getResourceAsStream(name, getClass());
52 assertNotNull("Cannot load " + name, stream);
53 return stream;
54 }
55
56 }