1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.xml.validation;
18
19 import javax.xml.XMLConstants;
20 import javax.xml.validation.Schema;
21
22 import junit.framework.TestCase;
23 import org.springframework.core.io.ClassPathResource;
24 import org.springframework.core.io.Resource;
25
26 public class SchemaLoaderUtilsTest extends TestCase {
27
28 public void testLoadSchema() throws Exception {
29 Resource resource = new ClassPathResource("schema.xsd", getClass());
30 Schema schema = SchemaLoaderUtils.loadSchema(resource, XMLConstants.W3C_XML_SCHEMA_NS_URI);
31 assertNotNull("No schema returned", schema);
32 assertFalse("Resource not closed", resource.isOpen());
33 }
34
35 public void testLoadNonExistantSchema() throws Exception {
36 try {
37 Resource nonExistant = new ClassPathResource("bla");
38 SchemaLoaderUtils.loadSchema(nonExistant, XMLConstants.W3C_XML_SCHEMA_NS_URI);
39 fail("Should have thrown an IllegalArgumentException");
40 }
41 catch (IllegalArgumentException e) {
42
43 }
44 }
45
46 public void testLoadNullSchema() throws Exception {
47 try {
48 SchemaLoaderUtils.loadSchema((Resource) null, XMLConstants.W3C_XML_SCHEMA_NS_URI);
49 fail("Should have thrown an IllegalArgumentException");
50 }
51 catch (IllegalArgumentException e) {
52
53 }
54 }
55
56 public void testLoadMultipleSchemas() throws Exception {
57 Resource envelope = new ClassPathResource("envelope.xsd", getClass());
58 Resource encoding = new ClassPathResource("encoding.xsd", getClass());
59 Schema schema =
60 SchemaLoaderUtils.loadSchema(new Resource[]{envelope, encoding}, XMLConstants.W3C_XML_SCHEMA_NS_URI);
61 assertNotNull("No schema returned", schema);
62 assertFalse("Resource not closed", envelope.isOpen());
63 assertFalse("Resource not closed", encoding.isOpen());
64 }
65 }