1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.spring;
12
13 import org.mule.tck.junit4.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.junit.Test;
26 import org.xml.sax.SAXException;
27
28 import static org.junit.Assert.assertNotNull;
29
30
31
32
33 public class SchemaValidationMule2225TestCase extends AbstractMuleTestCase
34 {
35
36
37
38
39
40
41
42 @Test
43 public void testValidation() throws SAXException, IOException
44 {
45 SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
46 schemaFactory.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
47 Source muleXsd = new StreamSource(load("META-INF/mule.xsd"));
48 Schema schema = schemaFactory.newSchema(muleXsd);
49 Source muleRootTestXml = new StreamSource(load("org/mule/test/spring/mule-root-test.xml"));
50 schema.newValidator().validate(muleRootTestXml);
51 }
52
53 protected InputStream load(String name) throws IOException
54 {
55 InputStream stream = IOUtils.getResourceAsStream(name, getClass());
56 assertNotNull("Cannot load " + name, stream);
57 return stream;
58 }
59
60 }