1
2
3
4
5
6
7 package org.mule.test.spring;
8
9 import org.mule.tck.junit4.AbstractMuleTestCase;
10 import org.mule.util.IOUtils;
11
12 import java.io.IOException;
13 import java.io.InputStream;
14
15 import javax.xml.XMLConstants;
16 import javax.xml.transform.Source;
17 import javax.xml.transform.stream.StreamSource;
18 import javax.xml.validation.Schema;
19 import javax.xml.validation.SchemaFactory;
20
21 import org.junit.Test;
22 import org.xml.sax.SAXException;
23
24 import static org.junit.Assert.assertNotNull;
25
26
27
28
29 public class SchemaValidationMule2225TestCase extends AbstractMuleTestCase
30 {
31
32
33
34
35
36
37
38 @Test
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 }